aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2001-06-15 20:10:39 +0000
committerandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2001-06-15 20:10:39 +0000
commit03867ef4d29fc6a43168ca0029966ff54bdaf08a (patch)
treeb96987223318891bdfd32a6fbb983f0219f7bce5
parentb6dd391224aed8c58ae0f805147d297d75032d42 (diff)
downloadbusybox-w32-03867ef4d29fc6a43168ca0029966ff54bdaf08a.tar.gz
busybox-w32-03867ef4d29fc6a43168ca0029966ff54bdaf08a.tar.bz2
busybox-w32-03867ef4d29fc6a43168ca0029966ff54bdaf08a.zip
With a bit of care I was able to save about 100 bytes.
-Erik git-svn-id: svn://busybox.net/trunk/busybox@2843 69ca8d6d-28ef-0310-b511-8ec308f3f277
-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