[MLton-commit] r4522

Wesley Terpstra MLton@mlton.org
Wed, 10 May 2006 09:44:58 -0700


stub syslog functionality, ftruncate and getpid exist in mingw now
----------------------------------------------------------------------

U   mlton/branches/on-20050822-x86_64-branch/runtime/platform/mingw.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/platform/mingw.h

----------------------------------------------------------------------

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/platform/mingw.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/platform/mingw.c	2006-05-10 16:04:44 UTC (rev 4521)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/platform/mingw.c	2006-05-10 16:44:52 UTC (rev 4522)
@@ -165,7 +165,6 @@
 /*                   Posix.FileSys                   */
 /* ------------------------------------------------- */
 
-#if FALSE
 static void GetWin32FileName (int fd, char* fname) {
         HANDLE fh, fhmap;
         DWORD fileSize, fileSizeHi;
@@ -184,18 +183,16 @@
         }
         return; 
 }
-#endif
 
-int chown (const char *path, uid_t owner, gid_t group) {
-        die ("chown not implemented");
+int fchmod (int filedes, mode_t mode) {
+      char fname[MAX_PATH + 1];
+
+      GetWin32FileName (filedes, fname);
+      return _chmod (fname, mode);
 }
 
-int fchmod (int filedes, mode_t mode) {
+int chown (const char *path, uid_t owner, gid_t group) {
         die ("chown not implemented");
-//      char fname[MAX_PATH + 1];
-//
-//      GetWin32FileName (filedes, fname);
-//      return _chmod (fname, mode);
 }
 
 int fchown (int fd, uid_t owner, gid_t group) {
@@ -206,10 +203,6 @@
         die ("fpathconf not implemented");
 }
 
-int ftruncate (int fd, off_t length) {
-        return _chsize (fd, length);
-}
-
 int link (const char *oldpath, const char *newpath) {
         die ("link not implemented");
 }
@@ -311,9 +304,6 @@
 pid_t getpgrp(void) {
         die ("getpgrp not implemented");
 }
-pid_t getpid (void) {
-        die ("getpid not implemented");
-}
 pid_t getppid (void) {
         die ("getppid not implemented");
 }
@@ -748,3 +738,46 @@
                 WSAStartup (version, &wsaData);
         }
 }
+
+/* ------------------------------------------------- */
+/*                      Socket                       */
+/* ------------------------------------------------- */
+
+static const char* logident = "<unknown>";
+static int logopt = LOG_PERROR;
+static int logfacility = LOG_LOCAL0;
+
+void openlog(const char* ident, int opt, int facility) {
+  logident = ident;
+  logopt = logopt;
+  logfacility = facility;
+}
+
+void closelog(void) {
+}
+
+void syslog(int priority, const char* fmt, const char* msg) {
+  static const char* severity[] = {
+    "debug", 
+    "informational", 
+    "notice", 
+    "warning", 
+    "error", 
+    "CRITICAL", 
+    "ALERT", 
+    "EMERGENCY"
+  };
+  
+  if (priority < 0) priority = LOG_DEBUG;
+  if (priority > LOG_EMERG) priority = LOG_EMERG;
+  
+  
+  /* !!! Use ReportEvent to log with windows */
+  
+  if ((logopt & LOG_PERROR) != 0) {
+    if ((logopt & LOG_PID) != 0)
+      fprintf("%s(%d): %s: %s\n", logident, getpid(), severity[priority], msg);
+    else
+      fprintf("%s: %s: %s\n", logident, severity[priority], msg);
+  }
+}

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/platform/mingw.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/platform/mingw.h	2006-05-10 16:04:44 UTC (rev 4521)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/platform/mingw.h	2006-05-10 16:44:52 UTC (rev 4522)
@@ -34,7 +34,7 @@
 
 // bullshit typedefs:
 typedef int id_t; // waitid() doesn't exist on windows
-typedef short nfds_t; // poll() doesn't either
+typedef unsigned int nfds_t; // we have a fake poll() with this many fds
 
 int getpagesize (void);
 int mkstemp (char *template);
@@ -154,7 +154,7 @@
         short revents;
 };
 
-int poll (struct pollfd *ufds, unsigned int nfds, int timeout);
+int poll (struct pollfd *ufds, nfds_t nfds, int timeout);
 
 /* ------------------------------------------------- */
 /*                    Posix.Error                    */
@@ -520,33 +520,41 @@
 /*                      Syslog                       */
 /* ------------------------------------------------- */
 
-#define LOG_ALERT 0
-#define LOG_AUTHPRIV 0
-#define LOG_CONS 0
-#define LOG_CRIT 0
-#define LOG_CRON 0
-#define LOG_DAEMON 0
+#define LOG_EMERG 7
+#define LOG_ALERT 6
+#define LOG_CRIT 5
+#define LOG_ERR 4
+#define LOG_WARNING 3
+#define LOG_NOTICE 2
+#define LOG_INFO 1
 #define LOG_DEBUG 0
-#define LOG_EMERG 0
-#define LOG_ERR 0
-#define LOG_INFO 0
-#define LOG_KERN 0
-#define LOG_LOCAL0 0
-#define LOG_LOCAL1 0
-#define LOG_LOCAL2 0
-#define LOG_LOCAL3 0
-#define LOG_LOCAL4 0
-#define LOG_LOCAL5 0
-#define LOG_LOCAL6 0
-#define LOG_LOCAL7 0
-#define LOG_LPR 0
-#define LOG_MAIL 0
-#define LOG_NDELAY 0
-#define LOG_NEWS 0
-#define LOG_NOTICE 0
-#define LOG_PERROR 0
-#define LOG_PID 0
-#define LOG_SYSLOG 0
-#define LOG_USER 0
-#define LOG_UUCP 0
-#define LOG_WARNING 0
+
+#define LOG_PID    0x01 /* include PID in output */
+#define LOG_CONS   0x02 /* dump to console (meaningless for windows?) */
+#define LOG_ODELAY 0x04 /* delay open; meaningless---always open */
+#define LOG_NDELAY 0x08 /* don't delay; meaningless */
+#define LOG_NOWAIT 0x10 /* ignored and obsolete anyways */
+#define LOG_PERROR 0x20 /* print to standard error, honoured */
+
+#define LOG_AUTH 1
+#define LOG_CRON 2
+#define LOG_DAEMON 3
+#define LOG_KERN 4
+#define LOG_LOCAL0 5
+#define LOG_LOCAL1 6
+#define LOG_LOCAL2 7
+#define LOG_LOCAL3 8
+#define LOG_LOCAL4 9
+#define LOG_LOCAL5 10
+#define LOG_LOCAL6 11
+#define LOG_LOCAL7 12
+#define LOG_LPR 13
+#define LOG_MAIL 14
+#define LOG_NEWS 15
+#define LOG_SYSLOG 16
+#define LOG_USER 17
+#define LOG_UUCP 18
+
+void openlog(const char* ident, int logopt, int facility);
+void closelog(void);
+void syslog(int priority, const char* fmt, const char* msg);