#include "HsBase.h"
-#if defined(mingw32_HOST_OS)
+#if defined(_MSC_VER) || defined(__MINGW32__) || defined(_WIN32)
#include <windows.h>
#include <stdlib.h>
#endif
#include <signal.h>
#endif
-#if !defined(mingw32_HOST_OS) && !defined(__MINGW32__)
+#if !(defined(_MSC_VER) || defined(__MINGW32__) || defined(_WIN32))
/* ----------------------------------------------------------------------------
UNIX versions
------------------------------------------------------------------------- */
}
}
- dup2 (fdStdInput[0], STDIN_FILENO);
- dup2 (fdStdOutput[1], STDOUT_FILENO);
- dup2 (fdStdError[1], STDERR_FILENO);
+ if (fdStdInput[0] != STDIN_FILENO) {
+ dup2 (fdStdInput[0], STDIN_FILENO);
+ close(fdStdInput[0]);
+ }
+
+ if (fdStdOutput[1] != STDOUT_FILENO) {
+ dup2 (fdStdOutput[1], STDOUT_FILENO);
+ close(fdStdOutput[1]);
+ }
+
+ if (fdStdError[1] != STDERR_FILENO) {
+ dup2 (fdStdError[1], STDERR_FILENO);
+ close(fdStdError[1]);
+ }
- close(fdStdInput[0]);
close(fdStdInput[1]);
close(fdStdOutput[0]);
- close(fdStdOutput[1]);
close(fdStdError[0]);
- close(fdStdError[1]);
/* the child */
if (environment) {
else
if (WIFSIGNALED(wstat))
{
- errno = EINTR;
+ return wstat;
}
else
{
maperrno();
return -1;
}
-
- CloseHandle((HANDLE) handle);
return 0;
}
maperrno();
return -1;
}
-
- CloseHandle((HANDLE) handle);
return 1;
}
maperrno();
return -1;
}
-
- CloseHandle((HANDLE) handle);
return retCode;
}