Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

strerror with MinGW-w64

Take this simple program

#include <stdio.h>
#include <string.h>
#include <errno.h>

int
main (void)
{
  printf ("ERROR %d %s\n", ETIMEDOUT, strerror (ETIMEDOUT));
  return 0;
}

If you compile it with Cygwin gcc it runs fine

$ gcc a.c

$ ./a
ERROR 116 Connection timed out

If you compile it with MinGW-w64 gcc it does not give proper error message

$ i686-w64-mingw32-gcc a.c

$ ./a
ERROR 138 Unknown error

How can I get MinGW-w64 to put correct error message?

like image 382
Zombo Avatar asked Nov 23 '12 05:11

Zombo


1 Answers

ETIMEDOUT seems to be a POSIX extension to the ISO C standard errno.h. Cygwin has better support for POSIX than MinGW. A bug report about ETIMEDOUT for mingw32 was opened and closed in 2007.

One option is to use the GNU Portability Library (Gnulib). It provides a POSIX-like errno.h and strerror()/strerror_override() .

like image 197
David L. Avatar answered Sep 20 '22 06:09

David L.