[project @ 2004-02-12 14:54:19 by simonpj]
[ghc-base.git] / include / HsBase.h
index bc88bad..6c68618 100644 (file)
@@ -1,5 +1,4 @@
 /* -----------------------------------------------------------------------------
- * $Id: HsBase.h,v 1.34 2003/10/30 18:51:26 sof Exp $
  *
  * (c) The University of Glasgow 2001-2002
  *
 #include <stdlib.h>
 #include <math.h>
 
-#ifdef HAVE_SYS_TYPES_H
+#if HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
-#ifdef HAVE_UNISTD_H
+#if HAVE_UNISTD_H
 #include <unistd.h>
 #endif
-#ifdef HAVE_SYS_STAT_H
+#if HAVE_SYS_STAT_H
 #include <sys/stat.h>
 #endif
-#ifdef HAVE_FCNTL_H
+#if HAVE_FCNTL_H
 # include <fcntl.h>
 #endif
-#ifdef HAVE_TERMIOS_H
+#if HAVE_TERMIOS_H
 #include <termios.h>
 #endif
-#ifdef HAVE_SIGNAL_H
+#if HAVE_SIGNAL_H
 #include <signal.h>
+/* Ultra-ugly: OpenBSD uses broken macros for sigemptyset and sigfillset (missing casts) */
+#if __OpenBSD__
+#undef sigemptyset
+#undef sigfillset
+#endif
 #endif
-#ifdef HAVE_ERRNO_H
+#if HAVE_ERRNO_H
 #include <errno.h>
 #endif
-#ifdef HAVE_STRING_H
+#if HAVE_STRING_H
 #include <string.h>
 #endif
-#ifdef HAVE_DIRENT_H
+#if HAVE_DIRENT_H
 #include <dirent.h>
 #endif
-#ifdef HAVE_UTIME_H
+#if HAVE_UTIME_H
 #include <utime.h>
 #endif
-#ifdef HAVE_SYS_UTSNAME_H
+#if HAVE_SYS_UTSNAME_H
 #include <sys/utsname.h>
 #endif
-#if defined(HAVE_GETTIMEOFDAY)
-#  ifdef HAVE_SYS_TIME_H
+#if HAVE_GETTIMEOFDAY
+#  if HAVE_SYS_TIME_H
 #   include <sys/time.h>
 #  endif
-#elif defined(HAVE_GETCLOCK)
-# ifdef HAVE_SYS_TIMERS_H
+#elif HAVE_GETCLOCK
+# if HAVE_SYS_TIMERS_H
 #  define POSIX_4D9 1
 #  include <sys/timers.h>
 # endif
 #endif
-#if defined(HAVE_TIME_H)
-# include <time.h>
+#if HAVE_TIME_H
+#include <time.h>
 #endif
-#ifdef HAVE_SYS_TIMEB_H
+#if HAVE_SYS_TIMEB_H
 #include <sys/timeb.h>
 #endif
-#ifdef HAVE_WINDOWS_H
+#if HAVE_WINDOWS_H
 #include <windows.h>
 #endif
-#ifdef HAVE_SYS_TIMES_H
+#if HAVE_SYS_TIMES_H
 #include <sys/times.h>
 #endif
-#if defined(HAVE_WINSOCK_H) && defined(mingw32_TARGET_OS)
+#if HAVE_WINSOCK_H && defined(mingw32_TARGET_OS)
 #include <winsock.h>
 #endif
-#ifdef HAVE_LIMITS_H
+#if HAVE_LIMITS_H
 #include <limits.h>
 #endif
-#ifdef HAVE_WCTYPE_H
+#if HAVE_WCTYPE_H
 #include <wctype.h>
 #endif
 
 #if !defined(mingw32_TARGET_OS) && !defined(irix_TARGET_OS)
-# if defined(HAVE_SYS_RESOURCE_H)
+# if HAVE_SYS_RESOURCE_H
 #  include <sys/resource.h>
 # endif
 #endif
 #endif
 
 /* For System */
-#ifdef HAVE_SYS_WAIT_H
+#if HAVE_SYS_WAIT_H
 #include <sys/wait.h>
 #endif
-#ifdef HAVE_VFORK_H
+#if HAVE_VFORK_H
 #include <vfork.h>
 #endif
 #include "lockFile.h"
 #include "timeUtils.h"
 #endif
 
-/* in ghc_errno.c */
-int *ghcErrno(void);
-
 /* in system.c */
 HsInt systemCmd(HsAddr cmd);
 
@@ -197,11 +198,16 @@ StgWord64 stg_integerToWord64 (StgInt sa, StgByteArray /* Really: mp_limb_t* */
 #ifndef INLINE
 # if defined(_MSC_VER)
 #  define INLINE extern __inline
+# elif defined(__HUGS__)
+#  define INLINE INLINE_ONLY
 # else
 #  define INLINE extern inline
 # endif
 #endif
 
+INLINE int __hscore_get_errno(void) { return errno; }
+INLINE void __hscore_set_errno(int e) { errno = e; }
+
 #if !defined(_MSC_VER)
 INLINE int __hscore_s_isreg(m)  { return S_ISREG(m);  }
 INLINE int __hscore_s_isdir(m)  { return S_ISDIR(m);  }
@@ -388,26 +394,14 @@ __hscore_setmode( HsInt fd, HsBool toBin )
 }
 
 INLINE HsInt
-__hscore_PrelHandle_write( HsInt fd, HsBool isSock, HsAddr ptr, 
-                          HsInt off, int sz )
+__hscore_PrelHandle_write( HsInt fd, HsAddr ptr, HsInt off, int sz )
 {
-#if defined(mingw32_TARGET_OS) || defined(_MSC_VER)
-  if (isSock) {
-    return send(fd,(char *)ptr + off, sz, 0);
-  }
-#endif
   return write(fd,(char *)ptr + off, sz);
 }
 
 INLINE HsInt
-__hscore_PrelHandle_read( HsInt fd, HsBool isSock, HsAddr ptr, 
-                         HsInt off, int sz )
+__hscore_PrelHandle_read( HsInt fd, HsAddr ptr, HsInt off, int sz )
 {
-#if defined(mingw32_TARGET_OS) || defined(_MSC_VER)
-  if (isSock) {
-    return recv(fd,(char *)ptr + off, sz, 0);
-  }
-#endif
   return read(fd,(char *)ptr + off, sz);
 
 }
@@ -433,7 +427,7 @@ __hscore_mkdir( HsAddr pathName, HsInt mode )
 INLINE HsInt
 __hscore_lstat( HsAddr fname, HsAddr st )
 {
-#ifdef HAVE_LSTAT
+#if HAVE_LSTAT
   return lstat((const char*)fname, (struct stat*)st);
 #else
   return stat((const char*)fname, (struct stat*)st);