[project @ 2004-10-14 14:58:50 by simonmar]
[ghc-base.git] / cbits / rawSystem.c
index 846ceee..7af7747 100644 (file)
@@ -1,5 +1,10 @@
 /* 
- * (c) The University of Glasgow 1994-2003
+ * (c) The University of Glasgow 1994-2004
+ *
+ * WARNING: this file is here for backwards compatibility only.  It is
+ * not included as part of the base package, but is #included into the
+ * compiler and the runghc utility when building either of these with 
+ * an old version of GHC.
  *
  * shell-less system Runtime Support (see System.Cmd.rawSystem).
  */
@@ -7,7 +12,16 @@
 /* The itimer stuff in this module is non-posix */
 /* #include "PosixSource.h" */
 
+/* This ifdef is required because this source might be compiled by an
+ * external compiler.  See ghc/utils/runghc/rawSystem.c for example.
+ */
+#ifdef __GLASGOW_HASKELL__
+#if __GLASGOW_HASKELL__ < 603
 #include "config.h"
+#else
+#include "ghcconfig.h"
+#endif
+#endif
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -67,10 +81,14 @@ rawSystem(HsAddr cmd)
        Since we are going to wait for the process to terminate anyway,
        there is no problem with such sharing. */
 
+      errno = EINVAL; // ToDo: wrong, caller should use GetLastError()
       return -1;
   }
   WaitForSingleObject(pInfo.hProcess, INFINITE);
-  if (GetExitCodeProcess(pInfo.hProcess, &retCode) == 0) return -1;
+  if (GetExitCodeProcess(pInfo.hProcess, &retCode) == 0) {
+      errno = EINVAL; // ToDo: wrong, caller should use GetLastError()
+      return -1;
+  }
 
   CloseHandle(pInfo.hProcess);
   CloseHandle(pInfo.hThread);