Rev 3255 | Rev 3306 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3255 | Rev 3292 | ||
---|---|---|---|
Line 60... | Line 60... | ||
60 | size_t cwd_len = 0; |
60 | size_t cwd_len = 0; |
61 | 61 | ||
62 | static char *absolutize(const char *path, size_t *retlen) |
62 | static char *absolutize(const char *path, size_t *retlen) |
63 | { |
63 | { |
64 | char *ncwd_path; |
64 | char *ncwd_path; |
- | 65 | char *ncwd_path_nc; |
|
65 | 66 | ||
66 | futex_down(&cwd_futex); |
67 | futex_down(&cwd_futex); |
67 | size_t len = strlen(path); |
68 | size_t len = strlen(path); |
68 | if (*path != '/') { |
69 | if (*path != '/') { |
69 | if (!cwd_path) { |
70 | if (!cwd_path) { |
70 | futex_up(&cwd_futex); |
71 | futex_up(&cwd_futex); |
71 | return NULL; |
72 | return NULL; |
72 | } |
73 | } |
73 | ncwd_path = malloc(len + cwd_len + 1); |
74 | ncwd_path_nc = malloc(len + cwd_len + 1); |
74 | if (!ncwd_path) { |
75 | if (!ncwd_path_nc) { |
75 | futex_up(&cwd_futex); |
76 | futex_up(&cwd_futex); |
76 | return NULL; |
77 | return NULL; |
77 | } |
78 | } |
78 | strcpy(ncwd_path, cwd_path); |
79 | strcpy(ncwd_path_nc, cwd_path); |
79 | ncwd_path[cwd_len] = '/'; |
80 | ncwd_path_nc[cwd_len] = '/'; |
80 | ncwd_path[cwd_len + 1] = '\0'; |
81 | ncwd_path_nc[cwd_len + 1] = '\0'; |
81 | } else { |
82 | } else { |
82 | ncwd_path = malloc(len + 1); |
83 | ncwd_path_nc = malloc(len + 1); |
83 | if (!ncwd_path) { |
84 | if (!ncwd_path_nc) { |
84 | futex_up(&cwd_futex); |
85 | futex_up(&cwd_futex); |
85 | return NULL; |
86 | return NULL; |
86 | } |
87 | } |
87 | ncwd_path[0] = '\0'; |
88 | ncwd_path_nc[0] = '\0'; |
88 | } |
89 | } |
89 | strcat(ncwd_path, path); |
90 | strcat(ncwd_path_nc, path); |
90 | if (!canonify(ncwd_path, retlen)) { |
91 | ncwd_path = canonify(ncwd_path_nc, retlen); |
- | 92 | if (!ncwd_path) { |
|
- | 93 | futex_up(&cwd_futex); |
|
- | 94 | free(ncwd_path_nc); |
|
- | 95 | return NULL; |
|
- | 96 | } |
|
- | 97 | /* |
|
- | 98 | * We need to clone ncwd_path because canonify() works in-place and thus |
|
- | 99 | * the address in ncwd_path need not be the same as ncwd_path_nc, even |
|
- | 100 | * though they both point into the same dynamically allocated buffer. |
|
- | 101 | */ |
|
- | 102 | ncwd_path = strdup(ncwd_path); |
|
- | 103 | free(ncwd_path_nc); |
|
- | 104 | if (!ncwd_path) { |
|
91 | futex_up(&cwd_futex); |
105 | futex_up(&cwd_futex); |
92 | free(ncwd_path); |
- | |
93 | return NULL; |
106 | return NULL; |
94 | } |
107 | } |
95 | futex_up(&cwd_futex); |
108 | futex_up(&cwd_futex); |
96 | return ncwd_path; |
109 | return ncwd_path; |
97 | } |
110 | } |