Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 8026076

Browse files
authored
Merge pull request #608 from kakurasan/xdg-spec
Fix #606
2 parents 36e7877 + 9ff0501 commit 8026076

1 file changed

Lines changed: 29 additions & 5 deletions

File tree

src/config-ini.c

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,15 @@ open_config_file(const char *filepath)
6363

6464
if (f == NULL && (env = getenv("XDG_CONFIG_HOME")) != NULL &&
6565
env[0] != '\0') {
66-
snprintf(cp, sizeof(cp), "%s/redshift.conf", env);
66+
snprintf(cp, sizeof(cp),
67+
"%s/redshift/redshift.conf", env);
6768
f = fopen(cp, "r");
69+
if (f == NULL) {
70+
/* Fall back to formerly used path. */
71+
snprintf(cp, sizeof(cp),
72+
"%s/redshift.conf", env);
73+
f = fopen(cp, "r");
74+
}
6875
}
6976

7077
#ifdef _WIN32
@@ -78,17 +85,29 @@ open_config_file(const char *filepath)
7885
if (f == NULL && (env = getenv("HOME")) != NULL &&
7986
env[0] != '\0') {
8087
snprintf(cp, sizeof(cp),
81-
"%s/.config/redshift.conf", env);
88+
"%s/.config/redshift/redshift.conf", env);
8289
f = fopen(cp, "r");
90+
if (f == NULL) {
91+
/* Fall back to formerly used path. */
92+
snprintf(cp, sizeof(cp),
93+
"%s/.config/redshift.conf", env);
94+
f = fopen(cp, "r");
95+
}
8396
}
8497
#ifndef _WIN32
8598

8699
if (f == NULL) {
87100
struct passwd *pwd = getpwuid(getuid());
88101
char *home = pwd->pw_dir;
89102
snprintf(cp, sizeof(cp),
90-
"%s/.config/redshift.conf", home);
103+
"%s/.config/redshift/redshift.conf", home);
91104
f = fopen(cp, "r");
105+
if (f == NULL) {
106+
/* Fall back to formerly used path. */
107+
snprintf(cp, sizeof(cp),
108+
"%s/.config/redshift.conf", home);
109+
f = fopen(cp, "r");
110+
}
92111
}
93112

94113
if (f == NULL && (env = getenv("XDG_CONFIG_DIRS")) != NULL &&
@@ -101,9 +120,14 @@ open_config_file(const char *filepath)
101120
int len = end - begin;
102121
if (len > 0) {
103122
snprintf(cp, sizeof(cp),
104-
"%.*s/redshift.conf", len, begin);
105-
123+
"%.*s/redshift/redshift.conf", len, begin);
106124
f = fopen(cp, "r");
125+
if (f != NULL) {
126+
/* Fall back to formerly used path. */
127+
snprintf(cp, sizeof(cp),
128+
"%.*s/redshift.conf", len, begin);
129+
f = fopen(cp, "r");
130+
}
107131
if (f != NULL) break;
108132
}
109133

0 commit comments

Comments
 (0)