summaryrefslogtreecommitdiff
path: root/user/i3status/glob_tilde.patch
blob: 87177d78e5383326ee984f8ffd7386b357656d69 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
diff --git a/i3status.c b/i3status.c
index 0898da3..f4b10fd 100644
--- a/i3status.c
+++ b/i3status.c
@@ -207,35 +207,23 @@ static int valid_color(const char *value) {
 
 /*
  * This function resolves ~ in pathnames.
- * It may resolve wildcards in the first part of the path, but if no match
- * or multiple matches are found, it just returns a copy of path as given.
+ * The syntax '~user' is not supported.
  *
  */
 static char *resolve_tilde(const char *path) {
-    static glob_t globbuf;
-    char *head, *tail, *result = NULL;
-
-    tail = strchr(path, '/');
-    head = strndup(path, tail ? (size_t)(tail - path) : strlen(path));
-
-    int res = glob(head, GLOB_TILDE, NULL, &globbuf);
-    free(head);
-    /* no match, or many wildcard matches are bad */
-    if (res == GLOB_NOMATCH || globbuf.gl_pathc != 1)
-        result = sstrdup(path);
-    else if (res != 0) {
-        die("glob() failed");
-    } else {
-        head = globbuf.gl_pathv[0];
-        result = scalloc(strlen(head) + (tail ? strlen(tail) : 0) + 1);
-        strcpy(result, head);
-        if (tail) {
-            strcat(result, tail);
+    char *home, *result = NULL;
+
+    if (path[0] == '~' && (path[1] == '/' || path[1] == '\0')) {
+        home = getenv("HOME");
+        if (home != NULL) {
+            result = scalloc(strlen(home) + strlen(path));
+            strcpy(result, home);
+            strcat(result, path + 1);
+            return result;
         }
     }
-    globfree(&globbuf);
 
-    return result;
+    return sstrdup(path);
 }
 
 static char *get_config_path(void) {
diff --git a/include/i3status.h b/include/i3status.h
index 217376a..34e44a0 100644
--- a/include/i3status.h
+++ b/include/i3status.h
@@ -241,4 +241,9 @@ extern cfg_t *cfg, *cfg_general, *cfg_section;
 extern void **cur_instance;
 
 extern pthread_t main_thread;
+
+#ifndef GLOB_TILDE
+#define GLOB_TILDE 0
+#endif
+
 #endif