Make System.Posix.Internals buildable by nhc98.
authorMalcolm.Wallace@cs.york.ac.uk <unknown>
Fri, 6 Feb 2009 11:11:52 +0000 (11:11 +0000)
committerMalcolm.Wallace@cs.york.ac.uk <unknown>
Fri, 6 Feb 2009 11:11:52 +0000 (11:11 +0000)
Makefile.nhc98
System/Posix/Internals.hs
include/HsBase.h
include/Nhc98BaseConfig.h [new file with mode: 0644]
include/dirUtils.h

index 6d7752b..b46a8a9 100644 (file)
@@ -40,7 +40,7 @@ SRCS  = \
        Text/ParserCombinators/ReadP.hs Data/Version.hs \
        Unsafe/Coerce.hs \
        WCsubst.c \
-       System/Posix/Types.hs \
+       System/Posix/Types.hs System/Posix/Internals.hs \
 
 #      Data/String.hs
 #      Text/ParserCombinators/ReadPrec.hs
index c4d9b19..09243ac 100644 (file)
@@ -23,7 +23,9 @@
 -- #hide
 module System.Posix.Internals where
 
-#include "HsBaseConfig.h"
+#ifndef __NHC__
+# include "HsBaseConfig.h"
+#endif
 
 #if ! (defined(mingw32_HOST_OS) || defined(__MINGW32__))
 import Control.Monad
@@ -48,8 +50,10 @@ import GHC.IOBase
 #elif __HUGS__
 import Hugs.Prelude (IOException(..), IOErrorType(..))
 import Hugs.IO (IOMode(..))
-#else
+#elif __NHC__
 import System.IO
+import Control.Exception
+import DIOError
 #endif
 
 #ifdef __HUGS__
@@ -90,8 +94,8 @@ fdFileSize fd =
     if not (s_isreg c_mode)
         then return (-1)
         else do
-    c_size <- st_size p_stat
-    return (fromIntegral c_size)
+      c_size <- st_size p_stat
+      return (fromIntegral c_size)
 
 data FDType  = Directory | Stream | RegularFile | RawDevice
                deriving (Eq)
@@ -132,12 +136,16 @@ statGetType p_stat = do
         | otherwise             -> ioError ioe_unknownfiletype
     
 ioe_unknownfiletype :: IOException
+#ifndef __NHC__
 ioe_unknownfiletype = IOError Nothing UnsupportedOperation "fdType"
                         "unknown file type"
-#if __GLASGOW_HASKELL__
+#  if __GLASGOW_HASKELL__
                         Nothing
-#endif
+#  endif
                         Nothing
+#else
+ioe_unknownfiletype = UserError "fdType" "unknown file type"
+#endif
 
 #if __GLASGOW_HASKELL__ && (defined(mingw32_HOST_OS) || defined(__MINGW32__))
 closeFd :: Bool -> CInt -> IO CInt
@@ -274,7 +282,11 @@ setCooked fd cooked = do
 
 ioe_unk_error :: String -> String -> IOException
 ioe_unk_error loc msg 
+#ifndef __NHC__
  = ioeSetErrorString (mkIOError OtherError loc Nothing Nothing) msg
+#else
+ = UserError loc msg
+#endif
 
 -- Note: echoing goes hand in hand with enabling 'line input' / raw-ness
 -- for Win32 consoles, hence setEcho ends up being the inverse of setCooked.
index fd10e11..dfc545f 100644 (file)
@@ -9,7 +9,11 @@
 #ifndef __HSBASE_H__
 #define __HSBASE_H__
 
+#ifdef __NHC__
+# include "Nhc98BaseConfig.h"
+#else
 #include "HsBaseConfig.h"
+#endif
 
 /* ultra-evil... */
 #undef PACKAGE_BUGREPORT
diff --git a/include/Nhc98BaseConfig.h b/include/Nhc98BaseConfig.h
new file mode 100644 (file)
index 0000000..5b6e23e
--- /dev/null
@@ -0,0 +1,44 @@
+/* -----------------------------------------------------------------------------
+ * (c) Malcolm Wallace 2009
+ * ---------------------------------------------------------------------------*/
+
+/* Until we work out how to use a configure script to determine the available
+   system headers (without going down the horrid autoconf route), let's just
+   take a reasonable hard-coded guess for now.  Feel free to change these
+   for your platform.
+ */
+#define HAVE_SYS_TYPES_H       1
+#define HAVE_UNISTD_H          1
+#define HAVE_SYS_STAT_H                1
+#define HAVE_FCNTL_H           1
+#define HAVE_TERMIOS_H         1
+#define HAVE_SIGNAL_H          1
+#define HAVE_ERRNO_H           1
+#define HAVE_STRING_H          1
+#define HAVE_UTIME_H           1
+#define HAVE_SYS_UTSNAME_H     1
+#define HAVE_GETTIMEOFDAY      1
+#define HAVE_SYS_TIME_H                1
+#define HAVE_GETCLOCK          0
+#define HAVE_SYS_TIMERS_H      0
+#define HAVE_TIME_H            1
+#define HAVE_SYS_TIMEB_H       1
+#define HAVE_WINDOWS_H         0
+#define HAVE_SYS_TIMES_H       1
+#define HAVE_WINSOCK_H         0
+#define HAVE_LIMITS_H          1
+#define HAVE_WCTYPE_H          1
+#define HAVE_INTTYPES_H                1
+// #define HAVE_STDINT_H               1
+#define HAVE_SYS_RESOURCE_H    1
+#define HAVE_GETRUSAGE         1
+#define HAVE_SYS_SYSCALL_H     1
+#define HAVE_SYS_WAIT_H                1
+#define HAVE_VFORK_H           0
+#define HAVE_SYS_SELECT_H      1
+#define HAVE_FTRUNCATE         1
+
+#undef SUPPORT_LONG_LONGS
+#define CONST_O_BINARY         0
+#define READDIR_ERRNO_EOF      0
+
index d5d75bb..87a3041 100644 (file)
@@ -5,6 +5,8 @@
  */
 #ifndef __DIRUTILS_H__
 #define __DIRUTILS_H__
+#include <sys/types.h>
+#include <dirent.h>
 
 extern int __hscore_readdir(DIR *dirPtr, struct dirent **pDirEnt);