Windows fixes
authorRobert Pengelly <robertapengelly@hotmail.com>
Wed, 17 Sep 2025 12:03:48 +0000 (13:03 +0100)
committerRobert Pengelly <robertapengelly@hotmail.com>
Wed, 17 Sep 2025 12:03:48 +0000 (13:03 +0100)
variable.c
xmake.c

index cb44327d67ba0169dc06977243bded70508ffde0..9460e984fdd339b7ff002cf022e1167760b934b9 100644 (file)
@@ -7,6 +7,8 @@
 
 #if     defined (unix) || defined (__unix) || defined (__unix__) || defined (__APPLE__)
 # define        __USE_POSIX
+#elif   defined (_WIN32)
+# define        strcasecmp              _stricmp
 #endif
 
 #include    <stdio.h>
diff --git a/xmake.c b/xmake.c
index f7ae429f1705a5b18382944736cd18aa752db6a2..e99b81e32e8d9c094a37544c9cb3e5b27d507e9d 100644 (file)
--- 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);