+ free(config_path);
+
+ /* 3: check the traditional path under /etc */
+ config_path = SYSCONFDIR "/i3/config";
+ if (path_exists(config_path))
+ return sstrdup(config_path);
+
+ /* 4: check for $XDG_CONFIG_DIRS/i3/config */
+ if ((xdg_config_dirs = getenv("XDG_CONFIG_DIRS")) == NULL)
+ xdg_config_dirs = "/etc/xdg";
+
+ char *buf = sstrdup(xdg_config_dirs);
+ char *tok = strtok(buf, ":");
+ while (tok != NULL) {
+ tok = resolve_tilde(tok);
+ if (asprintf(&config_path, "%s/i3/config", tok) == -1)
+ die("asprintf() failed");
+ free(tok);
+ if (path_exists(config_path)) {
+ free(buf);
+ return config_path;
+ }
+ free(config_path);
+ tok = strtok(NULL, ":");
+ }
+ free(buf);
+
+ die("Unable to find the configuration file (looked at "
+ "~/.i3/config, $XDG_CONFIG_HOME/i3/config, "
+ SYSCONFDIR "i3/config and $XDG_CONFIG_DIRS/i3/config)");