diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2024-10-08 04:03:17 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2024-10-08 04:03:17 +0200 |
commit | 49d9e06fbab0b02a71deed57610edb0c8f4fb20c (patch) | |
tree | 6b5263bcdb0972eaf17f35dbb8c2ce65d13a790e /debianutils | |
parent | 8c4bccb83e5e2594f16310b7cbe07bf05fc9f13a (diff) | |
download | busybox-w32-49d9e06fbab0b02a71deed57610edb0c8f4fb20c.tar.gz busybox-w32-49d9e06fbab0b02a71deed57610edb0c8f4fb20c.tar.bz2 busybox-w32-49d9e06fbab0b02a71deed57610edb0c8f4fb20c.zip |
libbb: modify find_executable() to not temporarily write to PATH
This allows to simplify "which" applet code
function old new delta
find_executable 93 111 +18
which_main 191 177 -14
builtin_source 316 294 -22
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 18/-36) Total: -18 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'debianutils')
-rw-r--r-- | debianutils/which.c | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/debianutils/which.c b/debianutils/which.c index 1f547919f..a7d55a215 100644 --- a/debianutils/which.c +++ b/debianutils/which.c | |||
@@ -31,15 +31,12 @@ | |||
31 | int which_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 31 | int which_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
32 | int which_main(int argc UNUSED_PARAM, char **argv) | 32 | int which_main(int argc UNUSED_PARAM, char **argv) |
33 | { | 33 | { |
34 | char *env_path; | 34 | const char *env_path; |
35 | int status = 0; | 35 | int status = 0; |
36 | /* This sizeof(): bb_default_root_path is shorter than BB_PATH_ROOT_PATH */ | ||
37 | char buf[sizeof(BB_PATH_ROOT_PATH)]; | ||
38 | 36 | ||
39 | env_path = getenv("PATH"); | 37 | env_path = getenv("PATH"); |
40 | if (!env_path) | 38 | if (!env_path) |
41 | /* env_path must be writable, and must not alloc, so... */ | 39 | env_path = bb_default_root_path; |
42 | env_path = strcpy(buf, bb_default_root_path); | ||
43 | 40 | ||
44 | getopt32(argv, "^" "a" "\0" "-1"/*at least one arg*/); | 41 | getopt32(argv, "^" "a" "\0" "-1"/*at least one arg*/); |
45 | argv += optind; | 42 | argv += optind; |
@@ -54,7 +51,7 @@ int which_main(int argc UNUSED_PARAM, char **argv) | |||
54 | puts(*argv); | 51 | puts(*argv); |
55 | } | 52 | } |
56 | } else { | 53 | } else { |
57 | char *path; | 54 | const char *path; |
58 | char *p; | 55 | char *p; |
59 | 56 | ||
60 | path = env_path; | 57 | path = env_path; |