aboutsummaryrefslogtreecommitdiffstats
path: root/src/config-ini.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-03-11 18:33:00 +0100
committerMattias Andrée <maandree@operamail.com>2014-03-11 18:33:00 +0100
commit68deadbda4a9ddc508d421591ddb902d22c85f97 (patch)
tree7aa7e5c416b9aae4dbfcf50f812894eddc6edb2a /src/config-ini.c
parentWhen looking for a redshift.conf file do not just check environment variable, also check that the file exists (diff)
downloadredshift-ng-68deadbda4a9ddc508d421591ddb902d22c85f97.tar.gz
redshift-ng-68deadbda4a9ddc508d421591ddb902d22c85f97.tar.bz2
redshift-ng-68deadbda4a9ddc508d421591ddb902d22c85f97.tar.xz
Look for configuration file in XDG_CONFIG_DIRS and /etc
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/config-ini.c')
-rw-r--r--src/config-ini.c33
1 files changed, 30 insertions, 3 deletions
diff --git a/src/config-ini.c b/src/config-ini.c
index 8449a8d..bc8e00a 100644
--- a/src/config-ini.c
+++ b/src/config-ini.c
@@ -82,16 +82,43 @@ open_config_file(const char *filepath)
"%s/.config/redshift.conf", home);
if (!stat(cp, &attr))
filepath = cp;
-#endif
}
+ if (filepath == NULL && (env = getenv("XDG_CONFIG_DIRS")) != NULL &&
+ env[0] != '\0') {
+ int conf_dirs_len = strlen(env);
+ int conf_dir_ptr = 0;
+ char *conf_dir = alloca((conf_dirs_len + 1) * sizeof(char));
+ int i;
+ for (i = 0; i < conf_dirs_len; i++) {
+ char c = env[i];
+ if (c == ':' || c == '\0') {
+ conf_dir[conf_dir_ptr] = '\0';
+ conf_dir_ptr = 0;
+ if (conf_dir[0] != '\0') {
+ snprintf(cp, sizeof(cp),
+ "%s/redshift.conf", conf_dir);
+ if (!stat(cp, &attr)) {
+ filepath = cp;
+ break;
+ }
+ }
+ } else
+ conf_dir[conf_dir_ptr++] = c;
+ }
+ }
+ if (filepath == NULL) {
+ snprintf(cp, sizeof(cp),
+ "%s/redshift.conf", "/etc");
+ if (!stat(cp, &attr))
+ filepath = cp;
+ }
+#endif
if (filepath != NULL) {
f = fopen(filepath, "r");
if (f != NULL) return f;
else if (f == NULL && errno != ENOENT) return NULL;
}
-
- /* TODO look in getenv("XDG_CONFIG_DIRS") */
} else {
f = fopen(filepath, "r");
if (f == NULL) {