const char *platform_get_path(path_type_t type, const char *append) { long len = 0; wchar_t login1[MAX_PATH]; int wintype = 0; switch (type) { case PLATFORM_PATH_PROGRAM: wintype = CSIDL_PROGRAM_FILES; break; case PLATFORM_PATH_PRIVATE: wintype = CSIDL_APPDATA; break; case PLATFORM_PATH_DATA: wintype = CSIDL_APPDATA; fill_in_default_path(); len = strlen(path); goto path_valid; break; case PLATFORM_PATH_TEMP: wintype = CSIDL_APPDATA; break; default: return NULL; } if (!SHGetSpecialFolderPath(NULL, login1, wintype, FALSE)) { return NULL; } for (len = 0; login1[len] != 0; len++) path[len] = (char) login1[len]; path_valid: if (type == PLATFORM_PATH_PROGRAM || type == PLATFORM_PATH_PRIVATE || type == PLATFORM_PATH_DATA || type == PLATFORM_PATH_TEMP) { wchar_t *wpath; if (len + strlen(DEFAULT_STORAGE_PATH_POSTFIX) > MAX_PATH_LEN) return NULL; len += snprintf(path + len, MAX_PATH_LEN - len, "%s", DEFAULT_STORAGE_PATH_POSTFIX); /* Make sure the path exists... */ wpath = strtowstr_alloc(path); if (wpath) { CreateDirectory(wpath, NULL); free(wpath); } } if (append) { if (len + strlen(append) > MAX_PATH_LEN) return NULL; strcpy(path + len, append); } return path; }
static void cleanup_pid_file() { string pidfile = PID_FILE; #if defined(OS_WINDOWS_MOBILE) || defined(OS_WINDOWS_VISTA) wchar_t *wpidfile = strtowstr_alloc(pidfile.c_str()); if (wpidfile) { DeleteFile(wpidfile); free(wpidfile); } #elif defined(OS_WINDOWS) DeleteFileA(pidfile.c_str()); #else unlink(pidfile.c_str()); #endif }