Re: Bug in implementation of "strerror" on MinGW
"Wesley W. Terpstra" <[email protected]>
| Newsgroups | gmane.comp.lang.ml.mlton.devel |
|---|---|
| Message-ID | <[email protected]> |
On Tue, Jul 6, 2010 at 3:07 PM, Nicolas Bertolotti <[email protected]> wrote: > 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. Hah! > If you are absolutely sure that the extended error codes that have been introduced will not conflict with the existing “errno” values... Ok, so I've done a bit of checking. According to <http://msdn.microsoft.com/en-us/library/aa924071.aspx>, the winsock error codes are all above 10000, so your proposed fix should work. Furthermore, 'curl' does this in its strerror.c A bit of background: Revision 7196 extended the values for errno to add the missing errno status codes as required by the basis' networking support. It defined these in terms of the winsock codes if there was not an existing errno code defined. There's a big table that maps the winsock errors to their closest POSIX analogue called MLton_fixSocketErrno. With regards to your fix: It seems safe to assume existing errno codes (< sys_nerr) have a matching result in strerror The added errno codes in mingw.h are defined in terms of WSAERR<X>, so FormatError will work (and they all have values over 10000) Thus, your solution should be correct (though _strerror is the wrong method). There is another problem with using a mixture of strerror and FormatError, though. strerror always returns English. FormatMessage uses the user's locale. Also, the FormatMessage error strings in both english and german are absurd. EADDRINUSE isn't "Address in use", but something like "Normally a network resource (address/port/protocol) can only be used once at the same time." ... curl wrote a big lookup table with the usual posix error strings. I'm considering doing the same.