aboutsummaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-07-31 08:08:53 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-07-31 08:08:53 +0000
commit35041cd431d9927c76f9f09ed454c57e58fd8b14 (patch)
tree1a41c00e9db5c77551ddfa5289cc3b32605bf96f /config.c
parenteditorconfig: don’t trim trailing whitespace in *.scd (diff)
parentconfig: include: use xasprintf() instead of two calls to snprintf() (diff)
Merge branch 'tilde-expansion-in-include'
Closes #659
Diffstat (limited to 'config.c')
-rw-r--r--config.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/config.c b/config.c
index f671e7e0..f57129a7 100644
--- a/config.c
+++ b/config.c
@@ -644,12 +644,29 @@ parse_section_main(const char *key, const char *value, struct config *conf,
const char *path, unsigned lineno, bool errors_are_fatal)
{
if (strcmp(key, "include") == 0) {
- const char *include_path = value;
+ char *_include_path = NULL;
+ const char *include_path = NULL;
+
+ if (value[0] == '~' && value[1] == '/') {
+ const char *home_dir = get_user_home_dir();
+
+ if (home_dir == NULL) {
+ LOG_AND_NOTIFY_ERRNO(
+ "%s:%d: [default]: include: %s: failed to expand '~'",
+ path, lineno, value);
+ return false;
+ }
+
+ _include_path = xasprintf("%s/%s", home_dir, value + 2);
+ include_path = _include_path;
+ } else
+ include_path = value;
if (include_path[0] != '/') {
LOG_AND_NOTIFY_ERR(
- "%s:%d: [default]: %s: not an absolute path",
+ "%s:%d: [default]: include: %s: not an absolute path",
path, lineno, include_path);
+ free(_include_path);
return false;
}
@@ -657,8 +674,9 @@ parse_section_main(const char *key, const char *value, struct config *conf,
if (include == NULL) {
LOG_AND_NOTIFY_ERRNO(
- "%s:%d: [default]: %s: failed to open",
+ "%s:%d: [default]: include: %s: failed to open",
path, lineno, include_path);
+ free(_include_path);
return false;
}
@@ -667,6 +685,7 @@ parse_section_main(const char *key, const char *value, struct config *conf,
fclose(include);
LOG_INFO("imported sub-configuration from %s", include_path);
+ free(_include_path);
return ret;
}