[project @ 2004-08-16 11:08:47 by simonmar]
[haskell-directory.git] / cbits / system.c
index 289499b..34a6f23 100644 (file)
@@ -1,50 +1,43 @@
 /* 
- * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
+ * (c) The University of Glasgow 2002
  *
- * $Id: system.c,v 1.1 2001/06/28 14:15:04 simonmar Exp $
+ * $Id: system.c,v 1.8 2003/07/02 13:27:35 stolz Exp $
  *
  * system Runtime Support
  */
 
 /* The itimer stuff in this module is non-posix */
-#define NON_POSIX_SOURCE
+// #include "PosixSource.h"
 
-#include "HsCore.h"
+#include "HsBase.h"
 
 #if defined(mingw32_TARGET_OS)
 #include <windows.h>
+#include <stdlib.h>
+#endif
+
+#ifdef HAVE_VFORK_H
+#include <vfork.h>
+#endif
+
+#ifdef HAVE_VFORK
+#define fork vfork
 #endif
 
 HsInt
 systemCmd(HsAddr cmd)
 {
-#if defined(mingw32_TARGET_OS)
-  STARTUPINFO sInfo;
-  PROCESS_INFORMATION pInfo;
-  DWORD retCode;
-
-  sInfo.cb              = sizeof(STARTUPINFO);
-  sInfo.lpReserved      = NULL;
-  sInfo.lpReserved2     = NULL;
-  sInfo.cbReserved2     = 0;
-  sInfo.lpDesktop       = NULL;
-  sInfo.lpTitle         = NULL;
-  sInfo.dwFlags         = 0;
-
-  if (!CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &sInfo, &pInfo))
-    return -1;
-  WaitForSingleObject(pInfo.hProcess, INFINITE);
-  if (GetExitCodeProcess(pInfo.hProcess, &retCode) == 0) return -1;
-  CloseHandle(pInfo.hProcess);
-  CloseHandle(pInfo.hThread);
-  return retCode;
+  /* -------------------- WINDOWS VERSION --------------------- */
+#if defined(mingw32_TARGET_OS) || defined(cygwin32_TARGET_OS)
+    return system(cmd);
 #else
+  /* -------------------- UNIX VERSION --------------------- */
     int pid;
     int wstat;
 
     switch(pid = fork()) {
     case -1:
-       if (errno != EINTR) {
+       {
            return -1;
        }
     case 0: