8 |
*/ |
*/ |
9 |
|
|
10 |
#include "libbb.h" |
#include "libbb.h" |
11 |
|
/* |
12 |
char *bb_get_last_path_component(char *path) |
* "/" -> "/" |
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 *first = path; |
char *slash = strrchr(path, '/'); |
|
char *last; |
|
20 |
|
|
21 |
last = path - 1; |
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) |
34 |
|
{ |
35 |
|
char *slash = last_char_is(path, '/'); |
36 |
|
|
37 |
while (*path) { |
if (slash) |
38 |
if ((*path != '/') && (path > ++last)) { |
while (*slash == '/' && slash != path) |
39 |
last = first = path; |
*slash-- = '\0'; |
|
} |
|
|
++path; |
|
|
} |
|
|
|
|
|
if (*first == '/') { |
|
|
last = first; |
|
|
} |
|
|
last[1] = 0; |
|
40 |
|
|
41 |
return first; |
return bb_get_last_path_component_nostrip(path); |
42 |
} |
} |