36 #if defined(_MSC_VER) || defined(__MINGW32__)
37 #define inline __inline
43 #include <sys/param.h>
46 #if defined(__linux__) || defined(BSD)
52 #define PATH_SEPARATOR_CHAR '/'
53 #define PATH_SEPARATOR_STRING "/"
55 #define CFGPATH_WINDOWS
58 #define PATH_SEPARATOR_CHAR '\\'
59 #define PATH_SEPARATOR_STRING "\\"
60 #elif defined(__APPLE__)
62 #include <CoreServices/CoreServices.h>
64 #define MAX_PATH PATH_MAX
65 #define PATH_SEPARATOR_CHAR '/'
66 #define PATH_SEPARATOR_STRING "/"
68 #error cfgpath.h functions have not been implemented for your platform! Please send patches.
99 const char *out_orig =
out;
100 char *home = getenv(
"XDG_CONFIG_HOME");
101 unsigned int config_len = 0;
103 home = getenv(
"HOME");
109 config_len = strlen(
".config/");
112 unsigned int home_len = strlen(home);
113 unsigned int appname_len = strlen(appname);
114 const int ext_len = strlen(
".conf");
117 if (home_len + 1 + config_len + appname_len + ext_len + 1 > maxlen) {
122 memcpy(
out, home, home_len);
127 memcpy(
out,
".config/", config_len);
131 mkdir(out_orig, 0755);
133 memcpy(
out, appname, appname_len);
135 memcpy(
out,
".conf", ext_len);
138 #elif defined(CFGPATH_WINDOWS)
139 if (maxlen < MAX_PATH) {
143 if (!SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0,
out))) {
148 unsigned int appname_len = strlen(appname);
149 if (strlen(
out) + 1 + appname_len + strlen(
".ini") + 1 > maxlen) {
154 strcat(
out, appname);
156 #elif defined(CFGPATH_MAC)
158 FSFindFolder(kUserDomain, kApplicationSupportFolderType, kCreateFolder, &ref);
160 FSRefMakePath(&ref, (UInt8 *)&home, MAX_PATH);
162 const char *ext =
".conf";
163 if (strlen(home) + 1 + strlen(appname) + strlen(ext) + 1 > maxlen) {
169 strcat(
out, PATH_SEPARATOR_STRING);
170 strcat(
out, appname);
206 const char *out_orig =
out;
207 char *home = getenv(
"XDG_CONFIG_HOME");
208 unsigned int config_len = 0;
210 home = getenv(
"HOME");
216 config_len = strlen(
".config/");
219 unsigned int home_len = strlen(home);
220 unsigned int appname_len = strlen(appname);
223 if (home_len + 1 + config_len + appname_len + 1 + 1 > maxlen) {
228 memcpy(
out, home, home_len);
233 memcpy(
out,
".config/", config_len);
237 mkdir(out_orig, 0755);
239 memcpy(
out, appname, appname_len);
243 mkdir(out_orig, 0755);
247 #elif defined(CFGPATH_WINDOWS)
248 if (maxlen < MAX_PATH) {
252 if (!SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0,
out))) {
257 unsigned int appname_len = strlen(appname);
258 if (strlen(
out) + 1 + appname_len + 1 + 1 > maxlen) {
263 strcat(
out, appname);
267 #elif defined(CFGPATH_MAC)
269 FSFindFolder(kUserDomain, kApplicationSupportFolderType, kCreateFolder, &ref);
271 FSRefMakePath(&ref, (UInt8 *)&home, MAX_PATH);
273 if (strlen(home) + 1 + strlen(appname) + 1 + 1 > maxlen) {
279 strcat(
out, PATH_SEPARATOR_STRING);
280 strcat(
out, appname);
283 strcat(
out, PATH_SEPARATOR_STRING);
323 const char *out_orig =
out;
324 char *home = getenv(
"XDG_DATA_HOME");
325 unsigned int config_len = 0;
327 home = getenv(
"HOME");
333 config_len = strlen(
".local/share/");
336 unsigned int home_len = strlen(home);
337 unsigned int appname_len = strlen(appname);
340 if (home_len + 1 + config_len + appname_len + 1 + 1 > maxlen) {
345 memcpy(
out, home, home_len);
350 memcpy(
out,
".local/share/", config_len);
354 mkdir(out_orig, 0755);
356 memcpy(
out, appname, appname_len);
360 mkdir(out_orig, 0755);
364 #elif defined(CFGPATH_WINDOWS) || defined(CFGPATH_MAC)
408 const char *out_orig =
out;
409 char *home = getenv(
"XDG_CACHE_HOME");
410 unsigned int config_len = 0;
412 home = getenv(
"HOME");
418 config_len = strlen(
".cache/");
421 unsigned int home_len = strlen(home);
422 unsigned int appname_len = strlen(appname);
425 if (home_len + 1 + config_len + appname_len + 1 + 1 > maxlen) {
430 memcpy(
out, home, home_len);
435 memcpy(
out,
".cache/", config_len);
439 mkdir(out_orig, 0755);
441 memcpy(
out, appname, appname_len);
445 mkdir(out_orig, 0755);
449 #elif defined(CFGPATH_WINDOWS)
450 if (maxlen < MAX_PATH) {
454 if (!SUCCEEDED(SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, 0,
out))) {
459 unsigned int appname_len = strlen(appname);
460 if (strlen(
out) + 1 + appname_len + 1 + 1 > maxlen) {
465 strcat(
out, appname);
469 #elif defined(CFGPATH_MAC)