-#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 */
+#ifdef __MINGW32__
+INLINE int __hscore_open(wchar_t *file, int how, mode_t mode) {
+ if ((how & O_WRONLY) || (how & O_RDWR) || (how & O_APPEND))
+ return _wsopen(file,how | _O_NOINHERIT,_SH_DENYRW,mode);
+ // _O_NOINHERIT: see #2650
+ else
+ return _wsopen(file,how | _O_NOINHERIT,_SH_DENYWR,mode);
+ // _O_NOINHERIT: see #2650
+}
+#else
+INLINE int __hscore_open(char *file, int how, mode_t mode) {
+ 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
+
+// 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
+
+INLINE int __hscore_select(int nfds, fd_set *readfds, fd_set *writefds,
+ fd_set *exceptfds, struct timeval *timeout) {
+ return (select(nfds,readfds,writefds,exceptfds,timeout));
+}
+
+// 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__) */
+
+#if darwin_HOST_OS
+// You should not access _environ directly on Darwin in a bundle/shared library.
+// See #2458 and http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man7/environ.7.html
+#include <crt_externs.h>
+INLINE char **__hscore_environ() { return *(_NSGetEnviron()); }
+#else
+/* 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; }
+#endif
+
+/* 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);
+
+#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