[MLton-commit] r7203

Wesley Terpstra wesley at mlton.org
Wed Jul 1 10:23:16 PDT 2009


Now that the error codes in errno have been extended to include winsock
codes, strerror is no longer sufficient to convert them. The FormatError
message gets the job done... in multiple languages!


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

U   mlton/trunk/runtime/platform/mingw.c
U   mlton/trunk/runtime/platform/mingw.h
U   mlton/trunk/runtime/util.c

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

Modified: mlton/trunk/runtime/platform/mingw.c
===================================================================
--- mlton/trunk/runtime/platform/mingw.c	2009-07-01 13:08:26 UTC (rev 7202)
+++ mlton/trunk/runtime/platform/mingw.c	2009-07-01 17:23:15 UTC (rev 7203)
@@ -1263,6 +1263,29 @@
         }
 }
 
+/* The default strerror() does not know extended error codes. */
+char *MLton_strerror(int code) {
+        static char buffer[512];
+        
+        /* Windows specific strerror */
+        if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 
+                          0,      /* Not used for FROM_SYSTEM */
+                          code,   /* The status code to look up */
+                          0,      /* Use the default language */
+                          buffer, /* Write the message to here */
+                          sizeof(buffer)-1,
+                          0) == 0) {
+                strcpy(buffer, "Unknown error");
+        }
+        
+        /* Cut message at EOL */
+        for (int i = 0; buffer[i]; ++i)
+                if (buffer[i] == '\n' || buffer[i] == '\r')
+                        buffer[i] = 0;
+        
+        return buffer;
+}
+
 int MLton_recv(int s, void *buf, int len, int flags) {
         int ret, status = 0;
         

Modified: mlton/trunk/runtime/platform/mingw.h
===================================================================
--- mlton/trunk/runtime/platform/mingw.h	2009-07-01 13:08:26 UTC (rev 7202)
+++ mlton/trunk/runtime/platform/mingw.h	2009-07-01 17:23:15 UTC (rev 7203)
@@ -364,6 +364,12 @@
 /*                    Posix.Error                    */
 /* ------------------------------------------------- */
 
+/* We cannot yet replace strerror at the time util.c is built */
+#ifndef MLTON_UTIL
+MLTON_WRAPPER char *MLton_strerror(int code);
+#undef strerror
+#define strerror MLton_strerror
+#endif
 
 /* If MinGW doesn't (currently) define an error status we need, but winsock
  * does, then default to using the winsock status. They will not conflict.

Modified: mlton/trunk/runtime/util.c
===================================================================
--- mlton/trunk/runtime/util.c	2009-07-01 13:08:26 UTC (rev 7202)
+++ mlton/trunk/runtime/util.c	2009-07-01 17:23:15 UTC (rev 7203)
@@ -5,5 +5,6 @@
  * See the file MLton-LICENSE for details.
  */
 
+#define MLTON_UTIL
 #include "util/die.c"
 #include "util/to-string.c"




More information about the MLton-commit mailing list