use ~/.config if $XDG_CONFIG_HOME isn't present

This commit is contained in:
jacekpoz 2024-02-11 19:49:14 +01:00
parent 274df36583
commit c013f078ab
No known key found for this signature in database
GPG key ID: 94E812A8B12AAE3C
2 changed files with 10 additions and 2 deletions

View file

@ -18,7 +18,7 @@ write your own using `mod.h` if you want to
## config
by default `$XDG_CONFIG_HOME/modfetch.conf`
by default `$XDG_CONFIG_HOME/modfetch.conf`, `~/.config/modfetch.conf` if `$XDG_CONFIG_HOME` doesn't exist
format:
```

View file

@ -211,8 +211,16 @@ Config parse_config(FILE *config_file) {
int main(int argc, char *argv[]) {
char *config_path;
char *config_dir = getenv("XDG_CONFIG_HOME");
if (config_dir == NULL) {
char *home = getenv("$HOME");
if (asprintf(&config_dir, "%s/.config", home) < 0) {
fprintf(stderr, "error: failed formatting config dir (this shouldn't happen)");
exit(EXIT_FAILURE);
}
}
if (asprintf(&config_path, "%s/modfetch.conf", getenv("XDG_CONFIG_HOME")) < 0) {
if (asprintf(&config_path, "%s/modfetch.conf", config_dir) < 0) {
fprintf(stderr, "error: failed formatting config path (this shouldn't happen)");
exit(EXIT_FAILURE);
}