This patch tweaks the mapping of error codes in the errno module and in
winsock.c, so that under mingw EWOULDBLOCK is not different from EAGAIN.
 It was inspired by the flock patch.

Ok?

Paolo

2008-10-03  Paolo Bonzini  <[EMAIL PROTECTED]>

        * lib/strerror.c: Return an error string for WSAEWOULDBLOCK,
        not EWOULDBLOCK.
        * lib/winsock.c (set_winsock_errno): Map WSAEWOULDBLOCK
        to EAGAIN.
        * lib/errno.in.h (EWOULDBLOCK) [win32]: Define to EAGAIN.

diff --git a/lib/errno.in.h b/lib/errno.in.h
index 7ffa203..a3a2a03 100644
--- a/lib/errno.in.h
+++ b/lib/errno.in.h
@@ -26,17 +26,20 @@
 #ifndef _GL_ERRNO_H
 #define _GL_ERRNO_H

-
 /* On native Windows platforms, many macros are not defined.  */
 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__

+# ifndef EWOULDBLOCK
+#  define EWOULDBLOCK     EAGAIN
+# endif
+
 /* Values >= 100 seem safe to use.  */
 #  define ETXTBSY   100
 #  define GNULIB_defined_ETXTBSY 1

 /* These are intentionally the same values as the WSA* error numbers,
defined
-   in <winsock2.h>.  */
-#  define EWOULDBLOCK     10035
+   in <winsock2.h>.  winsock.c maps WSAEWOULDBLOCK to EAGAIN to preserve
+   EAGAIN == EWOULDBLOCK.  */
 #  define EINPROGRESS     10036
 #  define EALREADY        10037
 #  define ENOTSOCK        10038
diff --git a/lib/strerror.c b/lib/strerror.c
index 2393c67..38e6ad1 100644
--- a/lib/strerror.c
+++ b/lib/strerror.c
@@ -49,8 +49,6 @@ rpl_strerror (int n)
 # endif

 # if GNULIB_defined_ESOCK /* native Windows platforms */
-    case EWOULDBLOCK:
-      return "Operation would block";
     case EINPROGRESS:
       return "Operation now in progress";
     case EALREADY:
@@ -135,7 +133,6 @@ rpl_strerror (int n)
     /* WSAEFAULT maps to EFAULT */
     /* WSAEINVAL maps to EINVAL */
     /* WSAEMFILE maos to EMFILE */
-    /* WSAEWOULDBLOCK is EWOULDBLOCK */
     /* WSAEINPROGRESS is EINPROGRESS */
     /* WSAEALREADY is EALREADY */
     /* WSAENOTSOCK is ENOTSOCK */
@@ -172,6 +169,8 @@ rpl_strerror (int n)
     /* WSAEDQUOT is EDQUOT */
     /* WSAESTALE is ESTALE */
     /* WSAEREMOTE is EREMOTE */
+    case WSAEWOULDBLOCK:
+      return "Operation would block";
     case WSASYSNOTREADY:
       return "Network subsystem is unavailable";
     case WSAVERNOTSUPPORTED:
diff --git a/lib/winsock.c b/lib/winsock.c
index 535145a..15affa7 100644
--- a/lib/winsock.c
+++ b/lib/winsock.c
@@ -91,6 +91,9 @@ set_winsock_errno (void)
     case WSA_INVALID_PARAMETER:
       errno = EINVAL;
       break;
+    case WSAEWOULDBLOCK:
+      errno = EAGAIN;
+      break;
     case WSAENAMETOOLONG:
       errno = ENAMETOOLONG;
       break;



Reply via email to