[MLton] Bug in implementation of "strerror" on MinGW

Nicolas Bertolotti Nicolas.Bertolotti at mathworks.fr
Tue Jul 6 06:07:23 PDT 2010


Hello,

I noticed that the function strerror() has been overridden for the MinGW version of MLton.

The overridden version uses "FormatMessage()" in order to build the error message. This was done in order to deal with extended error codes that have been introduced for sockets handling.

The problem with this implementation is that it leads to wrong results for existing error codes.
For example, with ENOSPC, strerror() should return "No space left on device". Anyway, the MLton implementation returns "The printer is out of paper" because the "errno" value does not have the same meaning than the corresponding system error code on Windows.

If you are absolutely sure that the extended error codes that have been introduced will not conflict with the existing "errno" values, a solution would consist in adding the following block of code at the beginning of the "MLton_strerror()" function :
  char *MLton_strerror(int code) {
          static char buffer[512];

+        /* FormatMessage() should only be called to generate an error message for the extended error codes. */
+        if (code < _sys_nerr)
+           return _strerror(code);
+

Best regards

Nicolas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mlton.org/pipermail/mlton/attachments/20100706/56a4c4a6/attachment.htm


More information about the MLton mailing list