aboutsummaryrefslogtreecommitdiff
path: root/win32/mingw.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2024-06-14 08:12:08 +0100
committerRon Yorston <rmy@pobox.com>2024-06-14 08:12:08 +0100
commit9ee8e87d5affe019aeb2b8afe4b908672c4c2fa5 (patch)
tree177dc25062b8eadddc988c638920f417c77bb2b1 /win32/mingw.c
parenta518a4f6023582744fa271ec279375dd3d51a4d4 (diff)
downloadbusybox-w32-9ee8e87d5affe019aeb2b8afe4b908672c4c2fa5.tar.gz
busybox-w32-9ee8e87d5affe019aeb2b8afe4b908672c4c2fa5.tar.bz2
busybox-w32-9ee8e87d5affe019aeb2b8afe4b908672c4c2fa5.zip
win32: allow for trailing separator in PATH
In recent versions of Windows the PATH environment variable has a trailing semicolon. This is insignificant to Windows because it's ignored. busybox-w32 conforms to the POSIX interpretation of PATH which treats an empty path element as denoting the current directory. As result, on these versions of Windows executables may by default be run from the current directory, contrary to usual Unix practice. Attempt to detect and remove the trailing semicolon on applet start up. If the user insists, they can add a trailing semicolon to the shell variable PATH and it will be respected in the conventional manner. Adds 88-112 bytes. (GitHub issue #422)
Diffstat (limited to '')
-rw-r--r--win32/mingw.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/win32/mingw.c b/win32/mingw.c
index d3daf8315..f96b5b49a 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -2464,3 +2464,29 @@ char *xappendword(const char *str, const char *word)
2464 free((void *)str); 2464 free((void *)str);
2465 return newstr; 2465 return newstr;
2466} 2466}
2467
2468/*
2469 * Detect if the environment contains certain mixed-case names:
2470 *
2471 * Path is present in a standard Windows environment
2472 * ComSpec is present in WINE
2473 * ProgramData is present in Cygwin/MSYS2
2474 */
2475int
2476windows_env(void)
2477{
2478 const char *names = "PATH=\0""COMSPEC=\0""PROGRAMDATA=\0";
2479 const char *n;
2480
2481 for (char **envp = environ; envp && *envp; envp++) {
2482 for (n = names; *n; ) {
2483 if (is_prefixed_with_case(*envp, n) &&
2484 !is_prefixed_with(*envp, n)) {
2485 return TRUE;
2486 }
2487 while (*n++)
2488 ;
2489 }
2490 }
2491 return FALSE;
2492}