Last change
on this file since 2846 was 2725, checked in by Bruno Cornec, 14 years ago |
- Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
|
File size:
1.1 KB
|
Rev | Line | |
---|
[821] | 1 | /* vi: set sw=4 ts=4: */
|
---|
| 2 | /*
|
---|
| 3 | * bb_simplify_path implementation for busybox
|
---|
| 4 | *
|
---|
| 5 | * Copyright (C) 2001 Manuel Novoa III <mjn3@codepoet.org>
|
---|
| 6 | *
|
---|
[2725] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
---|
[821] | 8 | */
|
---|
| 9 | #include "libbb.h"
|
---|
| 10 |
|
---|
[2725] | 11 | char* FAST_FUNC bb_simplify_abs_path_inplace(char *start)
|
---|
[821] | 12 | {
|
---|
[2725] | 13 | char *s, *p;
|
---|
[821] | 14 |
|
---|
| 15 | p = s = start;
|
---|
| 16 | do {
|
---|
| 17 | if (*p == '/') {
|
---|
[2725] | 18 | if (*s == '/') { /* skip duplicate (or initial) slash */
|
---|
[821] | 19 | continue;
|
---|
[1765] | 20 | }
|
---|
| 21 | if (*s == '.') {
|
---|
[2725] | 22 | if (s[1] == '/' || !s[1]) { /* remove extra '.' */
|
---|
[821] | 23 | continue;
|
---|
[1765] | 24 | }
|
---|
| 25 | if ((s[1] == '.') && (s[2] == '/' || !s[2])) {
|
---|
[821] | 26 | ++s;
|
---|
| 27 | if (p > start) {
|
---|
[2725] | 28 | while (*--p != '/') /* omit previous dir */
|
---|
[1765] | 29 | continue;
|
---|
[821] | 30 | }
|
---|
| 31 | continue;
|
---|
| 32 | }
|
---|
| 33 | }
|
---|
| 34 | }
|
---|
| 35 | *++p = *s;
|
---|
| 36 | } while (*++s);
|
---|
| 37 |
|
---|
[2725] | 38 | if ((p == start) || (*p != '/')) { /* not a trailing slash */
|
---|
| 39 | ++p; /* so keep last character */
|
---|
[821] | 40 | }
|
---|
[2725] | 41 | *p = '\0';
|
---|
| 42 | return p;
|
---|
| 43 | }
|
---|
[821] | 44 |
|
---|
[2725] | 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 | bb_simplify_abs_path_inplace(s);
|
---|
| 58 | return s;
|
---|
[821] | 59 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.