[project @ 2003-10-13 03:19:48 by sof]
[haskell-directory.git] / include / HsBase.h
index a917b96..0b24bc1 100644 (file)
@@ -1,14 +1,14 @@
 /* -----------------------------------------------------------------------------
- * $Id: HsBase.h,v 1.15 2002/10/03 12:43:50 panne Exp $
+ * $Id: HsBase.h,v 1.31 2003/10/13 03:19:48 sof Exp $
  *
  * (c) The University of Glasgow 2001-2002
  *
- * Definitions for package `core' which are visible in Haskell land.
+ * Definitions for package `base' which are visible in Haskell land.
  *
  * ---------------------------------------------------------------------------*/
 
-#ifndef HSCORE_H
-#define HSCORE_H
+#ifndef __HSBASE_H__
+#define __HSBASE_H__
 
 #include "config.h"
 #include "HsFFI.h"
@@ -78,6 +78,9 @@
 #ifdef HAVE_LIMITS_H
 #include <limits.h>
 #endif
+#ifdef HAVE_WCTYPE_H
+#include <wctype.h>
+#endif
 
 #if !defined(mingw32_TARGET_OS) && !defined(irix_TARGET_OS)
 # if defined(HAVE_SYS_RESOURCE_H)
@@ -114,11 +117,21 @@ int *ghcErrno(void);
 HsInt systemCmd(HsAddr cmd);
 
 /* in rawSystem.c */
-HsInt rawSystemCmd(HsAddr cmd);
+#if defined(mingw32_TARGET_OS)
+HsInt rawSystem(HsAddr cmd);
+#else
+HsInt rawSystem(HsAddr cmd, HsAddr args);
+#endif
 
 /* in inputReady.c */
 int inputReady(int fd, int msecs, int isSock);
 
+/* in writeError.c */
+void writeErrString__(HsAddr msg_hdr, HsAddr msg, HsInt len);
+
+/* in Signals.c */
+extern HsInt nocldstop;
+
 /* -----------------------------------------------------------------------------
    64-bit operations, defined in longlong.c
    -------------------------------------------------------------------------- */
@@ -182,9 +195,14 @@ StgWord64 stg_integerToWord64 (StgInt sa, StgByteArray /* Really: mp_limb_t* */
    -------------------------------------------------------------------------- */
 
 #ifndef INLINE
-#define INLINE extern inline
+# if defined(_MSC_VER)
+#  define INLINE extern __inline
+# else
+#  define INLINE extern inline
+# endif
 #endif
 
+#if !defined(_MSC_VER) && !defined(__MINGW__)
 INLINE int __hscore_s_isreg(m)  { return S_ISREG(m);  }
 INLINE int __hscore_s_isdir(m)  { return S_ISDIR(m);  }
 INLINE int __hscore_s_isfifo(m) { return S_ISFIFO(m); }
@@ -193,8 +211,9 @@ INLINE int __hscore_s_ischr(m)  { return S_ISCHR(m);  }
 #ifdef S_ISSOCK
 INLINE int __hscore_s_issock(m) { return S_ISSOCK(m); }
 #endif
+#endif
 
-#ifndef mingw32_TARGET_OS
+#if !defined(mingw32_TARGET_OS) && !defined(_MSC_VER) && !defined(__MINGW__)
 INLINE int
 __hscore_sigemptyset( sigset_t *set )
 { return sigemptyset(set); }
@@ -249,10 +268,10 @@ __hscore_seek_cur()
 INLINE HsInt
 __hscore_o_binary()
 {
-#ifdef HAVE_O_BINARY
+#if defined(_MSC_VER)
   return O_BINARY;
 #else
-  return 0;
+  return CONST_O_BINARY;
 #endif
 }
 
@@ -374,10 +393,10 @@ __hscore_PrelHandle_write( HsInt fd, HsBool isSock, HsAddr ptr,
 {
 #if defined(__MINGW32__)
   if (isSock) {
-    return send(fd,ptr + off, sz, 0);
+    return send(fd,(char *)ptr + off, sz, 0);
   }
 #endif
-  return write(fd,ptr + off, sz);
+  return write(fd,(char *)ptr + off, sz);
 }
 
 INLINE HsInt
@@ -386,10 +405,10 @@ __hscore_PrelHandle_read( HsInt fd, HsBool isSock, HsAddr ptr,
 {
 #if defined(__MINGW32__)
   if (isSock) {
-    return recv(fd,ptr + off, sz, 0);
+    return recv(fd,(char *)ptr + off, sz, 0);
   }
 #endif
-  return read(fd,ptr + off, sz);
+  return read(fd,(char *)ptr + off, sz);
 
 }
 
@@ -421,16 +440,37 @@ __hscore_lstat( HsAddr fname, HsAddr st )
 #endif
 }
 
-INLINE HsInt __hscore_path_max() { return PATH_MAX; }
+#ifdef PATH_MAX
+/* A size that will contain many path names, but not necessarily all
+ * (PATH_MAX is not defined on systems with unlimited path length,
+ * e.g. the Hurd).
+ */
+INLINE HsInt __hscore_long_path_size() { return PATH_MAX; }
+#else
+INLINE HsInt __hscore_long_path_size() { return 4096; }
+#endif
 
+#ifdef R_OK
 INLINE mode_t __hscore_R_OK() { return R_OK; }
+#endif
+#ifdef W_OK
 INLINE mode_t __hscore_W_OK() { return W_OK; }
+#endif
+#ifdef X_OK
 INLINE mode_t __hscore_X_OK() { return X_OK; }
+#endif
 
+#ifdef S_IRUSR
 INLINE mode_t __hscore_S_IRUSR() { return S_IRUSR; }
+#endif
+#ifdef S_IWUSR
 INLINE mode_t __hscore_S_IWUSR() { return S_IWUSR; }
+#endif
+#ifdef S_IXUSR
 INLINE mode_t __hscore_S_IXUSR() { return S_IXUSR; }
+#endif
 
+#if !defined(_MSC_VER) && !defined(__MINGW__)
 INLINE HsAddr
 __hscore_d_name( struct dirent* d )
 { 
@@ -440,6 +480,7 @@ __hscore_d_name( struct dirent* d )
   return (HsAddr)(d->d_name);
 #endif
 }
+#endif
 
 INLINE HsInt
 __hscore_end_of_dir( void )
@@ -467,7 +508,9 @@ __hscore_sizeof_stat( void )
 
 INLINE time_t __hscore_st_mtime ( struct stat* st ) { return st->st_mtime; }
 INLINE off_t  __hscore_st_size  ( struct stat* st ) { return st->st_size; }
+#if !defined(_MSC_VER) && !defined(__MINGW__)
 INLINE mode_t __hscore_st_mode  ( struct stat* st ) { return st->st_mode; }
+#endif
 
 #if HAVE_TERMIOS_H
 INLINE tcflag_t __hscore_lflag( struct termios* ts ) { return ts->c_lflag; }
@@ -478,7 +521,6 @@ __hscore_poke_lflag( struct termios* ts, tcflag_t t ) { ts->c_lflag = t; }
 INLINE unsigned char*
 __hscore_ptr_c_cc( struct termios* ts ) 
 { return (unsigned char*) &ts->c_cc; }
-#endif
 
 INLINE HsInt
 __hscore_sizeof_termios( void )
@@ -489,7 +531,9 @@ __hscore_sizeof_termios( void )
   return 0;
 #endif
 }
+#endif
 
+#if !defined(_MSC_VER) && !defined(__MINGW__)
 INLINE HsInt
 __hscore_sizeof_sigset_t( void )
 {
@@ -499,6 +543,7 @@ __hscore_sizeof_sigset_t( void )
   return 0;
 #endif
 }
+#endif
 
 INLINE int
 __hscore_echo( void )
@@ -597,9 +642,13 @@ __hscore_f_setfl( void )
 #endif
 }
 
+// defined in rts/RtsStartup.c.
+extern void* __hscore_get_saved_termios(int fd);
+extern void __hscore_set_saved_termios(int fd, void* ts);
+
 INLINE int __hscore_hs_fileno (FILE *f) { return fileno (f); }
 
-#ifndef mingw32_TARGET_OS
+#if !defined(mingw32_TARGET_OS) && !defined(_MSC_VER) && !defined(__MINGW32__)
 INLINE int __hsposix_SIGABRT()   { return SIGABRT; }
 INLINE int __hsposix_SIGALRM()   { return SIGALRM; }
 INLINE int __hsposix_SIGBUS()    { return SIGBUS; }
@@ -620,7 +669,9 @@ INLINE int __hsposix_SIGTTIN()   { return SIGTTIN; }
 INLINE int __hsposix_SIGTTOU()   { return SIGTTOU; }
 INLINE int __hsposix_SIGUSR1()   { return SIGUSR1; }
 INLINE int __hsposix_SIGUSR2()   { return SIGUSR2; }
+#if HAVE_SIGPOLL
 INLINE int __hsposix_SIGPOLL()   { return SIGPOLL; }
+#endif
 INLINE int __hsposix_SIGPROF()   { return SIGPROF; }
 INLINE int __hsposix_SIGSYS()    { return SIGSYS; }
 INLINE int __hsposix_SIGTRAP()   { return SIGTRAP; }
@@ -632,7 +683,7 @@ INLINE int __hsposix_SIGXFSZ()   { return SIGXFSZ; }
 INLINE int __hsposix_SIG_BLOCK()   { return SIG_BLOCK; }
 INLINE int __hsposix_SIG_UNBLOCK() { return SIG_SETMASK; }
 INLINE int __hsposix_SIG_SETMASK() { return SIG_UNBLOCK; }
-#endif // mingw32_TARGET_OS
+#endif /* mingw32_TARGET_OS */
 
-#endif
+#endif /* __HSBASE_H__ */