Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/libbb/simplify_path.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/libbb/simplify_path.c
r1765 r2725 5 5 * Copyright (C) 2001 Manuel Novoa III <mjn3@codepoet.org> 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 source tree. 8 8 */ 9 10 9 #include "libbb.h" 11 10 12 char *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 15 p = s = start; 24 25 16 do { 26 17 if (*p == '/') { 27 if (*s == '/') { 18 if (*s == '/') { /* skip duplicate (or initial) slash */ 28 19 continue; 29 20 } 30 21 if (*s == '.') { 31 if (s[1] == '/' || !s[1]) { 22 if (s[1] == '/' || !s[1]) { /* remove extra '.' */ 32 23 continue; 33 24 } … … 35 26 ++s; 36 27 if (p > start) { 37 while (*--p != '/') 28 while (*--p != '/') /* omit previous dir */ 38 29 continue; 39 30 } … … 45 36 } while (*++s); 46 37 47 if ((p == start) || (*p != '/')) { 48 ++p; 38 if ((p == start) || (*p != '/')) { /* not a trailing slash */ 39 ++p; /* so keep last character */ 49 40 } 50 *p = 0; 41 *p = '\0'; 42 return p; 43 } 51 44 52 return start; 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; 53 59 }
Note:
See TracChangeset
for help on using the changeset viewer.