Do only one call to GetVersionEx in the common case.
[pspp] / lib / execute.c
index c9f25b52d2a10fa2b8c28cb9f4f85b1d01430840..253b5a670f3ab3cc6a23c0441b52535ecd439501 100644 (file)
@@ -35,7 +35,7 @@
 
 #define _(str) gettext (str)
 
-#if defined _MSC_VER || defined __MINGW32__
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
 
 /* Native Woe32 API.  */
 # include <process.h>
@@ -104,7 +104,7 @@ execute (const char *progname,
         bool slave_process, bool exit_on_error,
         int *termsigp)
 {
-#if defined _MSC_VER || defined __MINGW32__
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
 
   /* Native Woe32 API.  */
   int orig_stdin;
@@ -119,11 +119,11 @@ execute (const char *progname,
 
   /* Save standard file handles of parent process.  */
   if (null_stdin)
-    orig_stdin = dup_noinherit (STDIN_FILENO);
+    orig_stdin = dup_safer_noinherit (STDIN_FILENO);
   if (null_stdout)
-    orig_stdout = dup_noinherit (STDOUT_FILENO);
+    orig_stdout = dup_safer_noinherit (STDOUT_FILENO);
   if (null_stderr)
-    orig_stderr = dup_noinherit (STDERR_FILENO);
+    orig_stderr = dup_safer_noinherit (STDERR_FILENO);
   exitcode = -1;
 
   /* Create standard file handles of child process.  */
@@ -154,14 +154,16 @@ execute (const char *progname,
        copy of the environment block - ignoring the effects of putenv() and
        [un]setenv().  */
     {
-      exitcode = spawnvpe (P_WAIT, prog_path, prog_argv, environ);
+      exitcode = spawnvpe (P_WAIT, prog_path, (const char **) prog_argv,
+                          (const char **) environ);
       if (exitcode < 0 && errno == ENOEXEC)
        {
          /* prog is not an native executable.  Try to execute it as a
             shell script.  Note that prepare_spawn() has already prepended
             a hidden element "sh.exe" to prog_argv.  */
          --prog_argv;
-         exitcode = spawnvpe (P_WAIT, prog_argv[0], prog_argv, environ);
+         exitcode = spawnvpe (P_WAIT, prog_argv[0], (const char **) prog_argv,
+                              (const char **) environ);
        }
     }
   if (nulloutfd >= 0)
@@ -171,11 +173,11 @@ execute (const char *progname,
 
   /* Restore standard file handles of parent process.  */
   if (null_stderr)
-    dup2 (orig_stderr, STDERR_FILENO), close (orig_stderr);
+    undup_safer_noinherit (orig_stderr, STDERR_FILENO);
   if (null_stdout)
-    dup2 (orig_stdout, STDOUT_FILENO), close (orig_stdout);
+    undup_safer_noinherit (orig_stdout, STDOUT_FILENO);
   if (null_stdin)
-    dup2 (orig_stdin, STDIN_FILENO), close (orig_stdin);
+    undup_safer_noinherit (orig_stdin, STDIN_FILENO);
 
   if (termsigp != NULL)
     *termsigp = 0;