-#ifndef mingw32_TARGET_OS
-INLINE int __hsposix_SIGABRT() { return SIGABRT; }
-INLINE int __hsposix_SIGALRM() { return SIGALRM; }
-INLINE int __hsposix_SIGBUS() { return SIGBUS; }
-INLINE int __hsposix_SIGCHLD() { return SIGCHLD; }
-INLINE int __hsposix_SIGCONT() { return SIGCONT; }
-INLINE int __hsposix_SIGFPE() { return SIGFPE; }
-INLINE int __hsposix_SIGHUP() { return SIGHUP; }
-INLINE int __hsposix_SIGILL() { return SIGILL; }
-INLINE int __hsposix_SIGINT() { return SIGINT; }
-INLINE int __hsposix_SIGKILL() { return SIGKILL; }
-INLINE int __hsposix_SIGPIPE() { return SIGPIPE; }
-INLINE int __hsposix_SIGQUIT() { return SIGQUIT; }
-INLINE int __hsposix_SIGSEGV() { return SIGSEGV; }
-INLINE int __hsposix_SIGSTOP() { return SIGSTOP; }
-INLINE int __hsposix_SIGTERM() { return SIGTERM; }
-INLINE int __hsposix_SIGTSTP() { return SIGTSTP; }
-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; }
-INLINE int __hsposix_SIGURG() { return SIGURG; }
-INLINE int __hsposix_SIGVTALRM() { return SIGVTALRM; }
-INLINE int __hsposix_SIGXCPU() { return SIGXCPU; }
-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 */
+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);
+ else
+ return _sopen(file,how,_SH_DENYWR,mode);
+#else
+ return open(file,how,mode);
+#endif
+}
+
+// These are wrapped because on some OSs (eg. Linux) they are
+// 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) {
+ return (stat(file,buf));
+}
+
+INLINE int __hscore_fstat(int fd, struct_stat *buf) {
+ return (fstat(fd,buf));
+}
+
+// select-related stuff
+
+#if !defined(__MINGW32__)
+INLINE int hsFD_SETSIZE(void) { return FD_SETSIZE; }
+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); }
+extern void hsFD_ZERO(fd_set *fds);
+#endif
+
+// gettimeofday()-related
+
+#if !defined(__MINGW32__)
+
+INLINE HsInt sizeofTimeVal(void) { return sizeof(struct timeval); }
+
+INLINE HsWord64 getUSecOfDay(void)
+{
+ struct timeval tv;
+ gettimeofday(&tv, (struct timezone *) NULL);
+ // Don't forget to cast *before* doing the arithmetic, otherwise
+ // the arithmetic happens at the type of tv_sec, which is probably
+ // only 'int'.
+ return ((HsWord64)tv.tv_sec * 1000000 + (HsWord64)tv.tv_usec);
+}
+
+INLINE void setTimevalTicks(struct timeval *p, HsWord64 usecs)
+{
+ p->tv_sec = usecs / 1000000;
+ p->tv_usec = usecs % 1000000;
+}
+#endif /* !defined(__MINGW32__) */
+
+/* ToDo: write a feature test that doesn't assume 'environ' to
+ * be in scope at link-time. */
+extern char** environ;
+INLINE char **__hscore_environ() { return environ; }
+
+/* lossless conversions between pointers and integral types */
+INLINE void * __hscore_from_uintptr(uintptr_t n) { return (void *)n; }
+INLINE void * __hscore_from_intptr (intptr_t n) { return (void *)n; }
+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);