diff options
author | Chris Robinson <[email protected]> | 2013-06-16 22:55:11 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2013-06-16 22:55:11 -0700 |
commit | 3c90ed95afa1feed70e6c5655cfeec096c00c23b (patch) | |
tree | 2440469ecd590334c349810a3aa6e0e2926173b9 | |
parent | 48d50021905ff8275cf7b828213c31bd55cbe51f (diff) |
Look for alsoft.conf in the XDG_CONFIG_DIRS and XDG_CONFIG_HOME directories
This follows the XDG Base Directory Specification. The old files/locations are
still supported, but configs found in XDG_CONFIG_DIRS take precedence over
/etc/openal/alsoft.conf, and a config found in XDG_CONFIG_HOME takes precedence
over $HOME/.alsoftrc.
-rw-r--r-- | Alc/alcConfig.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/Alc/alcConfig.c b/Alc/alcConfig.c index 832a17a3..accc0716 100644 --- a/Alc/alcConfig.c +++ b/Alc/alcConfig.c @@ -206,6 +206,41 @@ void ReadALConfig(void) LoadConfigFromFile(f); fclose(f); } + + if(!(str=getenv("XDG_CONFIG_DIRS")) || str[0] == 0) + str = "/etc/xdg"; + strncpy(buffer, str, sizeof(buffer)-1); + buffer[sizeof(buffer)-1] = 0; + /* Go through the list in reverse, since "the order of base directories + * denotes their importance; the first directory listed is the most + * important". Ergo, we need to load the settings from the later dirs + * first so that the settings in the earlier dirs override them. + */ + while(1) + { + char *next = strrchr(buffer, ':'); + if(next) *(next++) = 0; + else next = buffer; + + if(next[0] != '/') + continue; + { + size_t len = strlen(next); + strncpy(next+len, "/alsoft.conf", buffer+sizeof(buffer)-next-len); + buffer[sizeof(buffer)-1] = 0; + } + + TRACE("Loading config %s...\n", next); + f = fopen(next, "r"); + if(f) + { + LoadConfigFromFile(f); + fclose(f); + } + if(next == buffer) + break; + } + if((str=getenv("HOME")) != NULL && *str) { snprintf(buffer, sizeof(buffer), "%s/.alsoftrc", str); @@ -218,7 +253,27 @@ void ReadALConfig(void) fclose(f); } } + + if((str=getenv("XDG_CONFIG_HOME")) != NULL && str[0] != 0) + snprintf(buffer, sizeof(buffer), "%s/%s", str, "alsoft.conf"); + else + { + buffer[0] = 0; + if((str=getenv("HOME")) != NULL && str[0] != 0) + snprintf(buffer, sizeof(buffer), "%s/.config/%s", str, "alsoft.conf"); + } + if(buffer[0] != 0) + { + TRACE("Loading config %s...\n", buffer); + f = fopen(buffer, "r"); + if(f) + { + LoadConfigFromFile(f); + fclose(f); + } + } #endif + if((str=getenv("ALSOFT_CONF")) != NULL && *str) { TRACE("Loading config %s...\n", str); |