Mercurial > hg > th-libs
comparison th_file.c @ 740:caeb0a44ebdf
Change th_get_config_dir() API.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 14 Dec 2022 01:31:51 +0200 |
parents | 32dab9b6058a |
children | 0852bd106034 |
comparison
equal
deleted
inserted
replaced
739:32dab9b6058a | 740:caeb0a44ebdf |
---|---|
53 return th_strdup(getenv("HOME")); | 53 return th_strdup(getenv("HOME")); |
54 #endif | 54 #endif |
55 } | 55 } |
56 | 56 |
57 | 57 |
58 char * th_get_config_dir(const char *name) | 58 char * th_get_config_dir(void) |
59 { | 59 { |
60 #if defined(TH_PLAT_WINDOWS) | 60 #if defined(TH_PLAT_WINDOWS) |
61 // For Windows, we just use the appdata directory | 61 // For Windows, we just use the appdata directory |
62 (void) name; | |
63 return th_get_data_dir(); | 62 return th_get_data_dir(); |
64 #elif defined(USE_XDG) | 63 #elif defined(USE_XDG) |
65 const char *xdgConfigDir = getenv("XDG_CONFIG_HOME"); | 64 const char *xdgConfigDir = getenv("XDG_CONFIG_HOME"); |
66 | 65 |
67 // If XDG is enabled, try the environment variable first | 66 // If XDG is enabled, try the environment variable first |
68 if (xdgConfigDir != NULL && strcmp(xdgConfigDir, "")) | 67 if (xdgConfigDir != NULL && strcmp(xdgConfigDir, "")) |
69 { | 68 { |
70 return th_strdup_printf("%s%c%s%c", | 69 return th_strdup_printf("%s%c", |
71 xdgConfigDir, TH_DIR_SEPARATOR_CHR, | 70 xdgConfigDir, TH_DIR_SEPARATOR_CHR); |
72 name, TH_DIR_SEPARATOR_CHR); | |
73 } | 71 } |
74 else | 72 else |
75 { | 73 { |
76 // Nope, try the obvious alternative | 74 // Nope, try the obvious alternative |
77 char *data = th_get_data_dir(); | 75 char *data = th_get_data_dir(); |
78 char *dir = th_strdup_printf("%s%c%s%c%s%c", | 76 char *dir = th_strdup_printf("%s%c%s%c", |
79 data, TH_DIR_SEPARATOR_CHR, | 77 data, TH_DIR_SEPARATOR_CHR, |
80 ".config", TH_DIR_SEPARATOR_CHR, | 78 ".config", TH_DIR_SEPARATOR_CHR); |
81 name, TH_DIR_SEPARATOR_CHR); | |
82 th_free(data); | 79 th_free(data); |
83 return dir; | 80 return dir; |
84 } | 81 } |
85 #else | 82 #else |
86 // XDG not enabled | 83 // XDG not enabled |
87 (void) name; | |
88 return th_get_data_dir(); | 84 return th_get_data_dir(); |
89 #endif | 85 #endif |
90 } | 86 } |
91 | 87 |
92 | 88 |