Add XDG_CONFIG_HOME compatability (#954)

This commit is contained in:
Tom Swartz
2019-02-02 04:15:50 -05:00
committed by Christian W. Zuckschwerdt
parent 640fc57904
commit 2c7fbd90e9
2 changed files with 7 additions and 3 deletions

View File

@@ -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

View File

@@ -8,7 +8,7 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#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";