From aa1b7374db3a1b36959ec03b892d415b6b1e33d9 Mon Sep 17 00:00:00 2001 From: Ikey Doherty Date: Tue, 14 Nov 2017 21:10:35 +0000 Subject: [PATCH] common: Respect XDG specification for directories If `XDG_{DATA,CONFIG}_HOME` variables are set in the environment, use those to ensure portability and integration with the platform. This ensures we always use the right locations for accessing config files and the Steam root. This fixes #34. Signed-off-by: Ikey Doherty --- src/common/files.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/common/files.c b/src/common/files.c index 32a7cbd..dbcaac9 100644 --- a/src/common/files.c +++ b/src/common/files.c @@ -52,8 +52,16 @@ const char *lsi_get_home_dir() char *lsi_get_user_config_dir() { - const char *home = lsi_get_home_dir(); + const char *home = NULL; char *c = NULL; + char *xdg_config = getenv("XDG_CONFIG_HOME"); + + /* Respect the XDG_CONFIG_HOME variable if it is set */ + if (xdg_config) { + return strdup(xdg_config); + } + + home = lsi_get_home_dir(); if (asprintf(&c, "%s/.config", home) < 0) { return NULL; } @@ -66,6 +74,13 @@ char *lsi_get_user_config_dir() static inline char *lsi_get_fallback_steam_dir(const char *home) { char *p = NULL; + char *xdg_data = getenv("XDG_DATA_HOME"); + + /* Respect the XDG_CONFIG_HOME variable if it is set */ + if (xdg_data) { + return strdup(xdg_data); + } + if (asprintf(&p, "%s/.local/share/Steam", home) < 0) { return NULL; }