common: Return realpath'd config dir where possible

This ensures we only use a sane realpath and collapse the slashes where
we can to allow trivial string matching.

Signed-off-by: Ikey Doherty <ikey@solus-project.com>
This commit is contained in:
Ikey Doherty
2017-12-19 12:23:20 +00:00
parent 7cfdd41c7c
commit f12643039a
+10
View File
@@ -55,9 +55,14 @@ char *lsi_get_user_config_dir()
const char *home = NULL;
char *c = NULL;
char *xdg_config = getenv("XDG_CONFIG_HOME");
char *p = NULL;
/* Respect the XDG_CONFIG_HOME variable if it is set */
if (xdg_config) {
p = realpath(xdg_config, NULL);
if (p) {
return p;
}
return strdup(xdg_config);
}
@@ -65,6 +70,11 @@ char *lsi_get_user_config_dir()
if (asprintf(&c, "%s/.config", home) < 0) {
return NULL;
}
p = realpath(c, NULL);
if (p) {
free(c);
return p;
}
return c;
}