summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen2001-06-15 20:10:39 +0000
committerEric Andersen2001-06-15 20:10:39 +0000
commit32574a41b4fe490db8a0f2142ae0108d7186e1c3 (patch)
treeb96987223318891bdfd32a6fbb983f0219f7bce5
parentbd4b621e910ea096fa8b7db19012eded43eb0006 (diff)
downloadbusybox-32574a41b4fe490db8a0f2142ae0108d7186e1c3.zip
busybox-32574a41b4fe490db8a0f2142ae0108d7186e1c3.tar.gz
With a bit of care I was able to save about 100 bytes.
-Erik
-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 a322288..f1ddfbd 100644
--- a/libbb/get_last_path_component.c
+++ b/libbb/get_last_path_component.c
@@ -32,7 +32,13 @@
char *get_last_path_component(char *path)
{
- char *s=path+strlen(path)-1;
+ char *s;
+ register char *ptr = path;
+ register char *prev = 0;
+
+ while (*ptr)
+ ptr++;
+ s = ptr - 1;
/* strip trailing slashes */
while (s != path && *s == '/') {
@@ -40,7 +46,14 @@ char *get_last_path_component(char *path)
}
/* find last component */
- s = strrchr(path, '/');
+ ptr = path;
+ while (*ptr != '\0') {
+ if (*ptr == '/')
+ prev = ptr;
+ ptr++;
+ }
+ s = prev;
+
if (s == NULL || s[1] == '\0')
return path;
else