Skip to content

Commit

Permalink
Fallback to AppData if XDG_CONFIG_HOME is unset
Browse files Browse the repository at this point in the history
  • Loading branch information
ariellourenco committed Jun 29, 2024
1 parent 80ed467 commit 0a250b7
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions path.c
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,8 @@ int looks_like_command_line_option(const char *str)

char *xdg_config_home_for(const char *subdir, const char *filename)
{
const char *home, *config_home;
const char *appdata, *home, *config_home;

Check failure on line 1575 in path.c

View workflow job for this annotation

GitHub Actions / fuzz smoke test

path.c:1575:14: unused variable 'appdata' [-Werror,-Wunused-variable]

Check failure on line 1575 in path.c

View workflow job for this annotation

GitHub Actions / linux32 (daald/ubuntu32:xenial)

path.c:1575:14: unused variable 'appdata' [-Werror=unused-variable]

Check failure on line 1575 in path.c

View workflow job for this annotation

GitHub Actions / linux-musl (alpine)

path.c:1575:21: unused variable 'appdata' [-Werror=unused-variable]

Check failure on line 1575 in path.c

View workflow job for this annotation

GitHub Actions / pedantic (fedora)

path.c:1575:21: unused variable 'appdata' [-Werror=unused-variable]

Check failure on line 1575 in path.c

View workflow job for this annotation

GitHub Actions / linux-asan-ubsan (ubuntu-latest)

path.c:1575:14: unused variable 'appdata' [-Werror,-Wunused-variable]

Check failure on line 1575 in path.c

View workflow job for this annotation

GitHub Actions / linux-gcc (ubuntu-20.04)

path.c:1575:14: unused variable ‘appdata’ [-Werror=unused-variable]

Check failure on line 1575 in path.c

View workflow job for this annotation

GitHub Actions / linux-gcc-default (ubuntu-latest)

path.c:1575:21: unused variable ‘appdata’ [-Werror=unused-variable]

Check failure on line 1575 in path.c

View workflow job for this annotation

GitHub Actions / linux-leaks (ubuntu-latest)

path.c:1575:21: unused variable ‘appdata’ [-Werror=unused-variable]

Check failure on line 1575 in path.c

View workflow job for this annotation

GitHub Actions / linux-reftable-leaks (ubuntu-latest)

path.c:1575:21: unused variable ‘appdata’ [-Werror=unused-variable]

Check failure on line 1575 in path.c

View workflow job for this annotation

GitHub Actions / linux-sha256 (ubuntu-latest)

path.c:1575:14: unused variable 'appdata' [-Werror,-Wunused-variable]

Check failure on line 1575 in path.c

View workflow job for this annotation

GitHub Actions / linux-TEST-vars (ubuntu-20.04)

path.c:1575:14: unused variable ‘appdata’ [-Werror=unused-variable]
char *home_config = NULL;

assert(subdir);
assert(filename);
Expand All @@ -1581,10 +1582,24 @@ char *xdg_config_home_for(const char *subdir, const char *filename)
return mkpathdup("%s/%s/%s", config_home, subdir, filename);

home = getenv("HOME");
if (home)
return mkpathdup("%s/.config/%s/%s", home, subdir, filename);
if (home && *home)
home_config = mkpathdup("%s/.config/%s/%s", home, subdir, filename);

#ifdef WIN32
appdata = getenv("APPDATA");
if (appdata && *appdata) {
char *appdata_config = mkpathdup("%s/Git/%s", appdata, appdata, filename);

Check failure on line 1591 in path.c

View workflow job for this annotation

GitHub Actions / win build

path.c:1591:50: too many arguments for format [-Werror=format-extra-args]
if (file_exists(appdata_config)) {
if (home_config && file_exists(home_config))
warning("'%s' was ignored because '%s' exists.", home_config, appdata_config);
free(home_config);
return appdata_config;
}
free(appdata_config);
}
#endif

return NULL;
return home_config;
}

char *xdg_config_home(const char *filename)
Expand Down

0 comments on commit 0a250b7

Please sign in to comment.