From 5c1a3b00e235da31b2c73bae18aa5622d820b68a Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 17 Aug 2023 15:09:14 +0100 Subject: ash: detect native Windows environment on Wine The shell detected a native Windows environment by checking for a mixed-case 'Path' environment variable. This has always worked on Windows but recent versions of Wine have a 'PATH' environment variable. Check also for 'ComSpec'. Costs 24-48 bytes. --- shell/ash.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/shell/ash.c b/shell/ash.c index 5c4a3073a..41bf45734 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -15801,6 +15801,23 @@ static void setvar_if_unset(const char *key, const char *value) } #endif +#if ENABLE_PLATFORM_MINGW32 +static int mixed_case_special_name(const char *envp) +{ + const char *names = "PATH=\0""COMSPEC=\0"; + const char *n; + + for (n = names; *n; ) { + if (is_prefixed_with_case(envp, n) && !is_prefixed_with(envp, n)) { + return TRUE; + } + while (*n++) + ; + } + return FALSE; +} +#endif + /* Don't inline: conserve stack of caller from having our locals too */ static NOINLINE void init(void) @@ -15834,8 +15851,7 @@ init(void) * because it appears first. */ for (envp = environ; envp && *envp; envp++) { - if (is_prefixed_with_case(*envp, "PATH=") && - !is_prefixed_with(*envp, "PATH=")) { + if (mixed_case_special_name(*envp)) { break; } } -- cgit v1.2.3-55-g6feb