From 2c7fbd90e9fe4e3788df70be74eaee9e03c8e130 Mon Sep 17 00:00:00 2001 From: Tom Swartz Date: Sat, 2 Feb 2019 04:15:50 -0500 Subject: [PATCH] Add XDG_CONFIG_HOME compatability (#954) --- conf/rtl_433.example.conf | 2 +- src/compat_paths.c | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/conf/rtl_433.example.conf b/conf/rtl_433.example.conf index 86f75f3e..0ecb7eed 100644 --- a/conf/rtl_433.example.conf +++ b/conf/rtl_433.example.conf @@ -12,7 +12,7 @@ # # If no -c option is given the first found of this list will be loaded: # - ./rtl_433.conf -# - ~/.rtl_433/rtl_433.conf +# - ~/.config/rtl_433/rtl_433.conf # - /usr/local/etc/rtl_433.conf # - /etc/rtl_433.conf diff --git a/src/compat_paths.c b/src/compat_paths.c index 3f88f093..94aa21e1 100644 --- a/src/compat_paths.c +++ b/src/compat_paths.c @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include "compat_paths.h" @@ -17,9 +17,13 @@ char **compat_get_default_conf_paths() { static char *paths[5] = { NULL }; static char buf[256] = ""; + char *env_config_home = getenv("XDG_CONFIG_HOME"); if (!paths[0]) { paths[0] = "rtl_433.conf"; - snprintf(buf, sizeof(buf), "%s%s", getenv("HOME"), "/.rtl_433/rtl_433.conf"); + if (env_config_home && *env_config_home) + snprintf(buf, sizeof(buf), "%s%s", env_config_home, "/rtl_433/rtl_433.conf"); + else + snprintf(buf, sizeof(buf), "%s%s", getenv("HOME"), "/.config/rtl_433/rtl_433.conf"); paths[1] = buf; paths[2] = "/usr/local/etc/rtl_433/rtl_433.conf"; paths[3] = "/etc/rtl_433/rtl_433.conf";