diff options
author | Eric Andersen <andersen@codepoet.org> | 2001-06-15 20:10:39 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2001-06-15 20:10:39 +0000 |
commit | 32574a41b4fe490db8a0f2142ae0108d7186e1c3 (patch) | |
tree | b96987223318891bdfd32a6fbb983f0219f7bce5 | |
parent | bd4b621e910ea096fa8b7db19012eded43eb0006 (diff) | |
download | busybox-w32-32574a41b4fe490db8a0f2142ae0108d7186e1c3.tar.gz busybox-w32-32574a41b4fe490db8a0f2142ae0108d7186e1c3.tar.bz2 busybox-w32-32574a41b4fe490db8a0f2142ae0108d7186e1c3.zip |
With a bit of care I was able to save about 100 bytes.
-Erik
-rw-r--r-- | libbb/get_last_path_component.c | 17 |
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 | ||
33 | char *get_last_path_component(char *path) | 33 | char *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 |