7 void path_strip(char *str
)
18 while (str
[s
] && str
[s
] == '/')
24 } else if (i
&& str
[i
] == '.') {
25 if (str
[i
+ 1] == '/') {
31 } else if (str
[i
+ 1] == 0) {
34 } else if (str
[i
+ 1] == '.' &&
35 (str
[i
+ 2] == '/' || str
[i
+ 2] == 0)) {
43 d
= i
- 1; /* /../ccc */
48 } while (str
[d
] != '/');
50 /* std[d] is bbb/../ccc */
57 while (str
[i
] && str
[i
] != '/')
63 while (str
[i
] && str
[i
] != '/')
69 if (i
> 1 && str
[i
- 1] == '/')
73 char *path_absolute_cwd(const char *src
, const char *cwd
)
78 /* already absolute */
84 src_len
= strlen(src
);
85 cwd_len
= strlen(cwd
);
86 str
= xnew(char, cwd_len
+ 1 + src_len
+ 1);
87 memcpy(str
, cwd
, cwd_len
);
89 memcpy(str
+ cwd_len
+ 1, src
, src_len
+ 1);
95 char *path_absolute(const char *src
)
99 if (!getcwd(cwd
, sizeof(cwd
))) {
103 return path_absolute_cwd(src
, cwd
);