From a18c298ad446f016a90cfa0db1dd911de5a94f25 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 15 Mar 2021 10:14:38 +0100 Subject: [PATCH] Don't use ~/.config when XDG_CONFIG_HOME is set According to the spec, ~/.config is a fallback used when XDG_CONFIG_HOME is unset. When the user has explicitly set XDG_CONFIG_HOME, we shouldn't try to use the fallback. --- src/core/config.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/core/config.c b/src/core/config.c index e9fe946..c19da34 100644 --- a/src/core/config.c +++ b/src/core/config.c @@ -91,16 +91,20 @@ static char *get_config_path(void) { char *config_home_fallback = calloc(size_fallback, sizeof(char)); snprintf(config_home_fallback, size_fallback, "%s/.config", home); - const char *prefix[3]; - prefix[0] = getenv("XDG_CONFIG_HOME"); - prefix[1] = config_home_fallback; - prefix[2] = SYSCONFDIR "/xdg"; + const char *config_home = getenv("XDG_CONFIG_HOME"); + if (config_home == NULL || config_home[0] == '\0') { + config_home = config_home_fallback; + } + + const char *prefix[2]; + prefix[0] = config_home; + prefix[1] = SYSCONFDIR "/xdg"; const char *config[2]; config[0] = getenv("XDG_CURRENT_DESKTOP"); config[1] = "config"; - for (size_t i = 0; i < 3; i++) { + for (size_t i = 0; i < 2; i++) { for (size_t j = 0; j < 2; j++) { char *path = config_path(prefix[i], config[j]); if (!path) {