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
Fabian Maurer dark.shadow4@web.de writes:
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.
It shouldn't be necessary for cmd.exe to know about executable formats. Files without extension can already be handled with the PATHEXT mechanism.
On Donnerstag, 7. März 2019 19:13:51 CET you wrote:
It shouldn't be necessary for cmd.exe to know about executable
formats.
Files without extension can already be handled with the PATHEXT mechanism.
What do you mean? How would we use this to allow cmd to run files without extension?
Regards, Fabian Maurer
Fabian Maurer dark.shadow4@web.de writes:
On Donnerstag, 7. März 2019 19:13:51 CET you wrote:
It shouldn't be necessary for cmd.exe to know about executable formats.
Files without extension can already be handled with the PATHEXT
mechanism.
What do you mean? How would we use this to allow cmd to run files without extension?
By adding a dot to the PATHEXT value, cf. https://wiki.winehq.org/FAQ#How_do_I_launch_native_applications_from_a_Windo...
What do you mean? How would we use this to allow cmd to run files
without
extension?
By adding a dot to the PATHEXT value, cf. https://wiki.winehq.org/
FAQ#How_do_I_launch_native_applications_from_a_Windo
ws_application.3F
Welp... Sorry, somehow completely missed that. Hope that's not another dumb question, but why isn't that default?
Regards, Fabian Maurer
Fabian Maurer dark.shadow4@web.de writes:
What do you mean? How would we use this to allow cmd to run files without
extension?
By adding a dot to the PATHEXT value, cf.
https://wiki.winehq.org/FAQ#How_do_I_launch_native_applications_from_a_Windo
ws_application.3F
Welp... Sorry, somehow completely missed that.
Hope that's not another dumb question, but why isn't that default?
Because it could potentially break some Windows apps, but mostly because there hasn't been a clear need for it. Running Unix apps from cmd isn't all that useful...