Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 609306 | Differences between
and this patch

Collapse All | Expand All

(-)i3-4.11/i3bar/src/main.c (-7 / +13 lines)
Lines 45-58 void debuglog(char *fmt, ...) { Link Here
45
 *
45
 *
46
 */
46
 */
47
char *expand_path(char *path) {
47
char *expand_path(char *path) {
48
    static glob_t globbuf;
48
    char *home, *expanded;
49
    if (glob(path, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) < 0) {
49
50
        ELOG("glob() failed\n");
50
    if (strncmp(path, "~/", 2) == 0) {
51
        exit(EXIT_FAILURE);
51
        home = getenv("HOME");
52
        if (home != NULL) {
53
            /* new length: sum - 1 (omit '~') + 1 (for '\0') */
54
            expanded = scalloc(strlen(home)+strlen(path), 1);
55
            strcpy(expanded, home);
56
            strcat(expanded, path+1);
57
            return expanded;
58
        }
52
    }
59
    }
53
    char *result = sstrdup(globbuf.gl_pathc > 0 ? globbuf.gl_pathv[0] : path);
60
54
    globfree(&globbuf);
61
    return sstrdup(path);
55
    return result;
56
}
62
}
57
63
58
void print_usage(char *elf_name) {
64
void print_usage(char *elf_name) {
(-)i3-4.11/libi3/resolve_tilde.c (-20 / +11 lines)
Lines 19-45 Link Here
19
 *
19
 *
20
 */
20
 */
21
char *resolve_tilde(const char *path) {
21
char *resolve_tilde(const char *path) {
22
    static glob_t globbuf;
22
    char *home, *expanded;
23
    char *head, *tail, *result;
24
23
25
    tail = strchr(path, '/');
24
    if (strncmp(path, "~/", 2) == 0) {
26
    head = sstrndup(path, tail ? (size_t)(tail - path) : strlen(path));
25
        home = getenv("HOME");
27
26
        if (home != NULL) {
28
    int res = glob(head, GLOB_TILDE, NULL, &globbuf);
27
            /* new length: sum - 1 (omit '~') + 1 (for '\0') */
29
    free(head);
28
            expanded = scalloc(strlen(home)+strlen(path), 1);
30
    /* no match, or many wildcard matches are bad */
29
            strcpy(expanded, home);
31
    if (res == GLOB_NOMATCH || globbuf.gl_pathc != 1)
30
            strcat(expanded, path+1);
32
        result = sstrdup(path);
31
            return expanded;
33
    else if (res != 0) {
32
        }
34
        err(EXIT_FAILURE, "glob() failed");
35
    } else {
36
        head = globbuf.gl_pathv[0];
37
        result = scalloc(strlen(head) + (tail ? strlen(tail) : 0) + 1, 1);
38
        strncpy(result, head, strlen(head));
39
        if (tail)
40
            strncat(result, tail, strlen(tail));
41
    }
33
    }
42
    globfree(&globbuf);
43
34
44
    return result;
35
    return sstrdup(path);
45
}
36
}

Return to bug 609306