diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-05 13:33:59 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-05 13:33:59 +0000 |
commit | f592aa36f33430b866e9d7c975c6b9c356100d4b (patch) | |
tree | f7a8c565817ce331c6e18a2a399074c6c615cd79 /libbb | |
parent | f0d6068086b701522b92a7dd941739cf4fbb71e8 (diff) | |
download | busybox-w32-f592aa36f33430b866e9d7c975c6b9c356100d4b.tar.gz busybox-w32-f592aa36f33430b866e9d7c975c6b9c356100d4b.tar.bz2 busybox-w32-f592aa36f33430b866e9d7c975c6b9c356100d4b.zip |
which: -a support (needed for bfin uclibc build script)
real support (with CONFIG_DESKTOP=y): 120+ bytes:
text data bss dec hex filename
807958 624 7036 815618 c7202 busybox_old
808085 624 7036 815745 c7281 busybox_unstripped
"fake" support (with CONFIG_DESKTOP unset): ~45 bytes:
text data bss dec hex filename
797790 611 6996 805397 c4a15 busybox_old
797834 611 6996 805441 c4a41 busybox_unstripped
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/execable.c | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/libbb/execable.c b/libbb/execable.c index 2649a6cfe..5c2b4505c 100644 --- a/libbb/execable.c +++ b/libbb/execable.c | |||
@@ -19,15 +19,20 @@ int execable_file(const char *name) | |||
19 | return (!access(name, X_OK) && !stat(name, &s) && S_ISREG(s.st_mode)); | 19 | return (!access(name, X_OK) && !stat(name, &s) && S_ISREG(s.st_mode)); |
20 | } | 20 | } |
21 | 21 | ||
22 | /* search $PATH for an executable file; | 22 | /* search (*PATHp) for an executable file; |
23 | * return allocated string containing full path if found; | 23 | * return allocated string containing full path if found; |
24 | * return NULL otherwise; | 24 | * PATHp points to the component after the one where it was found |
25 | * (or NULL), | ||
26 | * you may call find_execable again with this PATHp to continue | ||
27 | * (if it's not NULL). | ||
28 | * return NULL otherwise; (PATHp is undefined) | ||
29 | * in all cases (*PATHp) contents will be trashed (s/:/NUL/). | ||
25 | */ | 30 | */ |
26 | char *find_execable(const char *filename) | 31 | char *find_execable(const char *filename, char **PATHp) |
27 | { | 32 | { |
28 | char *path, *p, *n; | 33 | char *p, *n; |
29 | 34 | ||
30 | p = path = xstrdup(getenv("PATH")); | 35 | p = *PATHp; |
31 | while (p) { | 36 | while (p) { |
32 | n = strchr(p, ':'); | 37 | n = strchr(p, ':'); |
33 | if (n) | 38 | if (n) |
@@ -35,15 +40,14 @@ char *find_execable(const char *filename) | |||
35 | if (*p != '\0') { /* it's not a PATH="foo::bar" situation */ | 40 | if (*p != '\0') { /* it's not a PATH="foo::bar" situation */ |
36 | p = concat_path_file(p, filename); | 41 | p = concat_path_file(p, filename); |
37 | if (execable_file(p)) { | 42 | if (execable_file(p)) { |
38 | free(path); | 43 | *PATHp = n; |
39 | return p; | 44 | return p; |
40 | } | 45 | } |
41 | free(p); | 46 | free(p); |
42 | } | 47 | } |
43 | p = n; | 48 | p = n; |
44 | } | 49 | } /* on loop exit p == NULL */ |
45 | free(path); | 50 | return p; |
46 | return NULL; | ||
47 | } | 51 | } |
48 | 52 | ||
49 | /* search $PATH for an executable file; | 53 | /* search $PATH for an executable file; |
@@ -52,7 +56,10 @@ char *find_execable(const char *filename) | |||
52 | */ | 56 | */ |
53 | int exists_execable(const char *filename) | 57 | int exists_execable(const char *filename) |
54 | { | 58 | { |
55 | char *ret = find_execable(filename); | 59 | char *path = xstrdup(getenv("PATH")); |
60 | char *tmp = path; | ||
61 | char *ret = find_execable(filename, &tmp); | ||
62 | free(path); | ||
56 | if (ret) { | 63 | if (ret) { |
57 | free(ret); | 64 | free(ret); |
58 | return 1; | 65 | return 1; |