[SDL2][X11] respect XDG base directory · AZO234/NP2kai@56a1cc2
@@ -188,30 +188,38 @@ main(int argc, char *argv[])
188188argv += optind;
189189190190if (modulefile[0] == '\0') {
191-char *env = getenv("HOME");
192-if (env) {
191+char *config_home = getenv("XDG_CONFIG_HOME");
192+char *home = getenv("HOME");
193+if (config_home && config_home[0] == '/') {
193194/* base dir */
194195g_snprintf(modulefile, sizeof(modulefile),
195-"%s/.config/xnp2kai/", env);
196-if (stat(modulefile, &sb) < 0) {
197-if (mkdir(modulefile, 0700) < 0) {
198-perror(modulefile);
199-exit(1);
200- }
201- } else if (!S_ISDIR(sb.st_mode)) {
202-g_printerr("%s isn't directory.\n",
203-modulefile);
196+"%s/xnp2kai/", config_home);
197+ } else if (home) {
198+/* base dir */
199+g_snprintf(modulefile, sizeof(modulefile),
200+"%s/.config/xnp2kai/", home);
201+ } else {
202+g_printerr("$HOME isn't defined.\n");
203+exit(1);
204+ }
205+if (stat(modulefile, &sb) < 0) {
206+if (mkdir(modulefile, 0700) < 0) {
207+perror(modulefile);
204208exit(1);
205209 }
210+ } else if (!S_ISDIR(sb.st_mode)) {
211+g_printerr("%s isn't directory.\n",
212+modulefile);
213+exit(1);
214+ }
206215207-/* config file */
208-milstr_ncat(modulefile, appname, sizeof(modulefile));
209-milstr_ncat(modulefile, "rc", sizeof(modulefile));
210-if ((stat(modulefile, &sb) >= 0)
211-&& !S_ISREG(sb.st_mode)) {
212-g_printerr("%s isn't regular file.\n",
213-modulefile);
214- }
216+/* config file */
217+milstr_ncat(modulefile, appname, sizeof(modulefile));
218+milstr_ncat(modulefile, "rc", sizeof(modulefile));
219+if ((stat(modulefile, &sb) >= 0)
220+&& !S_ISREG(sb.st_mode)) {
221+g_printerr("%s isn't regular file.\n",
222+modulefile);
215223 }
216224 }
217225if (modulefile[0] != '\0') {