void pocl_cache_init_topdir() { if (cache_topdir_initialized) return; const char *tmp_path = pocl_get_string_option("POCL_CACHE_DIR", NULL); int needed; if (tmp_path && (pocl_exists(tmp_path))) { needed = snprintf(cache_topdir, POCL_FILENAME_LENGTH, "%s", tmp_path); } else { #ifdef POCL_ANDROID char* process_name = pocl_get_process_name(); needed = snprintf(cache_topdir, POCL_FILENAME_LENGTH, "/data/data/%s/cache/", process_name); free(process_name); if (!pocl_exists(cache_topdir)) needed = snprintf(cache_topdir, POCL_FILENAME_LENGTH, "/sdcard/pocl/kcache"); #elif defined(_MSC_VER) || defined(__MINGW32__) tmp_path = getenv("LOCALAPPDATA"); if (!tmp_path) tmp_path = getenv("TEMP"); assert(tmp_path); needed = snprintf(cache_topdir, POCL_FILENAME_LENGTH, "%s\\pocl", tmp_path); #else // "If $XDG_CACHE_HOME is either not set or empty, a default equal to // $HOME/.cache should be used." // http://standards.freedesktop.org/basedir-spec/latest/ tmp_path = getenv("XDG_CACHE_HOME"); if (tmp_path && tmp_path[0] != '\0') { needed = snprintf(cache_topdir, POCL_FILENAME_LENGTH, "%s/pocl/kcache", tmp_path); } else if ((tmp_path = getenv("HOME")) != NULL) { needed = snprintf(cache_topdir, POCL_FILENAME_LENGTH, "%s/.cache/pocl/kcache", tmp_path); } else { needed = snprintf(cache_topdir, POCL_FILENAME_LENGTH, "/tmp/pocl/kcache"); } #endif } if (needed >= POCL_FILENAME_LENGTH) { POCL_ABORT("pocl: cache path longer than maximum filename length"); } assert(strlen(cache_topdir) > 0); if (pocl_mkdir_p(cache_topdir)) POCL_ABORT("Could not create topdir for cache"); cache_topdir_initialized = 1; }
char* pocl_create_program_cache_dir(cl_program program) { char *tmp_path = NULL, *cache_path = NULL; char hash_str[SHA1_DIGEST_SIZE * 2 + 1]; int i; for (i = 0; i < SHA1_DIGEST_SIZE; i++) sprintf(&hash_str[i*2], "%02x", (unsigned int) program->build_hash[i]); cache_path = (char*)malloc(CACHE_DIR_PATH_CHARS); tmp_path = getenv("POCL_CACHE_DIR"); if (tmp_path && (access(tmp_path, W_OK) == 0)) { snprintf(cache_path, CACHE_DIR_PATH_CHARS, "%s/%s", tmp_path, hash_str); } else { #ifdef POCL_ANDROID snprintf(cache_path, CACHE_DIR_PATH_CHARS, "/data/data/%s/cache/", pocl_get_process_name()); if (access(cache_path, W_OK) == 0) strcat(cache_path, hash_str); else snprintf(cache_path, CACHE_DIR_PATH_CHARS, "/sdcard/pocl/kcache/%s", hash_str); #else tmp_path = getenv("HOME"); if (tmp_path) snprintf(cache_path, CACHE_DIR_PATH_CHARS, "%s/.pocl/kcache/%s", tmp_path, hash_str); else snprintf(cache_path, CACHE_DIR_PATH_CHARS, "/tmp/pocl/kcache/%s", hash_str); #endif } if (access(cache_path, F_OK) != 0) pocl_make_directory(cache_path); return cache_path; }