[MLton-commit] r6684
Wesley Terpstra
wesley at mlton.org
Fri Aug 1 03:11:53 PDT 2008
Every time MinGW changes, it breaks the build of MLton.
This overly anal change to the mingw.h makes it work for both 20060117 and
20080720. Hopefully it will work for all the versions inbetween and now be
less sensitive to future changes. Win64 works with this change as well.
----------------------------------------------------------------------
U mlton/trunk/runtime/platform/mingw.c
U mlton/trunk/runtime/platform/mingw.h
----------------------------------------------------------------------
Modified: mlton/trunk/runtime/platform/mingw.c
===================================================================
--- mlton/trunk/runtime/platform/mingw.c 2008-07-31 20:57:39 UTC (rev 6683)
+++ mlton/trunk/runtime/platform/mingw.c 2008-08-01 10:11:49 UTC (rev 6684)
@@ -76,8 +76,8 @@
/* Based on notes by Wu Yongwei:
* http://mywebpage.netscape.com/yongweiwutime.htm
*/
-int mlton_gettimeofday (struct timeval *tv,
- __attribute__ ((unused)) struct timezone *tz) {
+int gettimeofday (struct timeval *tv,
+ __attribute__ ((unused)) struct timezone *tz) {
FILETIME ft;
LARGE_INTEGER li;
__int64 t;
@@ -85,7 +85,7 @@
unless (tzInit) {
tzInit = TRUE;
- _tzset();
+ tzset();
}
GetSystemTimeAsFileTime (&ft);
li.LowPart = ft.dwLowDateTime;
@@ -411,7 +411,7 @@
__attribute__ ((noreturn))
char *getlogin (void) {
- die ("*getlogin not implemented");
+ die ("getlogin not implemented");
}
__attribute__ ((noreturn))
@@ -547,18 +547,28 @@
os = "unknown";
break;
}
- sprintf (buf->sysname, "MINGW32_%s-%d.%d",
+#ifdef _WIN64
+#define mingw_name "MINGW64"
+#else
+#define mingw_name "MINGW32"
+#endif
+ sprintf (buf->sysname, "%s_%s-%d.%d", mingw_name,
os, (int)osv.dwMajorVersion, (int)osv.dwMinorVersion);
}
int uname (struct utsname *buf) {
setMachine (buf);
+ setSysname (buf);
unless (0 == gethostname (buf->nodename, sizeof (buf->nodename))) {
strcpy (buf->nodename, "unknown");
}
- sprintf (buf->release, "%d", 0); //__MINGW32_MINOR_VERSION);
- setSysname (buf);
- sprintf (buf->version, "%d", 0); //__MINGW32_MAJOR_VERSION);
+#ifdef _WIN64
+ sprintf (buf->release, "%d", MINGW64_VERSION_MINOR);
+ sprintf (buf->version, "%d", MINGW64_VERSION_MAJOR);
+#else
+ sprintf (buf->release, "%d", __MINGW32_MINOR_VERSION);
+ sprintf (buf->version, "%d", __MINGW32_MAJOR_VERSION);
+#endif
return 0;
}
Modified: mlton/trunk/runtime/platform/mingw.h
===================================================================
--- mlton/trunk/runtime/platform/mingw.h 2008-07-31 20:57:39 UTC (rev 6683)
+++ mlton/trunk/runtime/platform/mingw.h 2008-08-01 10:11:49 UTC (rev 6684)
@@ -3,9 +3,8 @@
#include <stdint.h>
#include <unistd.h>
+#include <windows.h>
-#include <windows.h> // lots of stuff depends on this
-
#include <dirent.h>
#include <fcntl.h>
#include <sys/stat.h>
@@ -14,6 +13,7 @@
#include <sys/timeb.h>
#include <sys/types.h>
#include <utime.h>
+#include <time.h>
#include <io.h>
#include <lm.h>
@@ -22,6 +22,7 @@
#include <winsock2.h>
#include <ws2tcpip.h>
#include <psapi.h>
+
#undef max
#define HAS_FEROUND TRUE
@@ -40,49 +41,161 @@
#define MLton_Platform_OS_host "mingw"
-typedef unsigned short gid_t;
-typedef unsigned short uid_t;
-typedef long suseconds_t; // type of timeval.tv_usec in sys/time.h
-typedef short nlink_t; // type of st_nlink in sys/stat.h
+/** MinGW is a moving target. MLton seems to break every release.
+ * Often new releases add new emulation for POSIX functions.
+ * We need to provide wrappers for some POSIX functions, but
+ * these wrappers end up conflicting with MinGW if they're added.
+ * Therefore, all wrapper stuff we add will be #define'd to use
+ * a MLton_prefix, thus avoiding collision with MinGW versions,
+ * current, old, or future. Macros themselves can conflict, so
+ * we need to #undef any old value, and in the case of constants,
+ * wrap the define in an ifndef. It's ugly and verbose, but safe.
+ */
-// bullshit typedefs:
-typedef unsigned int nfds_t; // we have a fake poll() with this many fds
+#define MLTON_WRAPPER
-int getpagesize (void);
-int mkstemp (char *template);
+typedef unsigned short MLton_gid_t;
+typedef unsigned short MLton_uid_t;
+typedef long MLton_suseconds_t; // type of timeval.tv_usec in sys/time.h
+typedef short MLton_nlink_t; // type of st_nlink in sys/stat.h
+typedef unsigned int MLton_nfds_t; // we have a fake poll() with this many fds
+#undef gid_t
+#undef uid_t
+#undef suseconds_t
+#undef nlink_t
+#undef nfds_t
+
+#define gid_t MLton_gid_t
+#define uid_t MLton_uid_t
+#define suseconds_t MLton_suseconds_t
+#define nlink_t MLton_nlink_t
+#define nfds_t MLton_nfds_t
+
+MLTON_WRAPPER int MLton_getpagesize (void);
+MLTON_WRAPPER int MLton_mkstemp (char *template);
+
+#undef getpagesize
+#undef mkstemp
+
+#define getpagesize MLton_getpagesize
+#define mkstemp MLton_mkstemp
+
+#ifndef POLLIN
#define POLLIN 1
+#endif
+
+#ifndef POLLPRI
#define POLLPRI 2
+#endif
+
+#ifndef POLLOUT
#define POLLOUT 4
+#endif
+#ifndef _PC_CHOWN_RESTRICTED
#define _PC_CHOWN_RESTRICTED 6
+#endif
+
+#ifndef _PC_LINK_MAX
#define _PC_LINK_MAX 0
+#endif
+
+#ifndef _PC_MAX_CANON
#define _PC_MAX_CANON 1
+#endif
+
+#ifndef _PC_MAX_INPUT
#define _PC_MAX_INPUT 2
+#endif
+
+#ifndef _PC_NAME_MAX
#define _PC_NAME_MAX 3
+#endif
+
+#ifndef _PC_NO_TRUNC
#define _PC_NO_TRUNC 7
+#endif
+
+#ifndef _PC_PATH_MAX
#define _PC_PATH_MAX 4
+#endif
+
+#ifndef _PC_PIPE_BUF
#define _PC_PIPE_BUF 5
+#endif
+
+#ifndef _PC_VDISABLE
#define _PC_VDISABLE 8
+#endif
+#ifndef F_DUPFD
#define F_DUPFD 0
+#endif
+
+#ifndef F_GETFD
#define F_GETFD 1
+#endif
+
+#ifndef F_SETFD
#define F_SETFD 2
+#endif
+
+#ifndef F_GETFL
#define F_GETFL 3
+#endif
+
+#ifndef F_SETFL
#define F_SETFL 4
+#endif
+
+#ifndef F_GETOWN
#define F_GETOWN 5
+#endif
+
+#ifndef F_SETOWN
#define F_SETOWN 6
+#endif
+
+#ifndef F_GETLK
#define F_GETLK 7
+#endif
+
+#ifndef F_SETLK
#define F_SETLK 8
+#endif
+
+#ifndef F_RDLCK
#define F_RDLCK 1
+#endif
+
+#ifndef F_WRLCK
#define F_WRLCK 2
+#endif
+
+#ifndef F_UNLCK
#define F_UNLCK 3
+#endif
+
+#ifndef F_SETLKW
#define F_SETLKW 9
+#endif
+
+#ifndef FD_CLOEXEC
#define FD_CLOEXEC 1
+#endif
+#ifndef SHUT_RD
#define SHUT_RD SD_RECEIVE
+#endif
+
+#ifndef SHUT_WR
#define SHUT_WR SD_SEND
+#endif
+
+#ifndef SHUT_RDWR
#define SHUT_RDWR SD_BOTH
+#endif
/* ------------------------------------------------- */
/* Date */
@@ -91,118 +204,250 @@
/* MinGW provides gettimeofday in -lmingwex, which we don't link.
* In order to avoid a name conflict, we use a different name.
*/
-int mlton_gettimeofday (struct timeval *tv, struct timezone *tz);
-#define gettimeofday mlton_gettimeofday
+struct MLton_timezone {
+ int unused;
+};
+#undef timezone
+#define timezone MLton_timezone
+MLTON_WRAPPER int MLton_gettimeofday (struct timeval *tv, struct timezone *tz);
+#undef gettimeofday
+#define gettimeofday MLton_gettimeofday
+
/* ------------------------------------------------- */
/* MLton.Itimer */
/* ------------------------------------------------- */
+#ifndef ITIMER_REAL
#define ITIMER_REAL 0 /*generates sigalrm */
+#endif
+
+#ifndef ITIMER_VIRTUAL
#define ITIMER_VIRTUAL 1 /*generates sigvtalrm */
+#endif
+
+#ifndef ITIMER_VIRT
#define ITIMER_VIRT 1 /*generates sigvtalrm */
+#endif
+
+#ifndef ITIMER_PROF
#define ITIMER_PROF 2 /*generates sigprof */
+#endif
-struct itimerval {
+struct MLton_itimerval {
struct timeval it_interval;
struct timeval it_value;
};
-int setitimer (int which,
- const struct itimerval *value,
- struct itimerval *ovalue);
+#undef itimerval
+#define itimerval MLton_itimerval
+MLTON_WRAPPER int MLton_setitimer (int which,
+ const struct itimerval *value,
+ struct itimerval *ovalue);
+#undef setitimer
+#define setitimer MLton_setitimer
+
/* ------------------------------------------------- */
/* MLton.Rlimit */
/* ------------------------------------------------- */
+#ifndef RLIMIT_CPU
#define RLIMIT_CPU 0 /* CPU time in seconds */
+#endif
+
+#ifndef RLIMIT_FSIZE
#define RLIMIT_FSIZE 1 /* Maximum filesize */
+#endif
+
+#ifndef RLIMIT_DATA
#define RLIMIT_DATA 2 /* max data size */
+#endif
+
+#ifndef RLIMIT_STACK
#define RLIMIT_STACK 3 /* max stack size */
+#endif
+
+#ifndef RLIMIT_CORE
#define RLIMIT_CORE 4 /* max core file size */
+#endif
+
+#ifndef RLIMIT_NOFILE
#define RLIMIT_NOFILE 5 /* max number of open files */
+#endif
+
+#ifndef RLIMIT_OFILE
#define RLIMIT_OFILE RLIMIT_NOFILE /* BSD name */
+#endif
+
+#ifndef RLIMIT_AS
#define RLIMIT_AS 6 /* address space (virt. memory) limit */
+#endif
#define RLIMIT_NLIMITS 7 /* upper bound of RLIMIT_* defines */
#define RLIM_NLIMITS RLIMIT_NLIMITS
+#ifndef RLIM_INFINITY
#define RLIM_INFINITY (0xffffffffUL)
+#endif
+
+#ifndef RLIM_SAVED_MAX
#define RLIM_SAVED_MAX RLIM_INFINITY
+#endif
+
+#ifndef RLIM_SAVED_CUR
#define RLIM_SAVED_CUR RLIM_INFINITY
+#endif
-typedef unsigned long rlim_t;
+typedef unsigned long MLton_rlim_t;
+#undef rlim_t
+#define rlim_t MLton_rlim_t
-struct rlimit {
+struct MLton_rlimit {
rlim_t rlim_cur;
rlim_t rlim_max;
};
+#undef rlimit
+#define rlimit MLton_rlimit
-int getrlimit (int resource, struct rlimit *rlim);
-int setrlimit (int resource, const struct rlimit *rlim);
+MLTON_WRAPPER int MLton_getrlimit (int resource, struct rlimit *rlim);
+MLTON_WRAPPER int MLton_setrlimit (int resource, const struct rlimit *rlim);
+#undef getrlimit
+#undef setrlimit
+#define getrlimit MLton_getrlimit
+#define setrlimit MLton_setrlimit
/* ------------------------------------------------- */
/* MLton.Rusage */
/* ------------------------------------------------- */
+#ifndef RUSAGE_SELF
#define RUSAGE_SELF 0 /* calling process */
+#endif
+
+#ifndef RUSAGE_CHILDREN
#define RUSAGE_CHILDREN -1 /* terminated child processes */
+#endif
-struct rusage {
+struct MLton_rusage {
struct timeval ru_utime;
struct timeval ru_stime;
};
+#undef rusage
+#define rusage MLton_rusage
-int getrusage (int who, struct rusage *usage);
+MLTON_WRAPPER int MLton_getrusage (int who, struct rusage *usage);
+#undef getrusage
+#define getrusage MLton_getrusage
/* ------------------------------------------------- */
/* OS.IO */
/* ------------------------------------------------- */
-struct pollfd {
+struct MLton_pollfd {
short events;
int fd;
short revents;
};
+#undef pollfd
+#define pollfd MLton_pollfd
-int poll (struct pollfd *ufds, nfds_t nfds, int timeout);
+MLTON_WRAPPER int MLton_poll (struct pollfd *ufds, nfds_t nfds, int timeout);
+#undef poll
+#define poll MLton_poll
/* ------------------------------------------------- */
/* Posix.Error */
/* ------------------------------------------------- */
+#ifndef EINPROGRESS
#define EINPROGRESS WSAEINPROGRESS
+#endif
+
+#ifndef EMSGSIZE
#define EMSGSIZE WSAEMSGSIZE
+#endif
+
+#ifndef ELOOP
#define ELOOP WSAELOOP
+#endif
+
+#ifndef EBADMSG
#define EBADMSG 77
+#endif
/* ------------------------------------------------- */
/* Posix.FileSys */
/* ------------------------------------------------- */
+#ifndef S_IRGRP
#define S_IRGRP 0000040
+#endif
+
+#ifndef S_IROTH
#define S_IROTH 0000004
+#endif
+
+#ifndef S_IRWXG
#define S_IRWXG 0000070
+#endif
+
+#ifndef S_IRWXO
#define S_IRWXO 0000007
+#endif
+
+#ifndef S_ISGID
#define S_ISGID 0002000
+#endif
+
+#ifndef S_ISUID
#define S_ISUID 0004000
+#endif
+
+#ifndef S_IWGRP
#define S_IWGRP 0000020
+#endif
+
+#ifndef S_IWOTH
#define S_IWOTH 0000002
+#endif
+
+#ifndef S_IXGRP
#define S_IXGRP 0000010
+#endif
+
+#ifndef S_IXOTH
#define S_IXOTH 0000001
+#endif
// Do not exist in a windows filesystem
+#ifndef S_IFLNK
#define S_IFLNK 0
+#endif
+
+#ifndef S_IFSOCK
#define S_IFSOCK 0
+#endif
+
+#ifndef S_ISVTX
#define S_ISVTX 0
+#endif
+#ifndef O_NOCTTY
#define O_NOCTTY 0x8000
+#endif
+
+#ifndef O_NONBLOCK
#define O_NONBLOCK 0x4000
+#endif
// Synchronized writes? Safety of any kind? ... and windows?! hell no!
+#ifndef O_SYNC
#define O_SYNC 0
+#endif
// Use m to silence unused warnings
+#undef S_ISLNK
+#undef S_ISSOCK
#define S_ISLNK(m) (m?FALSE:FALSE)
#define S_ISSOCK(m) (m?FALSE:FALSE)
@@ -210,58 +455,118 @@
#define O_ACCMODE O_RDONLY|O_WRONLY|O_RDWR
#endif
-int chown (const char *path, uid_t owner, gid_t group);
-int fchmod (int filedes, mode_t mode);
-int fchdir (int filedes);
-int fchown (int fd, uid_t owner, gid_t group);
-long fpathconf (int filedes, int name);
-int link (const char *oldpath, const char *newpath);
-int lstat (const char *file_name, struct stat *buf);
-int mkfifo (const char *pathname, mode_t mode);
-long pathconf (const char *path, int name);
-int readlink (const char *path, char *buf, size_t bufsiz);
-int symlink (const char *oldpath, const char *newpath);
-int truncate (const char *path, off_t len);
+MLTON_WRAPPER int MLton_chown (const char *path, uid_t owner, gid_t group);
+MLTON_WRAPPER int MLton_fchmod (int filedes, mode_t mode);
+MLTON_WRAPPER int MLton_fchdir (int filedes);
+MLTON_WRAPPER int MLton_fchown (int fd, uid_t owner, gid_t group);
+MLTON_WRAPPER long MLton_fpathconf (int filedes, int name);
+MLTON_WRAPPER int MLton_link (const char *oldpath, const char *newpath);
+MLTON_WRAPPER int MLton_lstat (const char *file_name, struct stat *buf);
+MLTON_WRAPPER int MLton_mkfifo (const char *pathname, mode_t mode);
+MLTON_WRAPPER long MLton_pathconf (const char *path, int name);
+MLTON_WRAPPER int MLton_readlink (const char *path, char *buf, size_t bufsiz);
+MLTON_WRAPPER int MLton_symlink (const char *oldpath, const char *newpath);
+MLTON_WRAPPER int MLton_truncate (const char *path, off_t len);
+#undef chown
+#undef fchmod
+#undef fchdir
+#undef fchown
+#undef fpathconf
+#undef link
+#undef lstat
+#undef mkfifo
+#undef pathconf
+#undef readlink
+#undef symlink
+#undef truncate
+
+#define chown MLton_chown
+#define fchmod MLton_fchmod
+#define fchdir MLton_fchdir
+#define fchown MLton_fchown
+#define fpathconf MLton_fpathconf
+#define link MLton_link
+#define lstat MLton_lstat
+#define mkfifo MLton_mkfifo
+#define pathconf MLton_pathconf
+#define readlink MLton_readlink
+#define symlink MLton_symlink
+#define truncate MLton_truncate
+
+#undef mkdir
#define mkdir(f, m) mkdir(f); chmod(f, m)
/* ------------------------------------------------- */
/* Posix.IO */
/* ------------------------------------------------- */
-struct flock {
+struct MLton_flock {
off_t l_len;
pid_t l_pid;
off_t l_start;
short l_type;
short l_whence;
};
+#undef flock
+#define flock MLton_flock
-int fcntl (int fd, int cmd, ...);
-int fsync (int fd);
-int pipe (int filedes[2]);
+MLTON_WRAPPER int MLton_fcntl (int fd, int cmd, ...);
+MLTON_WRAPPER int MLton_fsync (int fd);
+MLTON_WRAPPER int MLton_pipe (int filedes[2]);
+#undef fcntl
+#undef fsync
+#undef pipe
+
+#define fcntl MLton_fcntl
+#define fsync MLton_fsync
+#define pipe MLton_pipe
+
/* ------------------------------------------------- */
/* Posix.ProcEnv */
/* ------------------------------------------------- */
+#ifndef _SC_ARG_MAX
#define _SC_ARG_MAX 0
+#endif
+
+#ifndef _SC_CHILD_MAX
#define _SC_CHILD_MAX 1
+#endif
+
+#ifndef _SC_CLK_TCK
#define _SC_CLK_TCK 2
+#endif
+
+#ifndef _SC_JOB_CONTROL
#define _SC_JOB_CONTROL 5
+#endif
+
+#ifndef _SC_NGROUPS_MAX
#define _SC_NGROUPS_MAX 3
+#endif
+
+#ifndef _SC_OPEN_MAX
#define _SC_OPEN_MAX 4
+#endif
+
+#ifndef _SC_SAVED_IDS
#define _SC_SAVED_IDS 6
+#endif
+
+#ifndef _SC_VERSION
#define _SC_VERSION 7
+#endif
-struct tms {
+struct MLton_tms {
int tms_utime;
int tms_stime;
int tms_cutime;
int tms_cstime;
};
-struct utsname {
+struct MLton_utsname {
char machine[20];
char nodename[256];
char release[20];
@@ -269,27 +574,76 @@
char version[20];
};
-char *ctermid (char *s);
-gid_t getegid (void);
-uid_t geteuid (void);
-gid_t getgid (void);
-int getgroups (int size, gid_t list[]);
-char *getlogin (void);
-pid_t getpgid(pid_t pid);
-pid_t getpgrp(void);
-pid_t getppid (void);
-uid_t getuid (void);
-int setenv (const char *name, const char *value, int overwrite);
-int setgid (gid_t gid);
-int setgroups (size_t size, const gid_t *list);
-int setpgid (pid_t pid, pid_t pgid);
-pid_t setsid (void);
-int setuid (uid_t uid);
-long sysconf (int name);
-clock_t times (struct tms *buf);
-char *ttyname (int desc);
-int uname (struct utsname *buf);
+#undef tms
+#undef utsname
+#define tms MLton_tms
+#define utsname MLton_utsname
+
+MLTON_WRAPPER char *MLton_getlogin (void);
+MLTON_WRAPPER char *MLton_ctermid (char *s);
+MLTON_WRAPPER gid_t MLton_getegid (void);
+MLTON_WRAPPER uid_t MLton_geteuid (void);
+MLTON_WRAPPER gid_t MLton_getgid (void);
+MLTON_WRAPPER int MLton_getgroups (int size, gid_t list[]);
+MLTON_WRAPPER pid_t MLton_getpgid(pid_t pid);
+MLTON_WRAPPER pid_t MLton_getpgrp(void);
+MLTON_WRAPPER pid_t MLton_getppid (void);
+MLTON_WRAPPER uid_t MLton_getuid (void);
+MLTON_WRAPPER int MLton_setenv (const char *name, const char *value, int overwrite);
+MLTON_WRAPPER int MLton_setgid (gid_t gid);
+MLTON_WRAPPER int MLton_setgroups (size_t size, const gid_t *list);
+MLTON_WRAPPER int MLton_setpgid (pid_t pid, pid_t pgid);
+MLTON_WRAPPER pid_t MLton_setsid (void);
+MLTON_WRAPPER int MLton_setuid (uid_t uid);
+MLTON_WRAPPER long MLton_sysconf (int name);
+MLTON_WRAPPER clock_t MLton_times (struct tms *buf);
+MLTON_WRAPPER char *MLton_ttyname (int desc);
+MLTON_WRAPPER int MLton_uname (struct utsname *buf);
+
+#undef getlogin
+#undef ctermid
+#undef getegid
+#undef geteuid
+#undef getgid
+#undef getgroups
+#undef getpgid
+#undef getpgrp
+#undef getppid
+#undef getuid
+#undef setenv
+#undef setgid
+#undef setgroups
+#undef setpgid
+#undef setsid
+#undef setuid
+#undef sysconf
+#undef times
+#undef ttyname
+#undef uname
+
+#define getlogin MLton_getlogin
+#define ctermid MLton_ctermid
+#define getegid MLton_getegid
+#define geteuid MLton_geteuid
+#define getgid MLton_getgid
+#define getgroups MLton_getgroups
+#define getpgid MLton_getpgid
+#define getpgrp MLton_getpgrp
+#define getppid MLton_getppid
+#define getuid MLton_getuid
+#define setenv MLton_setenv
+#define setgid MLton_setgid
+#define setgroups MLton_setgroups
+#define setpgid MLton_setpgid
+#define setsid MLton_setsid
+#define setuid MLton_setuid
+#define sysconf MLton_sysconf
+#define times MLton_times
+#define ttyname MLton_ttyname
+#define uname MLton_uname
+
+
/* ------------------------------------------------- */
/* Posix.Process */
/* ------------------------------------------------- */
@@ -308,14 +662,37 @@
<code> == 80, there was a core dump.
*/
+#ifndef WNOHANG
#define WNOHANG 1
+#endif
+
+#ifndef WUNTRACED
#define WUNTRACED 2
+#endif
+
+#ifndef WIFEXITED
#define WIFEXITED(w) (((w) & 0xff) == 0)
+#endif
+
+#ifndef WIFSIGNALED
#define WIFSIGNALED(w) (((w) & 0x7f) > 0 && (((w) & 0x7f) < 0x7f))
+#endif
+
+#ifndef WIFSTOPPED
#define WIFSTOPPED(w) (((w) & 0xff) == 0x7f)
+#endif
+
+#ifndef WEXITSTATUS
#define WEXITSTATUS(w) (((w) >> 8) & 0xff)
+#endif
+
+#ifndef WTERMSIG
#define WTERMSIG(w) ((w) & 0x7f)
+#endif
+
+#ifndef WSTOPSIG
#define WSTOPSIG WEXITSTATUS
+#endif
/* Sometimes defined by mingw */
#ifndef TIMESPEC_DEFINED
@@ -325,25 +702,51 @@
};
#endif
-int alarm (int secs);
-int fork(void); /* mingw demands this return int */
-int kill (pid_t pid, int sig);
-int pause (void);
-int nanosleep (const struct timespec *req, struct timespec *rem);
-unsigned int sleep (unsigned int seconds);
-pid_t wait (int *status);
-pid_t waitpid (pid_t pid, int *status, int options);
+MLTON_WRAPPER int MLton_alarm(int);
+MLTON_WRAPPER int MLton_fork(void); /* mingw demands this return int */
+MLTON_WRAPPER int MLton_kill (pid_t pid, int sig);
+MLTON_WRAPPER int MLton_pause (void);
+MLTON_WRAPPER int MLton_nanosleep (const struct timespec *req, struct timespec *rem);
+MLTON_WRAPPER unsigned int MLton_sleep (unsigned int seconds);
+MLTON_WRAPPER pid_t MLton_wait (int *status);
+MLTON_WRAPPER pid_t MLton_waitpid (pid_t pid, int *status, int options);
+#undef alarm
+#undef fork
+#undef kill
+#undef pause
+#undef nanosleep
+#undef sleep
+#undef wait
+#undef waitpid
+
+#define alarm MLton_alarm
+#define fork MLton_fork
+#define kill MLton_kill
+#define pause MLton_pause
+#define nanosleep MLton_nanosleep
+#define sleep MLton_sleep
+#define wait MLton_wait
+#define waitpid MLton_waitpid
+
/* ------------------------------------------------- */
/* Posix.Signal */
/* ------------------------------------------------- */
+/* Sometimes mingw defines some of these. Some not. Some always. */
+
+#ifndef SIG_BLOCK
#define SIG_BLOCK 1
+#endif
+
+#ifndef SIG_SETMASK
#define SIG_SETMASK 0
+#endif
+
+#ifndef SIG_UNBLOCK
#define SIG_UNBLOCK 2
+#endif
-/* Sometimes mingw defines some of these. Some not. Some always. */
-
#ifndef SIGHUP
#define SIGHUP 1
#endif
@@ -385,54 +788,117 @@
/* SIGABRT2 = 22 */
/* These signals are fake. They do not exist on windows. */
+
+#ifndef SIGSTOP
#define SIGSTOP 16
+#endif
+
+#ifndef SIGTSTP
#define SIGTSTP 18
+#endif
+
+#ifndef SIGCHLD
#define SIGCHLD 23
+#endif
+
+#ifndef SIGTTIN
#define SIGTTIN 24
+#endif
+
+#ifndef SIGTTOU
#define SIGTTOU 25
+#endif
+
+#ifndef SIGCONT
#define SIGCONT 26
+#endif
+
+#ifndef SIGUSR1
#define SIGUSR1 27
+#endif
+
+#ifndef SIGUSR2
#define SIGUSR2 28
+#endif
+
+#ifndef SIGVTALRM
#define SIGVTALRM 29 /* virtual time alarm */
+#endif
+
+#ifndef SIGPROF
#define SIGPROF 30 /* profiling time alarm */
+#endif
+#ifndef _NSIG
#define _NSIG 32
+#endif
-typedef __p_sig_fn_t _sig_func_ptr;
-typedef int sigset_t; /* sometimes defined my mingw as int */
+typedef __p_sig_fn_t MLton__sig_func_ptr;
+typedef int MLton_sigset_t;
-struct sigaction {
+#undef _sig_func_ptr
+#undef sigset_t
+
+#define _sig_func_ptr MLton__sig_func_ptr
+#define sigset_t MLton_sigset_t
+
+struct MLton_sigaction {
int sa_flags;
sigset_t sa_mask;
_sig_func_ptr sa_handler;
};
+#undef sigaction
+#define sigaction MLton_sigaction
+
+#ifndef SIGTOMASK
#define SIGTOMASK(sn) (1 << ((sn)-1))
+#endif
-int sigaction (int signum,
- const struct sigaction *act,
- struct sigaction *oldact);
-int sigaddset (sigset_t *set, int signum);
-int sigdelset (sigset_t *set, int signum);
-int sigemptyset (sigset_t *set);
-int sigfillset (sigset_t *set);
-int sigismember (const sigset_t *set, int signum);
-int sigpending (sigset_t *set);
-int sigprocmask (int how, const sigset_t *set, sigset_t *oldset);
-int sigsuspend (const sigset_t *mask);
+MLTON_WRAPPER int MLton_sigaction (int signum,
+ const struct sigaction *act,
+ struct sigaction *oldact);
+MLTON_WRAPPER int MLton_sigaddset (sigset_t *set, int signum);
+MLTON_WRAPPER int MLton_sigdelset (sigset_t *set, int signum);
+MLTON_WRAPPER int MLton_sigemptyset (sigset_t *set);
+MLTON_WRAPPER int MLton_sigfillset (sigset_t *set);
+MLTON_WRAPPER int MLton_sigismember (const sigset_t *set, int signum);
+MLTON_WRAPPER int MLton_sigpending (sigset_t *set);
+MLTON_WRAPPER int MLton_sigprocmask (int how, const sigset_t *set, sigset_t *oldset);
+MLTON_WRAPPER int MLton_sigsuspend (const sigset_t *mask);
+#undef sigaction
+#undef sigaddset
+#undef sigdelset
+#undef sigemptyset
+#undef sigfillset
+#undef sigismember
+#undef sigpending
+#undef sigprocmask
+#undef sigsuspend
+
+#define sigaction MLton_sigaction
+#define sigaddset MLton_sigaddset
+#define sigdelset MLton_sigdelset
+#define sigemptyset MLton_sigemptyset
+#define sigfillset MLton_sigfillset
+#define sigismember MLton_sigismember
+#define sigpending MLton_sigpending
+#define sigprocmask MLton_sigprocmask
+#define sigsuspend MLton_sigsuspend
+
/* ------------------------------------------------- */
/* Posix.SysDB.Passwd */
/* ------------------------------------------------- */
-struct group {
+struct MLton_group {
gid_t gr_gid;
char **gr_mem;
char *gr_name;
char *gr_passwd;
};
-struct passwd {
+struct MLton_passwd {
char *pw_dir;
gid_t pw_gid;
char *pw_name;
@@ -440,135 +906,455 @@
uid_t pw_uid;
};
-struct group *getgrgid (gid_t gid);
-struct group *getgrnam (const char *name);
-struct passwd *getpwnam (const char *name);
-struct passwd *getpwuid (uid_t uid);
+#undef group
+#undef passwd
+#define group MLton_group
+#define passwd MLton_passwd
+MLTON_WRAPPER struct group *MLton_getgrgid (gid_t gid);
+MLTON_WRAPPER struct group *MLton_getgrnam (const char *name);
+MLTON_WRAPPER struct passwd *MLton_getpwnam (const char *name);
+MLTON_WRAPPER struct passwd *MLton_getpwuid (uid_t uid);
+
+#undef getgrgid
+#undef getgrnam
+#undef getpwnam
+#undef getpwuid
+
+#define getgrgid MLton_getgrgid
+#define getgrnam MLton_getgrnam
+#define getpwnam MLton_getpwnam
+#define getpwuid MLton_getpwuid
+
/* ------------------------------------------------- */
/* Posix.TTY */
/* ------------------------------------------------- */
+#ifndef B0
#define B0 0x00000
+#endif
+
+#ifndef B50
#define B50 0x00001
+#endif
+
+#ifndef B75
#define B75 0x00002
+#endif
+
+#ifndef B110
#define B110 0x00003
+#endif
+
+#ifndef B134
#define B134 0x00004
+#endif
+
+#ifndef B150
#define B150 0x00005
+#endif
+
+#ifndef B200
#define B200 0x00006
+#endif
+
+#ifndef B300
#define B300 0x00007
+#endif
+
+#ifndef B600
#define B600 0x00008
+#endif
+
+#ifndef B1200
#define B1200 0x00009
+#endif
+
+#ifndef B1800
#define B1800 0x0000a
+#endif
+
+#ifndef B2400
#define B2400 0x0000b
+#endif
+
+#ifndef B4800
#define B4800 0x0000c
+#endif
+
+#ifndef B9600
#define B9600 0x0000d
+#endif
+
+#ifndef B19200
#define B19200 0x0000e
+#endif
+
+#ifndef B38400
#define B38400 0x0000f
+#endif
+
+#ifndef VEOL
#define VEOL 2
+#endif
+
+#ifndef VEOL2
#define VEOL2 3
+#endif
+
+#ifndef VEOF
#define VEOF 4
+#endif
+
+#ifndef VERASE
#define VERASE 5
+#endif
+
+#ifndef VINTER
#define VINTR 6
+#endif
+
+#ifndef VKILL
#define VKILL 7
+#endif
+
+#ifndef VLNEXT
#define VLNEXT 8
+#endif
+
+#ifndef VMIN
#define VMIN 9
+#endif
+
+#ifndef VQUIT
#define VQUIT 10
+#endif
+
+#ifndef VREPRINT
#define VREPRINT 11
+#endif
+
+#ifndef VSTART
#define VSTART 12
+#endif
+
+#ifndef VSTOP
#define VSTOP 13
+#endif
+
+#ifndef VSUSP
#define VSUSP 14
+#endif
+
+#ifndef VSWTC
#define VSWTC 15
+#endif
+
+#ifndef VTIME
#define VTIME 16
+#endif
+
+#ifndef VWERASE
#define VWERASE 17
+#endif
+#ifndef NCCS
#define NCCS 18
+#endif
+#ifndef IGNBRK
#define IGNBRK 0x00001
+#endif
+
+#ifndef BRKINT
#define BRKINT 0x00002
+#endif
+
+#ifndef IGNPAR
#define IGNPAR 0x00004
+#endif
+
+#ifndef IMAXBEL
#define IMAXBEL 0x00008
+#endif
+
+#ifndef INPCK
#define INPCK 0x00010
+#endif
+
+#ifndef ISTRIP
#define ISTRIP 0x00020
+#endif
+
+#ifndef INLCR
#define INLCR 0x00040
+#endif
+
+#ifndef IGNCR
#define IGNCR 0x00080
+#endif
+
+#ifndef ICRNL
#define ICRNL 0x00100
+#endif
+
+#ifndef IXON
#define IXON 0x00400
+#endif
+
+#ifndef IXOFF
#define IXOFF 0x01000
+#endif
+
+#ifndef IUCLC
#define IUCLC 0x04000
+#endif
+
+#ifndef IXANY
#define IXANY 0x08000
+#endif
+
+#ifndef PARMRK
#define PARMRK 0x10000
+#endif
+
+#ifndef OPOST
#define OPOST 0x00001
+#endif
+
+#ifndef CSIZE
#define CSIZE 0x00030
+#endif
+
+#ifndef CS5
#define CS5 0x00000
+#endif
+
+#ifndef CS6
#define CS6 0x00010
+#endif
+
+#ifndef CS7
#define CS7 0x00020
+#endif
+
+#ifndef CS8
#define CS8 0x00030
+#endif
+
+#ifndef CSTOPB
#define CSTOPB 0x00040
+#endif
+
+#ifndef CREAD
#define CREAD 0x00080
+#endif
+
+#ifndef PARENB
#define PARENB 0x00100
+#endif
+
+#ifndef PARODD
#define PARODD 0x00200
+#endif
+
+#ifndef HPUCL
#define HUPCL 0x00400
+#endif
+
+#ifndef CLOCAL
#define CLOCAL 0x00800
+#endif
+
+#ifndef CBAUDEX
#define CBAUDEX 0x0100f
+#endif
+
+#ifndef B57600
#define B57600 0x01001
+#endif
+
+#ifndef B115200
#define B115200 0x01002
+#endif
+
+#ifndef B128000
#define B128000 0x01003
+#endif
+
+#ifndef B230400
#define B230400 0x01004
+#endif
+
+#ifndef B256000
#define B256000 0x01005
+#endif
+
+#ifndef CRTSXOFF
#define CRTSXOFF 0x04000
+#endif
+
+#ifndef CRTSCTS
#define CRTSCTS 0x08000
+#endif
+
+#ifndef ISIG
#define ISIG 0x0001
+#endif
+
+#ifndef ICANON
#define ICANON 0x0002
+#endif
+
+#ifndef ECHO
#define ECHO 0x0004
+#endif
+
+#ifndef ECHOE
#define ECHOE 0x0008
+#endif
+
+#ifndef ECHOK
#define ECHOK 0x0010
+#endif
+
+#ifndef ECHONL
#define ECHONL 0x0020
+#endif
+
+#ifndef NOFLSH
#define NOFLSH 0x0040
+#endif
+
+#ifndef TOSTOP
#define TOSTOP 0x0080
+#endif
+
+#ifndef IEXTEN
#define IEXTEN 0x0100
+#endif
+
+#ifndef FLUSHO
#define FLUSHO 0x0200
+#endif
+
+#ifndef ECHOKE
#define ECHOKE 0x0400
+#endif
+
+#ifndef ECHOCTL
#define ECHOCTL 0x0800
+#endif
+
+#ifndef TCOOFF
#define TCOOFF 0
+#endif
+
+#ifndef TCOON
#define TCOON 1
+#endif
+
+#ifndef TCIOFF
#define TCIOFF 2
+#endif
+
+#ifndef TCION
#define TCION 3
+#endif
+
+#ifndef TCIFLUSH
#define TCIFLUSH 0
+#endif
+
+#ifndef TCOFLUSH
#define TCOFLUSH 1
+#endif
+
+#ifndef TCIOFLUSH
#define TCIOFLUSH 2
+#endif
+
+#ifndef TCFLSH
#define TCFLSH 3
+#endif
+#ifndef TCSAFLUSH
#define TCSAFLUSH 1
+#endif
+
+#ifndef TCSANOW
#define TCSANOW 2
+#endif
+
+#ifndef TCSADRAIN
#define TCSADRAIN 3
+#endif
+
+#ifndef TCSADFLUSH
#define TCSADFLUSH 4
+#endif
-typedef unsigned char cc_t;
-typedef unsigned int speed_t;
-typedef unsigned int tcflag_t;
+typedef unsigned char MLton_cc_t;
+typedef unsigned int MLton_speed_t;
+typedef unsigned int MLton_tcflag_t;
-struct termios {
+#undef cc_t
+#undef speed_t
+#undef tcflag_t
+
+#define cc_t MLton_cc_t
+#define speed_t MLton_speed_t
+#define tcflag_t MLton_tcflag_t
+
+struct MLton_termios {
cc_t c_cc[NCCS];
tcflag_t c_cflag;
tcflag_t c_iflag;
tcflag_t c_lflag;
tcflag_t c_oflag;
};
+#undef termios
+#define termios MLton_termios
-speed_t cfgetispeed (struct termios *termios_p);
-speed_t cfgetospeed (struct termios *termios_p);
-int cfsetispeed (struct termios *termios_p, speed_t speed);
-int cfsetospeed (struct termios *termios_p, speed_t speed);
-int tcdrain (int fd);
-int tcflow (int fd, int action);
-int tcflush (int fd, int queue_selector);
-int tcgetattr (int fd, struct termios *termios_p);
-pid_t tcgetpgrp (int fd);
-int tcsendbreak (int fd, int duration);
-int tcsetattr (int fd, int optional_actions, struct termios *termios_p);
-int tcsetpgrp (int fd, pid_t pgrpid);
+MLTON_WRAPPER speed_t MLton_cfgetispeed (struct termios *termios_p);
+MLTON_WRAPPER speed_t MLton_cfgetospeed (struct termios *termios_p);
+MLTON_WRAPPER int MLton_cfsetispeed (struct termios *termios_p, speed_t speed);
+MLTON_WRAPPER int MLton_cfsetospeed (struct termios *termios_p, speed_t speed);
+MLTON_WRAPPER int MLton_tcdrain (int fd);
+MLTON_WRAPPER int MLton_tcflow (int fd, int action);
+MLTON_WRAPPER int MLton_tcflush (int fd, int queue_selector);
+MLTON_WRAPPER int MLton_tcgetattr (int fd, struct termios *termios_p);
+MLTON_WRAPPER pid_t MLton_tcgetpgrp (int fd);
+MLTON_WRAPPER int MLton_tcsendbreak (int fd, int duration);
+MLTON_WRAPPER int MLton_tcsetattr (int fd, int optional_actions, struct termios *termios_p);
+MLTON_WRAPPER int MLton_tcsetpgrp (int fd, pid_t pgrpid);
+#undef cfgetispeed
+#undef cfgetospeed
+#undef cfsetispeed
+#undef cfsetospeed
+#undef tcdrain
+#undef tcflow
+#undef tcflush
+#undef tcgetattr
+#undef tcgetpgrp
+#undef tcsendbreak
+#undef tcsetattr
+#undef tcsetpgrp
+
+#define cfgetispeed MLton_cfgetispeed
+#define cfgetospeed MLton_cfgetospeed
+#define cfsetispeed MLton_cfsetispeed
+#define cfsetospeed MLton_cfsetospeed
+#define tcdrain MLton_tcdrain
+#define tcflow MLton_tcflow
+#define tcflush MLton_tcflush
+#define tcgetattr MLton_tcgetattr
+#define tcgetpgrp MLton_tcgetpgrp
+#define tcsendbreak MLton_tcsendbreak
+#define tcsetattr MLton_tcsetattr
+#define tcsetpgrp MLton_tcsetpgrp
+
/* ------------------------------------------------- */
/* Socket */
/* ------------------------------------------------- */
@@ -577,74 +1363,206 @@
#ifndef MSG_WAITALL
#define MSG_WAITALL 0x8
#endif
+
+#ifndef MSG_DONTWAIT
#define MSG_DONTWAIT 0
+#endif
+
+#ifndef MSG_EOR
#define MSG_EOR 0
+#endif
+
+#ifndef MSG_CTRUNC
#define MSG_CTRUNC 0
+#endif
-// Has a different name:
+#ifndef MSG_TRUNC
#define MSG_TRUNC MSG_PARTIAL
+#endif
-
+#ifndef UNIX_PATH_MAX
#define UNIX_PATH_MAX 108
+#endif
-typedef unsigned short sa_family_t;
+typedef unsigned short MLton_sa_family_t;
+#undef sa_family_t
+#define sa_family_t MLton_sa_family_t
-struct sockaddr_un {
+struct MLton_sockaddr_un {
sa_family_t sun_family;
char sun_path[UNIX_PATH_MAX];
};
+#undef sockaddr_un
+#define sockaddr_un MLton_sockaddr_un
-int ioctl (int d, int request, ...);
-int socketpair (int d, int type, int protocol, int sv[2]);
+MLTON_WRAPPER int MLton_ioctl (int d, int request, ...);
+MLTON_WRAPPER int MLton_socketpair (int d, int type, int protocol, int sv[2]);
+#undef ioctl
+#undef socketpair
+
+#define ioctl MLton_ioctl
+#define socketpair MLton_socketpair
+
/* ------------------------------------------------- */
/* Syslog */
/* ------------------------------------------------- */
+#ifndef LOG_EMERG
#define LOG_EMERG 7
+#endif
+
+#ifndef LOG_ALERT
#define LOG_ALERT 6
+#endif
+
+#ifndef LOG_CRIT
#define LOG_CRIT 5
+#endif
+
+#ifndef LOG_ERR
#define LOG_ERR 4
+#endif
+
+#ifndef LOG_WARNING
#define LOG_WARNING 3
+#endif
+
+#ifndef LOG_NOTICE
#define LOG_NOTICE 2
+#endif
+
+#ifndef LOG_INFO
#define LOG_INFO 1
+#endif
+
+#ifndef LOG_DEBUG
#define LOG_DEBUG 0
+#endif
+#ifndef LOG_PID
#define LOG_PID 0x01 /* include PID in output */
+#endif
+
+#ifndef LOG_CONS
#define LOG_CONS 0x02 /* dump to console (meaningless for windows?) */
+#endif
+
+#ifndef LOG_ODELAY
#define LOG_ODELAY 0x04 /* delay open; meaningless---always open */
+#endif
+
+#ifndef LOG_NDELAY
#define LOG_NDELAY 0x08 /* don't delay; meaningless */
+#endif
+
+#ifndef LOG_NOWAIT
#define LOG_NOWAIT 0x10 /* ignored and obsolete anyways */
+#endif
+
+#ifndef LOG_PERROR
#define LOG_PERROR 0x20 /* print to standard error, honoured */
+#endif
+#ifndef LOG_AUTH
#define LOG_AUTH 1
+#endif
+
+#ifndef LOG_CRON
#define LOG_CRON 2
+#endif
+
+#ifndef LOG_DAEMON
#define LOG_DAEMON 3
+#endif
+
+#ifndef LOG_KERN
#define LOG_KERN 4
+#endif
+
+#ifndef LOG_LOCAL0
#define LOG_LOCAL0 5
+#endif
+
+#ifndef LOG_LOCAL1
#define LOG_LOCAL1 6
+#endif
+
+#ifndef LOG_LOCAL2
#define LOG_LOCAL2 7
+#endif
+
+#ifndef LOG_LOCAL3
#define LOG_LOCAL3 8
+#endif
+
+#ifndef LOG_LOCAL4
#define LOG_LOCAL4 9
+#endif
+
+#ifndef LOG_LOCAL5
#define LOG_LOCAL5 10
+#endif
+
+#ifndef LOG_LOCAL6
#define LOG_LOCAL6 11
+#endif
+
+#ifndef LOG_LOCAL7
#define LOG_LOCAL7 12
+#endif
+
+#ifndef LOG_LPR
#define LOG_LPR 13
+#endif
+
+#ifndef LOG_MAIL
#define LOG_MAIL 14
+#endif
+
+#ifndef LOG_NEWS
#define LOG_NEWS 15
+#endif
+
+#ifndef LOG_SYSLOG
#define LOG_SYSLOG 16
+#endif
+
+#ifndef LOG_USER
#define LOG_USER 17
+#endif
+
+#ifndef LOG_UUCP
#define LOG_UUCP 18
+#endif
-void openlog(const char* ident, int logopt, int facility);
-void closelog(void);
-void syslog(int priority, const char* fmt, const char* msg);
+MLTON_WRAPPER void MLton_openlog(const char* ident, int logopt, int facility);
+MLTON_WRAPPER void MLton_closelog(void);
+MLTON_WRAPPER void MLton_syslog(int priority, const char* fmt, const char* msg);
+#undef openlog
+#undef closelog
+#undef syslog
+
+#define openlog MLton_openlog
+#define closelog MLton_closelog
+#define syslog MLton_syslog
+
/* ------------------------------------------------- */
/* libdl */
/* ------------------------------------------------- */
-void *dlopen(const char *filename, int flag_IGNORED);
-const char *dlerror(void);
-void *dlsym(void *void_hmodule, const char *symbol);
-int dlclose(void *void_hmodule);
+MLTON_WRAPPER void *MLton_dlopen(const char *filename, int flag_IGNORED);
+MLTON_WRAPPER const char *MLton_dlerror(void);
+MLTON_WRAPPER void *MLton_dlsym(void *void_hmodule, const char *symbol);
+MLTON_WRAPPER int MLton_dlclose(void *void_hmodule);
+
+#undef dlopen
+#undef dlerror
+#undef dlsym
+#undef dlclose
+
+#define dlopen MLton_dlopen
+#define dlerror MLton_dlerror
+#define dlsym MLton_dlsym
+#define dlclose MLton_dlclose
More information about the MLton-commit
mailing list