diff options
-rw-r--r-- | debianutils/which.c | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/debianutils/which.c b/debianutils/which.c index f5ea17198..8e047efc2 100644 --- a/debianutils/which.c +++ b/debianutils/which.c | |||
@@ -34,6 +34,11 @@ int which_main(int argc UNUSED_PARAM, char **argv) | |||
34 | int status = 0; | 34 | int status = 0; |
35 | /* This sizeof(): bb_default_root_path is shorter than BB_PATH_ROOT_PATH */ | 35 | /* This sizeof(): bb_default_root_path is shorter than BB_PATH_ROOT_PATH */ |
36 | char buf[sizeof(BB_PATH_ROOT_PATH)]; | 36 | char buf[sizeof(BB_PATH_ROOT_PATH)]; |
37 | #if ENABLE_PLATFORM_MINGW32 && ENABLE_FEATURE_SH_STANDALONE | ||
38 | /* If we were run as 'which.exe' skip standalone shell behaviour */ | ||
39 | int sh_standalone = | ||
40 | is_suffixed_with_case(bb_busybox_exec_path, "which.exe") == NULL; | ||
41 | #endif | ||
37 | 42 | ||
38 | env_path = getenv("PATH"); | 43 | env_path = getenv("PATH"); |
39 | if (!env_path) | 44 | if (!env_path) |
@@ -47,19 +52,21 @@ int which_main(int argc UNUSED_PARAM, char **argv) | |||
47 | int missing = 1; | 52 | int missing = 1; |
48 | 53 | ||
49 | #if ENABLE_PLATFORM_MINGW32 && ENABLE_FEATURE_SH_STANDALONE | 54 | #if ENABLE_PLATFORM_MINGW32 && ENABLE_FEATURE_SH_STANDALONE |
50 | if (strcmp(*argv, "busybox") == 0 && | 55 | if (sh_standalone) { |
51 | is_suffixed_with(bb_busybox_exec_path, "busybox.exe")) { | 56 | if (strcmp(*argv, "busybox") == 0 && |
52 | missing = 0; | 57 | is_prefixed_with_case(bb_basename(bb_busybox_exec_path), |
53 | puts(bb_busybox_exec_path); | 58 | "busybox")) { |
54 | if (!option_mask32) /* -a not set */ | 59 | missing = 0; |
55 | break; | 60 | puts(bb_busybox_exec_path); |
56 | } | 61 | if (!option_mask32) /* -a not set */ |
57 | else if (find_applet_by_name(*argv) >= 0 || | 62 | break; |
58 | is_prefixed_with(*argv, "busybox")) { | 63 | } |
59 | missing = 0; | 64 | else if (find_applet_by_name(*argv) >= 0) { |
60 | puts(*argv); | 65 | missing = 0; |
61 | if (!option_mask32) /* -a not set */ | 66 | puts(*argv); |
62 | break; | 67 | if (!option_mask32) /* -a not set */ |
68 | break; | ||
69 | } | ||
63 | } | 70 | } |
64 | #endif | 71 | #endif |
65 | 72 | ||
@@ -72,9 +79,6 @@ int which_main(int argc UNUSED_PARAM, char **argv) | |||
72 | } | 79 | } |
73 | #else | 80 | #else |
74 | if (has_path(*argv)) { | 81 | if (has_path(*argv)) { |
75 | # if ENABLE_FEATURE_SH_STANDALONE | ||
76 | const char *name = bb_basename(*argv); | ||
77 | # endif | ||
78 | char *path = alloc_system_drive(*argv); | 82 | char *path = alloc_system_drive(*argv); |
79 | 83 | ||
80 | if (add_win32_extension(path) || file_is_executable(path)) { | 84 | if (add_win32_extension(path) || file_is_executable(path)) { |
@@ -82,9 +86,13 @@ int which_main(int argc UNUSED_PARAM, char **argv) | |||
82 | puts(bs_to_slash(path)); | 86 | puts(bs_to_slash(path)); |
83 | } | 87 | } |
84 | # if ENABLE_FEATURE_SH_STANDALONE | 88 | # if ENABLE_FEATURE_SH_STANDALONE |
85 | else if (unix_path(*argv) && find_applet_by_name(name) >= 0) { | 89 | else if (sh_standalone) { |
86 | missing = 0; | 90 | const char *name = bb_basename(*argv); |
87 | puts(name); | 91 | |
92 | if (unix_path(*argv) && find_applet_by_name(name) >= 0) { | ||
93 | missing = 0; | ||
94 | puts(name); | ||
95 | } | ||
88 | } | 96 | } |
89 | # endif | 97 | # endif |
90 | #endif | 98 | #endif |