From c013f078abf068323132bc3fe44927ce5af41018 Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Sun, 11 Feb 2024 19:49:14 +0100 Subject: [PATCH] use ~/.config if $XDG_CONFIG_HOME isn't present --- README.md | 2 +- modfetch.c | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8ae0084..df64006 100644 --- a/README.md +++ b/README.md @@ -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: ``` diff --git a/modfetch.c b/modfetch.c index 297a520..d1134ea 100644 --- a/modfetch.c +++ b/modfetch.c @@ -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); }