6 |
* |
* |
7 |
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
8 |
*/ |
*/ |
|
|
|
9 |
#include "libbb.h" |
#include "libbb.h" |
10 |
|
|
11 |
char* FAST_FUNC bb_simplify_path(const char *path) |
char* FAST_FUNC bb_simplify_abs_path_inplace(char *start) |
12 |
{ |
{ |
13 |
char *s, *start, *p; |
char *s, *p; |
14 |
|
|
|
if (path[0] == '/') |
|
|
start = xstrdup(path); |
|
|
else { |
|
|
s = xrealloc_getcwd_or_warn(NULL); |
|
|
start = concat_path_file(s, path); |
|
|
free(s); |
|
|
} |
|
15 |
p = s = start; |
p = s = start; |
|
|
|
16 |
do { |
do { |
17 |
if (*p == '/') { |
if (*p == '/') { |
18 |
if (*s == '/') { /* skip duplicate (or initial) slash */ |
if (*s == '/') { /* skip duplicate (or initial) slash */ |
38 |
if ((p == start) || (*p != '/')) { /* not a trailing slash */ |
if ((p == start) || (*p != '/')) { /* not a trailing slash */ |
39 |
++p; /* so keep last character */ |
++p; /* so keep last character */ |
40 |
} |
} |
41 |
*p = 0; |
*p = '\0'; |
42 |
|
return p; |
43 |
|
} |
44 |
|
|
45 |
|
char* FAST_FUNC bb_simplify_path(const char *path) |
46 |
|
{ |
47 |
|
char *s, *p; |
48 |
|
|
49 |
|
if (path[0] == '/') |
50 |
|
s = xstrdup(path); |
51 |
|
else { |
52 |
|
p = xrealloc_getcwd_or_warn(NULL); |
53 |
|
s = concat_path_file(p, path); |
54 |
|
free(p); |
55 |
|
} |
56 |
|
|
57 |
return start; |
bb_simplify_abs_path_inplace(s); |
58 |
|
return s; |
59 |
} |
} |