bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Redefinition of errno constants in MSVC10


From: Bruno Haible
Subject: Re: Redefinition of errno constants in MSVC10
Date: Sat, 22 Oct 2011 16:28:03 +0200
User-agent: KMail/1.13.6 (Linux/2.6.37.6-0.5-desktop; KDE/4.6.0; x86_64; ; )

Hi,

Michael Goffioul wrote:
> When trying to compile current octave with MSVC10, I get a bunch of
> macro redefinition in errno.h module. See the following from the
> involved headers:
> 
> $ grep ECONNRESET errno.h
> #  define ECONNRESET      10054
> 
> $ grep ECONNRESET /c/Program\ Files/Microsoft\ Visual\ Studio\
> 10.0/VC/include/errno.h
> #define ECONNRESET      108

MSVC 10 has introduced a number of errno values that were not present in
MSVC 9. I'm updating gnulib's errno module to use these values, such as
to maximize interoperability between code compiled with mingw / MSVC 9
and gnulib and code compiled with MSVC 10.

I haven't tested this with MSVC 10, only with mingw and MSVC 9.


2011-10-22  Bruno Haible  <address@hidden>

        errno, strerror-override: Support for MSVC 10.
        * lib/errno.in.h (GNULIB_defined_ETXTBSY): Remove macro.
        (ENOMSG, EIDRM, ENOLINK, EPROTO, EBADMSG, EOVERFLOW, ENOTSUP,
        ENETRESET, ECONNABORTED, ECANCELED, EINPROGRESS, EALREADY, ENOTSOCK,
        EDESTADDRREQ, EMSGSIZE, EPROTOTYPE, ENOPROTOOPT, EPROTONOSUPPORT,
        EOPNOTSUPP, EAFNOSUPPORT, EADDRINUSE, EADDRNOTAVAIL, ENETDOWN,
        ENETUNREACH, ECONNRESET, ENOBUFS, EISCONN, ENOTCONN, ETIMEDOUT,
        ECONNREFUSED, ELOOP, EHOSTUNREACH, EWOULDBLOCK, ETXTBSY) [Win32]:
        Assign values compatible with MSVC 10.
        (ENODATA, ENOSR, ENOSTR, ENOTRECOVERABLE, EOWNERDEAD, ETIME, EOTHER):
        New macros.
        (GNULIB_defined_EWINSOCK): New macro.
        * lib/strerror-override.c (strerror_override): Update accordingly.
        * lib/strerror-override.h: Likewise.
        * lib/w32sock.h (set_winsock_errno): Map those WSA* values that are no
        longer equal to the corresponding errno value.
        Reported by Michael Goffioul <address@hidden>.

--- lib/errno.in.h.orig Sat Oct 22 16:15:09 2011
+++ lib/errno.in.h      Sat Oct 22 15:51:54 2011
@@ -33,50 +33,106 @@
 /* On native Windows platforms, many macros are not defined.  */
 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
 
-/* POSIX says that EAGAIN and EWOULDBLOCK may have the same value.  */
-#  define EWOULDBLOCK     EAGAIN
+/* These are the same values as defined by MSVC 10, for interoperability.  */
 
-/* Values >= 100 seem safe to use.  */
-#  define ETXTBSY   100
-#  define GNULIB_defined_ETXTBSY 1
+#  ifndef ENOMSG
+#   define ENOMSG    122
+#   define GNULIB_defined_ENOMSG 1
+#  endif
+
+#  ifndef EIDRM
+#   define EIDRM     111
+#   define GNULIB_defined_EIDRM 1
+#  endif
+
+#  ifndef ENOLINK
+#   define ENOLINK   121
+#   define GNULIB_defined_ENOLINK 1
+#  endif
+
+#  ifndef EPROTO
+#   define EPROTO    134
+#   define GNULIB_defined_EPROTO 1
+#  endif
+
+#  ifndef EBADMSG
+#   define EBADMSG   104
+#   define GNULIB_defined_EBADMSG 1
+#  endif
+
+#  ifndef EOVERFLOW
+#   define EOVERFLOW 132
+#   define GNULIB_defined_EOVERFLOW 1
+#  endif
+
+#  ifndef ENOTSUP
+#   define ENOTSUP   129
+#   define GNULIB_defined_ENOTSUP 1
+#  endif
+
+#  ifndef ENETRESET
+#   define ENETRESET 117
+#   define GNULIB_defined_ENETRESET 1
+#  endif
+
+#  ifndef ECONNABORTED
+#   define ECONNABORTED 106
+#   define GNULIB_defined_ECONNABORTED 1
+#  endif
+
+#  ifndef ECANCELED
+#   define ECANCELED 105
+#   define GNULIB_defined_ECANCELED 1
+#  endif
+
+#  ifndef EINPROGRESS
+#   define EINPROGRESS     112
+#   define EALREADY        103
+#   define ENOTSOCK        128
+#   define EDESTADDRREQ    109
+#   define EMSGSIZE        115
+#   define EPROTOTYPE      136
+#   define ENOPROTOOPT     123
+#   define EPROTONOSUPPORT 135
+#   define EOPNOTSUPP      130
+#   define EAFNOSUPPORT    102
+#   define EADDRINUSE      100
+#   define EADDRNOTAVAIL   101
+#   define ENETDOWN        116
+#   define ENETUNREACH     118
+#   define ECONNRESET      108
+#   define ENOBUFS         119
+#   define EISCONN         113
+#   define ENOTCONN        126
+#   define ETIMEDOUT       138
+#   define ECONNREFUSED    107
+#   define ELOOP           114
+#   define EHOSTUNREACH    110
+#   define EWOULDBLOCK     140
+#   define ETXTBSY         139
+#   define ENODATA         120  /* not required by POSIX */
+#   define ENOSR           124  /* not required by POSIX */
+#   define ENOSTR          125  /* not required by POSIX */
+#   define ENOTRECOVERABLE 127  /* not required by POSIX */
+#   define EOWNERDEAD      133  /* not required by POSIX */
+#   define ETIME           137  /* not required by POSIX */
+#   define EOTHER          131  /* not required by POSIX */
+#   define GNULIB_defined_ESOCK 1
+#  endif
 
 /* These are intentionally the same values as the WSA* error numbers, defined
    in <winsock2.h>.  */
-#  define EINPROGRESS     10036
-#  define EALREADY        10037
-#  define ENOTSOCK        10038
-#  define EDESTADDRREQ    10039
-#  define EMSGSIZE        10040
-#  define EPROTOTYPE      10041
-#  define ENOPROTOOPT     10042
-#  define EPROTONOSUPPORT 10043
 #  define ESOCKTNOSUPPORT 10044  /* not required by POSIX */
-#  define EOPNOTSUPP      10045
 #  define EPFNOSUPPORT    10046  /* not required by POSIX */
-#  define EAFNOSUPPORT    10047
-#  define EADDRINUSE      10048
-#  define EADDRNOTAVAIL   10049
-#  define ENETDOWN        10050
-#  define ENETUNREACH     10051
-#  define ENETRESET       10052
-#  define ECONNABORTED    10053
-#  define ECONNRESET      10054
-#  define ENOBUFS         10055
-#  define EISCONN         10056
-#  define ENOTCONN        10057
 #  define ESHUTDOWN       10058  /* not required by POSIX */
 #  define ETOOMANYREFS    10059  /* not required by POSIX */
-#  define ETIMEDOUT       10060
-#  define ECONNREFUSED    10061
-#  define ELOOP           10062
 #  define EHOSTDOWN       10064  /* not required by POSIX */
-#  define EHOSTUNREACH    10065
 #  define EPROCLIM        10067  /* not required by POSIX */
 #  define EUSERS          10068  /* not required by POSIX */
 #  define EDQUOT          10069
 #  define ESTALE          10070
 #  define EREMOTE         10071  /* not required by POSIX */
-#  define GNULIB_defined_ESOCK 1
+#  define GNULIB_defined_EWINSOCK 1
 
 # endif
 
--- lib/strerror-override.c.orig        Sat Oct 22 16:15:09 2011
+++ lib/strerror-override.c     Sat Oct 22 16:11:51 2011
@@ -23,7 +23,7 @@
 
 #include <errno.h>
 
-#if GNULIB_defined_ESOCK /* native Windows platforms */
+#if GNULIB_defined_EWINSOCK /* native Windows platforms */
 # if HAVE_WINSOCK2_H
 #  include <winsock2.h>
 # endif
@@ -42,13 +42,7 @@
       return "Success";
 #endif
 
-#if GNULIB_defined_ETXTBSY
-    case ETXTBSY:
-      return "Text file busy";
-#endif
-
-#if GNULIB_defined_ESOCK /* native Windows platforms */
-      /* EWOULDBLOCK is the same as EAGAIN.  */
+#if GNULIB_defined_ESOCK /* native Windows platforms with older <errno.h> */
     case EINPROGRESS:
       return "Operation now in progress";
     case EALREADY:
@@ -65,12 +59,8 @@
       return "Protocol not available";
     case EPROTONOSUPPORT:
       return "Protocol not supported";
-    case ESOCKTNOSUPPORT:
-      return "Socket type not supported";
     case EOPNOTSUPP:
       return "Operation not supported";
-    case EPFNOSUPPORT:
-      return "Protocol family not supported";
     case EAFNOSUPPORT:
       return "Address family not supported by protocol";
     case EADDRINUSE:
@@ -81,10 +71,6 @@
       return "Network is down";
     case ENETUNREACH:
       return "Network is unreachable";
-    case ENETRESET:
-      return "Network dropped connection on reset";
-    case ECONNABORTED:
-      return "Software caused connection abort";
     case ECONNRESET:
       return "Connection reset by peer";
     case ENOBUFS:
@@ -93,20 +79,44 @@
       return "Transport endpoint is already connected";
     case ENOTCONN:
       return "Transport endpoint is not connected";
-    case ESHUTDOWN:
-      return "Cannot send after transport endpoint shutdown";
-    case ETOOMANYREFS:
-      return "Too many references: cannot splice";
     case ETIMEDOUT:
       return "Connection timed out";
     case ECONNREFUSED:
       return "Connection refused";
     case ELOOP:
       return "Too many levels of symbolic links";
-    case EHOSTDOWN:
-      return "Host is down";
     case EHOSTUNREACH:
       return "No route to host";
+    case EWOULDBLOCK:
+      return "Operation would block";
+    case ETXTBSY:
+      return "Text file busy";
+    case ENODATA:
+      return "No data available";
+    case ENOSR:
+      return "Out of streams resources";
+    case ENOSTR:
+      return "Device not a stream";
+    case ENOTRECOVERABLE:
+      return "State not recoverable";
+    case EOWNERDEAD:
+      return "Owner died";
+    case ETIME:
+      return "Timer expired";
+    case EOTHER:
+      return "Other error";
+#endif
+#if GNULIB_defined_EWINSOCK /* native Windows platforms */
+    case ESOCKTNOSUPPORT:
+      return "Socket type not supported";
+    case EPFNOSUPPORT:
+      return "Protocol family not supported";
+    case ESHUTDOWN:
+      return "Cannot send after transport endpoint shutdown";
+    case ETOOMANYREFS:
+      return "Too many references: cannot splice";
+    case EHOSTDOWN:
+      return "Host is down";
     case EPROCLIM:
       return "Too many processes";
     case EUSERS:
@@ -134,36 +144,36 @@
       /* WSAEINVAL maps to EINVAL */
       /* WSAEMFILE maps to EMFILE */
       /* WSAEWOULDBLOCK maps to EWOULDBLOCK */
-      /* WSAEINPROGRESS is EINPROGRESS */
-      /* WSAEALREADY is EALREADY */
-      /* WSAENOTSOCK is ENOTSOCK */
-      /* WSAEDESTADDRREQ is EDESTADDRREQ */
-      /* WSAEMSGSIZE is EMSGSIZE */
-      /* WSAEPROTOTYPE is EPROTOTYPE */
-      /* WSAENOPROTOOPT is ENOPROTOOPT */
-      /* WSAEPROTONOSUPPORT is EPROTONOSUPPORT */
+      /* WSAEINPROGRESS maps to EINPROGRESS */
+      /* WSAEALREADY maps to EALREADY */
+      /* WSAENOTSOCK maps to ENOTSOCK */
+      /* WSAEDESTADDRREQ maps to EDESTADDRREQ */
+      /* WSAEMSGSIZE maps to EMSGSIZE */
+      /* WSAEPROTOTYPE maps to EPROTOTYPE */
+      /* WSAENOPROTOOPT maps to ENOPROTOOPT */
+      /* WSAEPROTONOSUPPORT maps to EPROTONOSUPPORT */
       /* WSAESOCKTNOSUPPORT is ESOCKTNOSUPPORT */
-      /* WSAEOPNOTSUPP is EOPNOTSUPP */
+      /* WSAEOPNOTSUPP maps to EOPNOTSUPP */
       /* WSAEPFNOSUPPORT is EPFNOSUPPORT */
-      /* WSAEAFNOSUPPORT is EAFNOSUPPORT */
-      /* WSAEADDRINUSE is EADDRINUSE */
-      /* WSAEADDRNOTAVAIL is EADDRNOTAVAIL */
-      /* WSAENETDOWN is ENETDOWN */
-      /* WSAENETUNREACH is ENETUNREACH */
-      /* WSAENETRESET is ENETRESET */
-      /* WSAECONNABORTED is ECONNABORTED */
-      /* WSAECONNRESET is ECONNRESET */
-      /* WSAENOBUFS is ENOBUFS */
-      /* WSAEISCONN is EISCONN */
-      /* WSAENOTCONN is ENOTCONN */
+      /* WSAEAFNOSUPPORT maps to EAFNOSUPPORT */
+      /* WSAEADDRINUSE maps to EADDRINUSE */
+      /* WSAEADDRNOTAVAIL maps to EADDRNOTAVAIL */
+      /* WSAENETDOWN maps to ENETDOWN */
+      /* WSAENETUNREACH maps to ENETUNREACH */
+      /* WSAENETRESET maps to ENETRESET */
+      /* WSAECONNABORTED maps to ECONNABORTED */
+      /* WSAECONNRESET maps to ECONNRESET */
+      /* WSAENOBUFS maps to ENOBUFS */
+      /* WSAEISCONN maps to EISCONN */
+      /* WSAENOTCONN maps to ENOTCONN */
       /* WSAESHUTDOWN is ESHUTDOWN */
       /* WSAETOOMANYREFS is ETOOMANYREFS */
-      /* WSAETIMEDOUT is ETIMEDOUT */
-      /* WSAECONNREFUSED is ECONNREFUSED */
-      /* WSAELOOP is ELOOP */
+      /* WSAETIMEDOUT maps to ETIMEDOUT */
+      /* WSAECONNREFUSED maps to ECONNREFUSED */
+      /* WSAELOOP maps to ELOOP */
       /* WSAENAMETOOLONG maps to ENAMETOOLONG */
       /* WSAEHOSTDOWN is EHOSTDOWN */
-      /* WSAEHOSTUNREACH is EHOSTUNREACH */
+      /* WSAEHOSTUNREACH maps to EHOSTUNREACH */
       /* WSAENOTEMPTY maps to ENOTEMPTY */
       /* WSAEPROCLIM is EPROCLIM */
       /* WSAEUSERS is EUSERS */
--- lib/strerror-override.h.orig        Sat Oct 22 16:15:09 2011
+++ lib/strerror-override.h     Sat Oct 22 16:12:50 2011
@@ -29,8 +29,8 @@
 /* If ERRNUM maps to an errno value defined by gnulib, return a string
    describing the error.  Otherwise return NULL.  */
 # if REPLACE_STRERROR_0 \
-     || GNULIB_defined_ETXTBSY \
      || GNULIB_defined_ESOCK \
+     || GNULIB_defined_EWINSOCK \
      || GNULIB_defined_ENOMSG \
      || GNULIB_defined_EIDRM \
      || GNULIB_defined_ENOLINK \
--- lib/w32sock.h.orig  Sat Oct 22 16:15:09 2011
+++ lib/w32sock.h       Sat Oct 22 15:34:27 2011
@@ -48,15 +48,87 @@
     case WSA_INVALID_PARAMETER:
       errno = EINVAL;
       break;
-    case WSAEWOULDBLOCK:
-      errno = EWOULDBLOCK;
-      break;
     case WSAENAMETOOLONG:
       errno = ENAMETOOLONG;
       break;
     case WSAENOTEMPTY:
       errno = ENOTEMPTY;
       break;
+    case WSAEWOULDBLOCK:
+      errno = EWOULDBLOCK;
+      break;
+    case WSAEINPROGRESS:
+      errno = EINPROGRESS;
+      break;
+    case WSAEALREADY:
+      errno = EALREADY;
+      break;
+    case WSAENOTSOCK:
+      errno = ENOTSOCK;
+      break;
+    case WSAEDESTADDRREQ:
+      errno = EDESTADDRREQ;
+      break;
+    case WSAEMSGSIZE:
+      errno = EMSGSIZE;
+      break;
+    case WSAEPROTOTYPE:
+      errno = EPROTOTYPE;
+      break;
+    case WSAENOPROTOOPT:
+      errno = ENOPROTOOPT;
+      break;
+    case WSAEPROTONOSUPPORT:
+      errno = EPROTONOSUPPORT;
+      break;
+    case WSAEOPNOTSUPP:
+      errno = EOPNOTSUPP;
+      break;
+    case WSAEAFNOSUPPORT:
+      errno = EAFNOSUPPORT;
+      break;
+    case WSAEADDRINUSE:
+      errno = EADDRINUSE;
+      break;
+    case WSAEADDRNOTAVAIL:
+      errno = EADDRNOTAVAIL;
+      break;
+    case WSAENETDOWN:
+      errno = ENETDOWN;
+      break;
+    case WSAENETUNREACH:
+      errno = ENETUNREACH;
+      break;
+    case WSAENETRESET:
+      errno = ENETRESET;
+      break;
+    case WSAECONNABORTED:
+      errno = ECONNABORTED;
+      break;
+    case WSAECONNRESET:
+      errno = ECONNRESET;
+      break;
+    case WSAENOBUFS:
+      errno = ENOBUFS;
+      break;
+    case WSAEISCONN:
+      errno = EISCONN;
+      break;
+    case WSAENOTCONN:
+      errno = ENOTCONN;
+      break;
+    case WSAETIMEDOUT:
+      errno = ETIMEDOUT;
+      break;
+    case WSAECONNREFUSED:
+      errno = ECONNREFUSED;
+      break;
+    case WSAELOOP:
+      errno = ELOOP;
+      break;
+    case WSAEHOSTUNREACH:
+      errno = EHOSTUNREACH;
+      break;
     default:
       errno = (err > 10000 && err < 10025) ? err - 10000 : err;
       break;
-- 
In memoriam Nunilo and Alodia <http://en.wikipedia.org/wiki/Nunilo_and_Alodia>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]