aboutsummaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2022-05-01 10:20:16 +0100
committerRon Yorston <rmy@pobox.com>2022-05-01 11:03:10 +0100
commit6d87be4d760ceda18d354c6d4c523a9adf50c04b (patch)
treeca286c74b3d0689591ce7bee6a9b98af93e15e21 /win32
parentae61e126ee8e8200e87f285d9c410eb377505578 (diff)
downloadbusybox-w32-6d87be4d760ceda18d354c6d4c523a9adf50c04b.tar.gz
busybox-w32-6d87be4d760ceda18d354c6d4c523a9adf50c04b.tar.bz2
busybox-w32-6d87be4d760ceda18d354c6d4c523a9adf50c04b.zip
which,ash: changes to which/command/type
Change how 'which' detects if it was run from a standalone shell: the shell passes the undocumented '-s' option. This is stricter and more reliable than the previous method of checking the name of the binary. Add a function to determine the binary associated with a given applet name. This makes it possible for 'which' and 'command -v' to list the correct binary even for applets other than 'busybox'. For example, when the binary is called 'sh.exe' 'which sh' will report its path. In standalone shell mode 'command -V' and 'type' now report "xxx is a builtin applet" rather than "xxx is xxx", which is true but not very illuminating. (GitHub issue #248)
Diffstat (limited to 'win32')
-rw-r--r--win32/mingw.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/win32/mingw.c b/win32/mingw.c
index 063a0c546..0fa2a1b8f 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -2130,3 +2130,24 @@ int is_relative_path(const char *path)
2130{ 2130{
2131 return !is_dir_sep(path[0]) && !has_dos_drive_prefix(path); 2131 return !is_dir_sep(path[0]) && !has_dos_drive_prefix(path);
2132} 2132}
2133
2134#if ENABLE_FEATURE_SH_STANDALONE
2135/*
2136 * In standalone shell mode it's possible there's no binary file
2137 * corresponding to an applet name. There's one case where it's
2138 * easy to determine the corresponding binary: if the applet name
2139 * matches the file name from bb_busybox_exec_path (with appropriate
2140 * allowance for 'busybox*.exe').
2141 */
2142const char *applet_to_exe(const char *name)
2143{
2144 const char *exefile = bb_basename(bb_busybox_exec_path);
2145 const char *exesuff = is_prefixed_with_case(exefile, name);
2146
2147 if (exesuff && (strcmp(name, "busybox") == 0 ||
2148 strcasecmp(exesuff, ".exe") == 0)) {
2149 return bb_busybox_exec_path;
2150 }
2151 return name;
2152}
2153#endif