From a2c0827ddfdd6cfcd7f232bc954589484477ec09 Mon Sep 17 00:00:00 2001 From: Robert Pengelly Date: Wed, 17 Sep 2025 13:03:48 +0100 Subject: [PATCH] Windows fixes --- variable.c | 2 ++ xmake.c | 46 +++++++++++++++++++++++++--------------------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/variable.c b/variable.c index cb44327..9460e98 100644 --- a/variable.c +++ b/variable.c @@ -7,6 +7,8 @@ #if defined (unix) || defined (__unix) || defined (__unix__) || defined (__APPLE__) # define __USE_POSIX +#elif defined (_WIN32) +# define strcasecmp _stricmp #endif #include diff --git a/xmake.c b/xmake.c index f7ae429..e99b81e 100644 --- a/xmake.c +++ b/xmake.c @@ -104,7 +104,7 @@ static char *internal_commands[] = { static int pipe_command (const char *filename, unsigned long line_no, char *input, int is_ignoring_errors, const char *name) { - DWORD dwExitCode; + DWORD dwExitCode = 0; PROCESS_INFORMATION pi; SECURITY_ATTRIBUTES sa; @@ -117,15 +117,9 @@ static int pipe_command (const char *filename, unsigned long line_no, char *inpu char *p; struct linebuf lbuf; - input = skip_whitespace (input); - - /*for (p = input; !isspace ((int) *p); p++) { - - if (*p == '/') { - *p = '\\'; - } + int internal = 0; - }*/ + input = skip_whitespace (input); if ((p = strchr (input, ' '))) { @@ -138,7 +132,8 @@ static int pipe_command (const char *filename, unsigned long line_no, char *inpu if (!(p = strchr (lpApplicationName, '\\'))) { - unsigned long count = sizeof (internal_commands) / sizeof (internal_commands[0]), i; + unsigned long count = sizeof (internal_commands) / sizeof (internal_commands[0]) - 1; + unsigned long i; for (i = 0; i < count; i++) { @@ -156,21 +151,29 @@ static int pipe_command (const char *filename, unsigned long line_no, char *inpu sprintf (lpCommandLine, "/C %s", input); lpApplicationName = xstrdup (getenv ("COMSPEC")); + internal = 1; + break; } } - }/* else { + } - if (lpApplicationName) { - free (lpApplicationName); + if (!internal) { + + if (!lpCommandLine) { + lpCommandLine = xstrdup (""); } - lpApplicationName = 0; + p = xmalloc (strlen (lpApplicationName) + strlen (lpCommandLine) + 8); + sprintf (p, "/C %s %s", lpApplicationName, lpCommandLine); + + free (lpCommandLine); + lpCommandLine = p; - }*/ + } memset (&sa, 0, sizeof (sa)); memset (&si, 0, sizeof (si)); @@ -191,7 +194,7 @@ static int pipe_command (const char *filename, unsigned long line_no, char *inpu exit (EXIT_FAILURE); } - + /* if (!SetHandleInformation (hStdInPipeRead, HANDLE_FLAG_INHERIT, 0)) { fprintf (stderr, "process_begin: CreateProcess(NULL, %s, ...) failed.\n", input); @@ -204,7 +207,7 @@ static int pipe_command (const char *filename, unsigned long line_no, char *inpu exit (EXIT_FAILURE); } - + */ if (!CreatePipe (&hStdOutPipeRead, &hStdOutPipeWrite, &sa, 0)) { fprintf (stderr, "process_begin: CreateProcess(NULL, %s, ...) failed.\n", input); @@ -239,7 +242,7 @@ static int pipe_command (const char *filename, unsigned long line_no, char *inpu si.dwFlags |= STARTF_USESTDHANDLES; - if (!CreateProcess (lpApplicationName, lpCommandLine, 0, 0, 1, 0, 0, 0, &si, &pi)) { + if (!CreateProcess (getenv ("COMSPEC"), lpCommandLine, 0, 0, 1, 0, 0, 0, &si, &pi)) { fprintf (stderr, "process_begin: CreateProcess(NULL, %s, ...) failed.\n", input); fprintf (stderr, "%s: %s:%lu: pipe: %s\n", program_name, filename, line_no, strerror (GetLastError ())); @@ -254,6 +257,7 @@ static int pipe_command (const char *filename, unsigned long line_no, char *inpu CloseHandle (hStdOutPipeWrite); CloseHandle (hStdInPipeRead); + CloseHandle (hStdInPipeWrite); /*WaitForSingleObject (pi.hProcess, INFINITE);*/ lbuf.start = xmalloc (lbuf.size = 256); @@ -286,10 +290,10 @@ static int pipe_command (const char *filename, unsigned long line_no, char *inpu } - CloseHandle (hStdOutPipeRead); - CloseHandle (hStdInPipeWrite); - GetExitCodeProcess (pi.hProcess, &dwExitCode); + WaitForSingleObject (pi.hProcess, INFINITE); + + CloseHandle (hStdOutPipeRead); CloseHandle (pi.hProcess); CloseHandle (pi.hThread); -- 2.34.1