From 03867ef4d29fc6a43168ca0029966ff54bdaf08a Mon Sep 17 00:00:00 2001 From: andersen Date: Fri, 15 Jun 2001 20:10:39 +0000 Subject: 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 --- libbb/get_last_path_component.c | 17 +++++++++++++++-- 1 file 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 @@ 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 -- cgit v1.2.3-55-g6feb