use ~/.config if $XDG_CONFIG_HOME isn't present
This commit is contained in:
parent
274df36583
commit
c013f078ab
2 changed files with 10 additions and 2 deletions
|
@ -18,7 +18,7 @@ write your own using `mod.h` if you want to
|
||||||
|
|
||||||
## config
|
## 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:
|
format:
|
||||||
```
|
```
|
||||||
|
|
10
modfetch.c
10
modfetch.c
|
@ -211,8 +211,16 @@ Config parse_config(FILE *config_file) {
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
char *config_path;
|
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)");
|
fprintf(stderr, "error: failed formatting config path (this shouldn't happen)");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue