With a bit of care I was able to save about 100 bytes.

-Erik
This commit is contained in:
Eric Andersen 2001-06-15 20:10:39 +00:00
parent bd4b621e91
commit 32574a41b4

View File

@ -32,7 +32,13 @@
char *get_last_path_component(char *path) 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 */ /* strip trailing slashes */
while (s != path && *s == '/') { while (s != path && *s == '/') {
@ -40,7 +46,14 @@ char *get_last_path_component(char *path)
} }
/* find last component */ /* find last component */
s = strrchr(path, '/'); ptr = path;
while (*ptr != '\0') {
if (*ptr == '/')
prev = ptr;
ptr++;
}
s = prev;
if (s == NULL || s[1] == '\0') if (s == NULL || s[1] == '\0')
return path; return path;
else else