aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libbb/get_last_path_component.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/libbb/get_last_path_component.c b/libbb/get_last_path_component.c
index a322288a6..f1ddfbde0 100644
--- a/libbb/get_last_path_component.c
+++ b/libbb/get_last_path_component.c
@@ -32,7 +32,13 @@
32 32
33char *get_last_path_component(char *path) 33char *get_last_path_component(char *path)
34{ 34{
35 char *s=path+strlen(path)-1; 35 char *s;
36 register char *ptr = path;
37 register char *prev = 0;
38
39 while (*ptr)
40 ptr++;
41 s = ptr - 1;
36 42
37 /* strip trailing slashes */ 43 /* strip trailing slashes */
38 while (s != path && *s == '/') { 44 while (s != path && *s == '/') {
@@ -40,7 +46,14 @@ char *get_last_path_component(char *path)
40 } 46 }
41 47
42 /* find last component */ 48 /* find last component */
43 s = strrchr(path, '/'); 49 ptr = path;
50 while (*ptr != '\0') {
51 if (*ptr == '/')
52 prev = ptr;
53 ptr++;
54 }
55 s = prev;
56
44 if (s == NULL || s[1] == '\0') 57 if (s == NULL || s[1] == '\0')
45 return path; 58 return path;
46 else 59 else