filerail/utils.h
// parse the resource path (gets resource dir and resource name)
parse the resource path (gets resource dir and resource name)
parse the resource path ( gets resource dir and resource name )
bool filerail_parse_resource_path(const char *resource_path, char *resource_name, char *resource_dir) {
	int i;
	size_t path_len = strlen(resource_path);
	if (path_len > MAX_PATH_LENGTH - 1) {
		printf("Length of resource path exceeded MAX_PATH_LENGTH\n");
		return false;
	}
	for (i = path_len - 1; i > 0; i--) {
		if (resource_path[i] == '/') {
			break;
		}
	}
	resource_name[0] = '\0';
	resource_dir[0] = '\0';
	if (i == -1) {
		printf("Resource path must be absolute\n");
		return false;
	}
	if (path_len - i - 1 > MAX_RESOURCE_LENGTH - 1) {
		printf("Length of resource name exceeded MAX_RESOURCE_LENGTH\n");
		return false;
	}
	memcpy(resource_name, resource_path + i + 1, path_len - i - 1);
	if (i == 0) {
		strcpy(resource_dir, "/");
	} else {
		memcpy(resource_dir, resource_path, i);
	}
	return true;
}
bool filerail_parse_resource_path ( const char * resource_path , char * resource_name , char * resource_dir ) { int i ; size_t path_len = strlen ( resource_path ) ; if ( path_len > MAX_PATH_LENGTH - 1 ) { printf ( " \n " ) ; return false ; } for ( i = path_len - 1 ; i > 0 ; i -- ) { if ( resource_path [ i ] == ' ' ) { break ; } } resource_name [ 0 ] = ' \0 ' ; resource_dir [ 0 ] = ' \0 ' ; if ( i == -1 ) { printf ( " \n " ) ; return false ; } if ( path_len - i - 1 > MAX_RESOURCE_LENGTH - 1 ) { printf ( " \n " ) ; return false ; } memcpy ( resource_name , resource_path + i + 1 , path_len - i - 1 ) ; if ( i == 0 ) { strcpy ( resource_dir , " " ) ; } else { memcpy ( resource_dir , resource_path , i ) ; } return true ; }
parse the resource path (gets resource dir and resource name)
parse the resource path ( gets resource dir and resource name )