summaryrefslogtreecommitdiff
path: root/common/path.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/path.c')
-rw-r--r--common/path.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/common/path.c b/common/path.c
index d807301..a22c2a6 100644
--- a/common/path.c
+++ b/common/path.c
@@ -91,19 +91,40 @@ p11_path_base (const char *path)
return strndup (beg, end - beg);
}
+static inline bool
+is_path_component_or_null (char ch)
+{
+ return (ch == '\0' || ch == '/'
+#ifdef OS_WIN32
+ || ch == '\\'
+#endif
+ );
+}
+
static char *
expand_homedir (const char *remainder)
{
const char *env;
- if (remainder[0] == '\0')
- remainder = NULL;
-
if (getauxval (AT_SECURE)) {
errno = EPERM;
return NULL;
}
+ while (remainder[0] && is_path_component_or_null (remainder[0]))
+ remainder++;
+ if (remainder[0] == '\0')
+ remainder = NULL;
+
+ /* Expand $XDG_CONFIG_HOME */
+ if (remainder != NULL &&
+ strncmp (remainder, ".config", 7) == 0 &&
+ is_path_component_or_null (remainder[7])) {
+ env = getenv ("XDG_CONFIG_HOME");
+ if (env && env[0])
+ return p11_path_build (env, remainder + 8, NULL);
+ }
+
env = getenv ("HOME");
if (env && env[0]) {
return p11_path_build (env, remainder, NULL);
@@ -139,16 +160,6 @@ expand_homedir (const char *remainder)
}
}
-static inline bool
-is_path_component_or_null (char ch)
-{
- return (ch == '\0' || ch == '/'
-#ifdef OS_WIN32
- || ch == '\\'
-#endif
- );
-}
-
char *
p11_path_expand (const char *path)
{