From de0a7c547fa13491a70df787084ee15c30253cf3 Mon Sep 17 00:00:00 2001 From: Martin Lund Date: Sun, 14 Apr 2024 12:52:28 +0200 Subject: [PATCH] Rework resolve_config_file() --- src/configfile.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/configfile.c b/src/configfile.c index b1ef72c..b123071 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -393,30 +393,36 @@ static int resolve_config_file(void) char *xdg = getenv("XDG_CONFIG_HOME"); if (xdg) { - asprintf(&c.path, "%s/tio/config", xdg); - if (access(c.path, F_OK) == 0) + if (asprintf(&c.path, "%s/tio/config", xdg) != -1) { - return 0; + if (access(c.path, F_OK) == 0) + { + return 0; + } + free(c.path); } - free(c.path); } char *home = getenv("HOME"); if (home) { - asprintf(&c.path, "%s/.config/tio/config", home); - if (access(c.path, F_OK) == 0) + if (asprintf(&c.path, "%s/.config/tio/config", home) != -1) { - return 0; + if (access(c.path, F_OK) == 0) + { + return 0; + } + free(c.path); } - free(c.path); - asprintf(&c.path, "%s/.tioconfig", home); - if (access(c.path, F_OK) == 0) + if (asprintf(&c.path, "%s/.tioconfig", home) != -1) { - return 0; + if (access(c.path, F_OK) == 0) + { + return 0; + } + free(c.path); } - free(c.path); } c.path = NULL;