Note that this is obviously different from what windows cmd does, but Wine has a different situation. Running native binaries without 'start' is pretty useful, IMHO.
We check for a magic signature to avoid regressions in case there is a file without the extension that's not a native executable.
Signed-off-by: Fabian Maurer dark.shadow4@web.de --- programs/cmd/wcmdmain.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-)
diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c index 637c0e94bd..26910ee4c8 100644 --- a/programs/cmd/wcmdmain.c +++ b/programs/cmd/wcmdmain.c @@ -1009,6 +1009,29 @@ static void init_msvcrt_io_block(STARTUPINFOW* st) } }
+static BOOL is_native_executable(WCHAR *path) +{ + HANDLE file; + char buffer[4]; + static const char magic_elf[] = {0x7f, 'E', 'L', 'F'}; + DWORD bytes_read; + + file = CreateFileW(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); + ReadFile(file, buffer, ARRAY_SIZE(buffer), &bytes_read, NULL); + CloseHandle(file); + + if (bytes_read < ARRAY_SIZE(buffer)) + return FALSE; + + if (memcmp(buffer, magic_elf, 4) == 0) + return TRUE; + + if (memcmp(buffer, "#!/", 3) == 0) + return TRUE; + + return FALSE; +} + /****************************************************************************** * WCMD_run_program * @@ -1141,11 +1164,11 @@ void WCMD_run_program (WCHAR *command, BOOL called) strcatW(thisDir, stemofsearch); pos = &thisDir[strlenW(thisDir)]; /* Pos = end of name */
- /* 1. If extension supplied, see if that file exists */ - if (extensionsupplied) { - if (GetFileAttributesW(thisDir) != INVALID_FILE_ATTRIBUTES) { - found = TRUE; - } + /* 1. If extension supplied, see if that file exists - also check if we got a path to a native executable */ + if (GetFileAttributesW(thisDir) != INVALID_FILE_ATTRIBUTES) { + if (extensionsupplied || is_native_executable(thisDir)) { + found = TRUE; + } }
/* 2. Any .* matches? */ -- 2.21.0