aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-09-24 18:27:04 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-09-24 18:27:04 +0000
commit818322b9b19a452d66a07ca69256e2c092f5db5f (patch)
tree0b34390ac0cd61951bb9dc5b9fd3a226dae4f1ef /libbb
parenta7ce207bd82882d6436d256a73c42ca4c8500ff3 (diff)
downloadbusybox-w32-818322b9b19a452d66a07ca69256e2c092f5db5f.tar.gz
busybox-w32-818322b9b19a452d66a07ca69256e2c092f5db5f.tar.bz2
busybox-w32-818322b9b19a452d66a07ca69256e2c092f5db5f.zip
*: kill bb_get_last_path_component, replace with two functions
(one which strips trailing slash and one which does not) wget: straighten out as a result of above change text data bss dec hex filename 5056 1 0 5057 13c1 busybox.t4/networking/wget.o 5022 0 0 5022 139e busybox.t5/networking/wget.o
Diffstat (limited to 'libbb')
-rw-r--r--libbb/get_last_path_component.c42
-rw-r--r--libbb/run_shell.c2
2 files changed, 27 insertions, 17 deletions
diff --git a/libbb/get_last_path_component.c b/libbb/get_last_path_component.c
index b7bc0e626..0f602157d 100644
--- a/libbb/get_last_path_component.c
+++ b/libbb/get_last_path_component.c
@@ -8,25 +8,35 @@
8 */ 8 */
9 9
10#include "libbb.h" 10#include "libbb.h"
11 11/*
12char *bb_get_last_path_component(char *path) 12 * "/" -> "/"
13 * "abc" -> "abc"
14 * "abc/def" -> "def"
15 * "abc/def/" -> ""
16 */
17char *bb_get_last_path_component_nostrip(const char *path)
13{ 18{
14 char *first = path; 19 char *slash = strrchr(path, '/');
15 char *last; 20
21 if (!slash || (slash == path && !slash[1]))
22 return (char*)path;
16 23
17 last = path - 1; 24 return slash + 1;
25}
18 26
19 while (*path) { 27/*
20 if ((*path != '/') && (path > ++last)) { 28 * "/" -> "/"
21 last = first = path; 29 * "abc" -> "abc"
22 } 30 * "abc/def" -> "def"
23 ++path; 31 * "abc/def/" -> "def" !!
24 } 32 */
33char *bb_get_last_path_component_strip(char *path)
34{
35 char *slash = last_char_is(path, '/');
25 36
26 if (*first == '/') { 37 if (slash)
27 last = first; 38 while (*slash == '/' && slash != path)
28 } 39 *slash-- = '\0';
29 last[1] = '\0';
30 40
31 return first; 41 return bb_get_last_path_component_nostrip(path);
32} 42}
diff --git a/libbb/run_shell.c b/libbb/run_shell.c
index b2b4216f4..239887d85 100644
--- a/libbb/run_shell.c
+++ b/libbb/run_shell.c
@@ -67,7 +67,7 @@ void run_shell(const char *shell, int loginshell, const char *command, const cha
67 67
68 args = xmalloc(sizeof(char*) * (4 + additional_args_cnt)); 68 args = xmalloc(sizeof(char*) * (4 + additional_args_cnt));
69 69
70 args[0] = bb_get_last_path_component(xstrdup(shell)); 70 args[0] = bb_get_last_path_component_nostrip(xstrdup(shell));
71 71
72 if (loginshell) 72 if (loginshell)
73 args[0] = xasprintf("-%s", args[0]); 73 args[0] = xasprintf("-%s", args[0]);