diff options
Diffstat (limited to 'libbb')
| -rw-r--r-- | libbb/simplify_path.c | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/libbb/simplify_path.c b/libbb/simplify_path.c index 367f1f04d..f80e3e8a5 100644 --- a/libbb/simplify_path.c +++ b/libbb/simplify_path.c | |||
| @@ -6,22 +6,13 @@ | |||
| 6 | * | 6 | * |
| 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
| 8 | */ | 8 | */ |
| 9 | |||
| 10 | #include "libbb.h" | 9 | #include "libbb.h" |
| 11 | 10 | ||
| 12 | char* FAST_FUNC bb_simplify_path(const char *path) | 11 | char* FAST_FUNC bb_simplify_abs_path_inplace(char *start) |
| 13 | { | 12 | { |
| 14 | char *s, *start, *p; | 13 | char *s, *p; |
| 15 | 14 | ||
| 16 | if (path[0] == '/') | ||
| 17 | start = xstrdup(path); | ||
| 18 | else { | ||
| 19 | s = xrealloc_getcwd_or_warn(NULL); | ||
| 20 | start = concat_path_file(s, path); | ||
| 21 | free(s); | ||
| 22 | } | ||
| 23 | p = s = start; | 15 | p = s = start; |
| 24 | |||
| 25 | do { | 16 | do { |
| 26 | if (*p == '/') { | 17 | if (*p == '/') { |
| 27 | if (*s == '/') { /* skip duplicate (or initial) slash */ | 18 | if (*s == '/') { /* skip duplicate (or initial) slash */ |
| @@ -47,7 +38,22 @@ char* FAST_FUNC bb_simplify_path(const char *path) | |||
| 47 | if ((p == start) || (*p != '/')) { /* not a trailing slash */ | 38 | if ((p == start) || (*p != '/')) { /* not a trailing slash */ |
| 48 | ++p; /* so keep last character */ | 39 | ++p; /* so keep last character */ |
| 49 | } | 40 | } |
| 50 | *p = 0; | 41 | *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 | } | ||
| 51 | 56 | ||
| 52 | return start; | 57 | bb_simplify_abs_path_inplace(s); |
| 58 | return s; | ||
| 53 | } | 59 | } |
