#ifndef __HSBASE_H__
#define __HSBASE_H__
+#ifdef __NHC__
+# include "Nhc98BaseConfig.h"
+#else
#include "HsBaseConfig.h"
+#endif
/* ultra-evil... */
#undef PACKAGE_BUGREPORT
#if HAVE_VFORK_H
#include <vfork.h>
#endif
-#include "lockFile.h"
#include "dirUtils.h"
#include "WCsubst.h"
#endif
/* in inputReady.c */
-int inputReady(int fd, int msecs, int isSock);
+extern int fdReady(int fd, int write, int msecs, int isSock);
/* in Signals.c */
extern HsInt nocldstop;
INLINE int __hscore_s_isfifo(mode_t m) { return S_ISFIFO(m); }
INLINE int __hscore_s_isblk(mode_t m) { return S_ISBLK(m); }
INLINE int __hscore_s_ischr(mode_t m) { return S_ISCHR(m); }
-#ifdef S_ISSOCK
+#if !defined(mingw32_HOST_OS) && !defined(__MINGW32__)
INLINE int __hscore_s_issock(mode_t m) { return S_ISSOCK(m); }
#endif
#endif
__hscore_memcpy_src_off( char *dst, char *src, int src_off, size_t sz )
{ return memcpy(dst, src+src_off, sz); }
-INLINE HsBool
-__hscore_supportsTextMode()
-{
-#if defined(_MSC_VER) || defined(__MINGW32__) || defined(_WIN32)
- return HS_BOOL_FALSE;
-#else
- return HS_BOOL_TRUE;
-#endif
-}
-
INLINE HsInt
__hscore_bufsiz()
{
#elif defined(HAVE__CHSIZE)
return _chsize(fd,where);
#else
+// ToDo: we should use _chsize_s() on Windows which allows a 64-bit
+// offset, but it doesn't seem to be available from mingw at this time
+// --SDM (01/2008)
#error at least ftruncate or _chsize functions are required to build
#endif
}
#endif
}
+#if defined(__MINGW32__)
+// We want the versions of stat/fstat/lseek that use 64-bit offsets,
+// and you have to ask for those explicitly. Unfortunately there
+// doesn't seem to be a 64-bit version of truncate/ftruncate, so while
+// hFileSize and hSeek will work with large files, hSetFileSize will not.
+#define stat(file,buf) _stati64(file,buf)
+#define fstat(fd,buf) _fstati64(fd,buf)
+typedef struct _stati64 struct_stat;
+typedef off64_t stsize_t;
+#else
+typedef struct stat struct_stat;
+typedef off_t stsize_t;
+#endif
+
INLINE HsInt
__hscore_sizeof_stat( void )
{
- return sizeof(struct stat);
+ return sizeof(struct_stat);
}
-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; }
+INLINE time_t __hscore_st_mtime ( struct_stat* st ) { return st->st_mtime; }
+INLINE stsize_t __hscore_st_size ( struct_stat* st ) { return st->st_size; }
#if !defined(_MSC_VER)
-INLINE mode_t __hscore_st_mode ( struct stat* st ) { return st->st_mode; }
+INLINE mode_t __hscore_st_mode ( struct_stat* st ) { return st->st_mode; }
+INLINE dev_t __hscore_st_dev ( struct_stat* st ) { return st->st_dev; }
+INLINE ino_t __hscore_st_ino ( struct_stat* st ) { return st->st_ino; }
#endif
#if HAVE_TERMIOS_H
#endif
}
+#ifndef __MINGW32__
+INLINE size_t __hscore_sizeof_siginfo_t (void)
+{
+ return sizeof(siginfo_t);
+}
+#endif
+
INLINE int
__hscore_f_getfl( void )
{
#endif
}
+INLINE int
+__hscore_f_setfd( void )
+{
+#ifdef F_SETFD
+ return F_SETFD;
+#else
+ return 0;
+#endif
+}
+
+INLINE long
+__hscore_fd_cloexec( void )
+{
+#ifdef FD_CLOEXEC
+ return FD_CLOEXEC;
+#else
+ return 0;
+#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_open(char *file, int how, mode_t mode) {
#ifdef __MINGW32__
if ((how & O_WRONLY) || (how & O_RDWR) || (how & O_APPEND))
- return _sopen(file,how,_SH_DENYRW,mode);
+ return _sopen(file,how | _O_NOINHERIT,_SH_DENYRW,mode);
+ // _O_NOINHERIT: see #2650
else
- return _sopen(file,how,_SH_DENYWR,mode);
+ return _sopen(file,how | _O_NOINHERIT,_SH_DENYWR,mode);
+ // _O_NOINHERIT: see #2650
#else
return open(file,how,mode);
#endif
// macros which redirect to the 64-bit-off_t versions when large file
// support is enabled.
//
+#if defined(__MINGW32__)
+INLINE off64_t __hscore_lseek(int fd, off64_t off, int whence) {
+ return (_lseeki64(fd,off,whence));
+}
+#else
INLINE off_t __hscore_lseek(int fd, off_t off, int whence) {
return (lseek(fd,off,whence));
}
+#endif
-INLINE int __hscore_stat(char *file, struct stat *buf) {
+INLINE int __hscore_stat(char *file, struct_stat *buf) {
return (stat(file,buf));
}
-INLINE int __hscore_fstat(int fd, struct stat *buf) {
+INLINE int __hscore_fstat(int fd, struct_stat *buf) {
return (fstat(fd,buf));
}
#if !defined(__MINGW32__)
INLINE int hsFD_SETSIZE(void) { return FD_SETSIZE; }
-INLINE void hsFD_CLR(int fd, fd_set *fds) { FD_CLR(fd, fds); }
INLINE int hsFD_ISSET(int fd, fd_set *fds) { return FD_ISSET(fd, fds); }
INLINE void hsFD_SET(int fd, fd_set *fds) { FD_SET(fd, fds); }
INLINE HsInt sizeof_fd_set(void) { return sizeof(fd_set); }
INLINE uintptr_t __hscore_to_uintptr (void *p) { return (uintptr_t)p; }
INLINE intptr_t __hscore_to_intptr (void *p) { return (intptr_t)p; }
+void errorBelch2(const char*s, char *t);
+void debugBelch2(const char*s, char *t);
+
+#if !defined(mingw32_HOST_OS) && !defined(__MINGW32__)
+
+INLINE int fcntl_read(int fd, int cmd) {
+ return fcntl(fd, cmd);
+}
+INLINE int fcntl_write(int fd, int cmd, long arg) {
+ return fcntl(fd, cmd, arg);
+}
+INLINE int fcntl_lock(int fd, int cmd, struct flock *lock) {
+ return fcntl(fd, cmd, lock);
+}
+
+#endif
+
#endif /* __HSBASE_H__ */