Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/libbb/get_last_path_component.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/get_last_path_component.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 9 10 10 #include "libbb.h" 11 /* 12 * "/" -> "/" 13 * "abc" -> "abc" 14 * "abc/def" -> "def" 15 * "abc/def/" -> "" 16 */ 17 char* FAST_FUNC bb_get_last_path_component_nostrip(const char *path) 18 { 19 char *slash = strrchr(path, '/'); 11 20 12 char *bb_get_last_path_component(char *path) 21 if (!slash || (slash == path && !slash[1])) 22 return (char*)path; 23 24 return slash + 1; 25 } 26 27 /* 28 * "/" -> "/" 29 * "abc" -> "abc" 30 * "abc/def" -> "def" 31 * "abc/def/" -> "def" !! 32 */ 33 char* FAST_FUNC bb_get_last_path_component_strip(char *path) 13 34 { 14 char *first = path; 15 char *last; 35 char *slash = last_char_is(path, '/'); 16 36 17 last = path - 1; 37 if (slash) 38 while (*slash == '/' && slash != path) 39 *slash-- = '\0'; 18 40 19 while (*path) { 20 if ((*path != '/') && (path > ++last)) { 21 last = first = path; 22 } 23 ++path; 24 } 25 26 if (*first == '/') { 27 last = first; 28 } 29 last[1] = '\0'; 30 31 return first; 41 return bb_get_last_path_component_nostrip(path); 32 42 }
Note:
See TracChangeset
for help on using the changeset viewer.