From 49d9e06fbab0b02a71deed57610edb0c8f4fb20c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 8 Oct 2024 04:03:17 +0200 Subject: 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 --- debianutils/which.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'debianutils') 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 @@ int which_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int which_main(int argc UNUSED_PARAM, char **argv) { - char *env_path; + const char *env_path; int status = 0; - /* This sizeof(): bb_default_root_path is shorter than BB_PATH_ROOT_PATH */ - char buf[sizeof(BB_PATH_ROOT_PATH)]; env_path = getenv("PATH"); if (!env_path) - /* env_path must be writable, and must not alloc, so... */ - env_path = strcpy(buf, bb_default_root_path); + env_path = bb_default_root_path; getopt32(argv, "^" "a" "\0" "-1"/*at least one arg*/); argv += optind; @@ -54,7 +51,7 @@ int which_main(int argc UNUSED_PARAM, char **argv) puts(*argv); } } else { - char *path; + const char *path; char *p; path = env_path; -- cgit v1.2.3-55-g6feb