]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Windows: merge WIN32_strerror() and wsastrerror() into xstrerr()
authorAmos Jeffries <squid3@treenet.co.nz>
Sun, 7 Aug 2011 09:29:11 +0000 (21:29 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 7 Aug 2011 09:29:11 +0000 (21:29 +1200)
compat/mswin.cc
compat/xstrerror.cc
compat/xstrerror.h
include/util.h
src/ipc_win32.cc

index 7538299ea7506ab4f7a7c5d57d0524d446bc1fb8..f5b3c5f29c822e17f390b045c3b49f758f8d6979 100644 (file)
@@ -284,212 +284,6 @@ WIN32_truncate(const char *pathname, off_t length)
     return res;
 }
 
-static struct _wsaerrtext {
-    int err;
-    const char *errconst;
-    const char *errdesc;
-} _wsaerrtext[] = {
-
-    {
-        WSA_E_CANCELLED, "WSA_E_CANCELLED", "Lookup cancelled."
-    },
-    {
-        WSA_E_NO_MORE, "WSA_E_NO_MORE", "No more data available."
-    },
-    {
-        WSAEACCES, "WSAEACCES", "Permission denied."
-    },
-    {
-        WSAEADDRINUSE, "WSAEADDRINUSE", "Address already in use."
-    },
-    {
-        WSAEADDRNOTAVAIL, "WSAEADDRNOTAVAIL", "Cannot assign requested address."
-    },
-    {
-        WSAEAFNOSUPPORT, "WSAEAFNOSUPPORT", "Address family not supported by protocol family."
-    },
-    {
-        WSAEALREADY, "WSAEALREADY", "Operation already in progress."
-    },
-    {
-        WSAEBADF, "WSAEBADF", "Bad file number."
-    },
-    {
-        WSAECANCELLED, "WSAECANCELLED", "Operation cancelled."
-    },
-    {
-        WSAECONNABORTED, "WSAECONNABORTED", "Software caused connection abort."
-    },
-    {
-        WSAECONNREFUSED, "WSAECONNREFUSED", "Connection refused."
-    },
-    {
-        WSAECONNRESET, "WSAECONNRESET", "Connection reset by peer."
-    },
-    {
-        WSAEDESTADDRREQ, "WSAEDESTADDRREQ", "Destination address required."
-    },
-    {
-        WSAEDQUOT, "WSAEDQUOT", "Disk quota exceeded."
-    },
-    {
-        WSAEFAULT, "WSAEFAULT", "Bad address."
-    },
-    {
-        WSAEHOSTDOWN, "WSAEHOSTDOWN", "Host is down."
-    },
-    {
-        WSAEHOSTUNREACH, "WSAEHOSTUNREACH", "No route to host."
-    },
-    {
-        WSAEINPROGRESS, "WSAEINPROGRESS", "Operation now in progress."
-    },
-    {
-        WSAEINTR, "WSAEINTR", "Interrupted function call."
-    },
-    {
-        WSAEINVAL, "WSAEINVAL", "Invalid argument."
-    },
-    {
-        WSAEINVALIDPROCTABLE, "WSAEINVALIDPROCTABLE", "Invalid procedure table from service provider."
-    },
-    {
-        WSAEINVALIDPROVIDER, "WSAEINVALIDPROVIDER", "Invalid service provider version number."
-    },
-    {
-        WSAEISCONN, "WSAEISCONN", "Socket is already connected."
-    },
-    {
-        WSAELOOP, "WSAELOOP", "Too many levels of symbolic links."
-    },
-    {
-        WSAEMFILE, "WSAEMFILE", "Too many open files."
-    },
-    {
-        WSAEMSGSIZE, "WSAEMSGSIZE", "Message too long."
-    },
-    {
-        WSAENAMETOOLONG, "WSAENAMETOOLONG", "File name is too long."
-    },
-    {
-        WSAENETDOWN, "WSAENETDOWN", "Network is down."
-    },
-    {
-        WSAENETRESET, "WSAENETRESET", "Network dropped connection on reset."
-    },
-    {
-        WSAENETUNREACH, "WSAENETUNREACH", "Network is unreachable."
-    },
-    {
-        WSAENOBUFS, "WSAENOBUFS", "No buffer space available."
-    },
-    {
-        WSAENOMORE, "WSAENOMORE", "No more data available."
-    },
-    {
-        WSAENOPROTOOPT, "WSAENOPROTOOPT", "Bad protocol option."
-    },
-    {
-        WSAENOTCONN, "WSAENOTCONN", "Socket is not connected."
-    },
-    {
-        WSAENOTEMPTY, "WSAENOTEMPTY", "Directory is not empty."
-    },
-    {
-        WSAENOTSOCK, "WSAENOTSOCK", "Socket operation on nonsocket."
-    },
-    {
-        WSAEOPNOTSUPP, "WSAEOPNOTSUPP", "Operation not supported."
-    },
-    {
-        WSAEPFNOSUPPORT, "WSAEPFNOSUPPORT", "Protocol family not supported."
-    },
-    {
-        WSAEPROCLIM, "WSAEPROCLIM", "Too many processes."
-    },
-    {
-        WSAEPROTONOSUPPORT, "WSAEPROTONOSUPPORT", "Protocol not supported."
-    },
-    {
-        WSAEPROTOTYPE, "WSAEPROTOTYPE", "Protocol wrong type for socket."
-    },
-    {
-        WSAEPROVIDERFAILEDINIT, "WSAEPROVIDERFAILEDINIT", "Unable to initialise a service provider."
-    },
-    {
-        WSAEREFUSED, "WSAEREFUSED", "Refused."
-    },
-    {
-        WSAEREMOTE, "WSAEREMOTE", "Too many levels of remote in path."
-    },
-    {
-        WSAESHUTDOWN, "WSAESHUTDOWN", "Cannot send after socket shutdown."
-    },
-    {
-        WSAESOCKTNOSUPPORT, "WSAESOCKTNOSUPPORT", "Socket type not supported."
-    },
-    {
-        WSAESTALE, "WSAESTALE", "Stale NFS file handle."
-    },
-    {
-        WSAETIMEDOUT, "WSAETIMEDOUT", "Connection timed out."
-    },
-    {
-        WSAETOOMANYREFS, "WSAETOOMANYREFS", "Too many references."
-    },
-    {
-        WSAEUSERS, "WSAEUSERS", "Too many users."
-    },
-    {
-        WSAEWOULDBLOCK, "WSAEWOULDBLOCK", "Resource temporarily unavailable."
-    },
-    {
-        WSANOTINITIALISED, "WSANOTINITIALISED", "Successful WSAStartup not yet performed."
-    },
-    {
-        WSASERVICE_NOT_FOUND, "WSASERVICE_NOT_FOUND", "Service not found."
-    },
-    {
-        WSASYSCALLFAILURE, "WSASYSCALLFAILURE", "System call failure."
-    },
-    {
-        WSASYSNOTREADY, "WSASYSNOTREADY", "Network subsystem is unavailable."
-    },
-    {
-        WSATYPE_NOT_FOUND, "WSATYPE_NOT_FOUND", "Class type not found."
-    },
-    {
-        WSAVERNOTSUPPORTED, "WSAVERNOTSUPPORTED", "Winsock.dll version out of range."
-    },
-    {
-        WSAEDISCON, "WSAEDISCON", "Graceful shutdown in progress."
-    }
-};
-
-/*
- * wsastrerror() - description of WSAGetLastError()
- */
-const char *
-wsastrerror(int err)
-{
-    static char xwsaerror_buf[BUFSIZ];
-    int i, errind = -1;
-
-    if (err == 0)
-        return "(0) No error.";
-    for (i = 0; i < sizeof(_wsaerrtext) / sizeof(struct _wsaerrtext); i++) {
-        if (_wsaerrtext[i].err != err)
-            continue;
-        errind = i;
-        break;
-    }
-    if (errind == -1)
-        snprintf(xwsaerror_buf, BUFSIZ, "Unknown");
-    else
-        snprintf(xwsaerror_buf, BUFSIZ, "%s, %s", _wsaerrtext[errind].errconst, _wsaerrtext[errind].errdesc);
-    return xwsaerror_buf;
-}
-
 struct passwd *
 getpwnam(char *unused) {
     static struct passwd pwd = {NULL, NULL, 100, 100, NULL, NULL, NULL};
@@ -502,21 +296,6 @@ getgrnam(char *unused) {
     return &grp;
 }
 
-/*
- * WIN32_strerror with argument for late notification */
-
-const char *
-WIN32_strerror(int err)
-{
-    static char xbstrerror_buf[BUFSIZ];
-
-    if (err < 0 || err >= sys_nerr)
-        strncpy(xbstrerror_buf, wsastrerror(err), BUFSIZ);
-    else
-        strncpy(xbstrerror_buf, strerror(err), BUFSIZ);
-    return xbstrerror_buf;
-}
-
 #if defined(__MINGW32__)       /* MinGW environment */
 int
 _free_osfhnd(int filehandle)
index 0cf722d1e3c0f63f57486570a529d83f561b87a7..eae455adcdbeaa92cc1251dd60b5497cab460dd3 100644 (file)
@@ -5,10 +5,95 @@
 #include <string.h>
 #endif
 
+#if _SQUID_WINDOWS_
+static struct _wsaerrtext {
+    int err;
+    const char *errconst;
+    const char *errdesc;
+} _wsaerrtext[] = {
+
+    { WSA_E_CANCELLED, "WSA_E_CANCELLED", "Lookup cancelled." },
+    { WSA_E_NO_MORE, "WSA_E_NO_MORE", "No more data available." },
+    { WSAEACCES, "WSAEACCES", "Permission denied." },
+    { WSAEADDRINUSE, "WSAEADDRINUSE", "Address already in use." },
+    { WSAEADDRNOTAVAIL, "WSAEADDRNOTAVAIL", "Cannot assign requested address." },
+    { WSAEAFNOSUPPORT, "WSAEAFNOSUPPORT", "Address family not supported by protocol family." },
+    { WSAEALREADY, "WSAEALREADY", "Operation already in progress." },
+    { WSAEBADF, "WSAEBADF", "Bad file number." },
+    { WSAECANCELLED, "WSAECANCELLED", "Operation cancelled." },
+    { WSAECONNABORTED, "WSAECONNABORTED", "Software caused connection abort." },
+    { WSAECONNREFUSED, "WSAECONNREFUSED", "Connection refused." },
+    { WSAECONNRESET, "WSAECONNRESET", "Connection reset by peer." },
+    { WSAEDESTADDRREQ, "WSAEDESTADDRREQ", "Destination address required." },
+    { WSAEDQUOT, "WSAEDQUOT", "Disk quota exceeded." },
+    { WSAEFAULT, "WSAEFAULT", "Bad address." },
+    { WSAEHOSTDOWN, "WSAEHOSTDOWN", "Host is down." },
+    { WSAEHOSTUNREACH, "WSAEHOSTUNREACH", "No route to host." },
+    { WSAEINPROGRESS, "WSAEINPROGRESS", "Operation now in progress." },
+    { WSAEINTR, "WSAEINTR", "Interrupted function call." },
+    { WSAEINVAL, "WSAEINVAL", "Invalid argument." },
+    { WSAEINVALIDPROCTABLE, "WSAEINVALIDPROCTABLE", "Invalid procedure table from service provider." },
+    { WSAEINVALIDPROVIDER, "WSAEINVALIDPROVIDER", "Invalid service provider version number." },
+    { WSAEISCONN, "WSAEISCONN", "Socket is already connected." },
+    { WSAELOOP, "WSAELOOP", "Too many levels of symbolic links." },
+    { WSAEMFILE, "WSAEMFILE", "Too many open files." },
+    { WSAEMSGSIZE, "WSAEMSGSIZE", "Message too long." },
+    { WSAENAMETOOLONG, "WSAENAMETOOLONG", "File name is too long." },
+    { WSAENETDOWN, "WSAENETDOWN", "Network is down." },
+    { WSAENETRESET, "WSAENETRESET", "Network dropped connection on reset." },
+    { WSAENETUNREACH, "WSAENETUNREACH", "Network is unreachable." },
+    { WSAENOBUFS, "WSAENOBUFS", "No buffer space available." },
+    { WSAENOMORE, "WSAENOMORE", "No more data available." },
+    { WSAENOPROTOOPT, "WSAENOPROTOOPT", "Bad protocol option." },
+    { WSAENOTCONN, "WSAENOTCONN", "Socket is not connected." },
+    { WSAENOTEMPTY, "WSAENOTEMPTY", "Directory is not empty." },
+    { WSAENOTSOCK, "WSAENOTSOCK", "Socket operation on nonsocket." },
+    { WSAEOPNOTSUPP, "WSAEOPNOTSUPP", "Operation not supported." },
+    { WSAEPFNOSUPPORT, "WSAEPFNOSUPPORT", "Protocol family not supported." },
+    { WSAEPROCLIM, "WSAEPROCLIM", "Too many processes." },
+    { WSAEPROTONOSUPPORT, "WSAEPROTONOSUPPORT", "Protocol not supported." },
+    { WSAEPROTOTYPE, "WSAEPROTOTYPE", "Protocol wrong type for socket." },
+    { WSAEPROVIDERFAILEDINIT, "WSAEPROVIDERFAILEDINIT", "Unable to initialise a service provider." },
+    { WSAEREFUSED, "WSAEREFUSED", "Refused." },
+    { WSAEREMOTE, "WSAEREMOTE", "Too many levels of remote in path." },
+    { WSAESHUTDOWN, "WSAESHUTDOWN", "Cannot send after socket shutdown." },
+    { WSAESOCKTNOSUPPORT, "WSAESOCKTNOSUPPORT", "Socket type not supported." },
+    { WSAESTALE, "WSAESTALE", "Stale NFS file handle." },
+    { WSAETIMEDOUT, "WSAETIMEDOUT", "Connection timed out." },
+    { WSAETOOMANYREFS, "WSAETOOMANYREFS", "Too many references." },
+    { WSAEUSERS, "WSAEUSERS", "Too many users." },
+    { WSAEWOULDBLOCK, "WSAEWOULDBLOCK", "Resource temporarily unavailable." },
+    { WSANOTINITIALISED, "WSANOTINITIALISED", "Successful WSAStartup not yet performed." },
+    { WSASERVICE_NOT_FOUND, "WSASERVICE_NOT_FOUND", "Service not found." },
+    { WSASYSCALLFAILURE, "WSASYSCALLFAILURE", "System call failure." },
+    { WSASYSNOTREADY, "WSASYSNOTREADY", "Network subsystem is unavailable." },
+    { WSATYPE_NOT_FOUND, "WSATYPE_NOT_FOUND", "Class type not found." },
+    { WSAVERNOTSUPPORTED, "WSAVERNOTSUPPORTED", "Winsock.dll version out of range." },
+    { WSAEDISCON, "WSAEDISCON", "Graceful shutdown in progress."    }
+};
+#endif
+
 const char *
 xstrerr(int error)
 {
     static char xstrerror_buf[BUFSIZ];
+
+    if (error == 0)
+        return "(0) No error.";
+
+#if _SQUID_WINDOWS_
+    // Description of WSAGetLastError()
+    if (error < 0 || error >= sys_nerr) {
+        for (size_t i = 0;i < sizeof(_wsaerrtext) / sizeof(struct _wsaerrtext); i++) {
+            if (_wsaerrtext[i].err == error) {
+                // small optimization, save using a temporary buffer and two copies...
+                snprintf(xstrerror_buf, BUFSIZ, "(%d) %s, %s", error, _wsaerrtext[i].errconst, _wsaerrtext[i].errdesc);
+                return xstrerror_buf;
+            }
+        }
+    }
+#endif
+
     const char *errmsg = strerror(error);
 
     if (!errmsg || !*errmsg)
index 8a55f166cb3dab692e3e25d805e31aa9555d7ff6..69fa439e88f8f2ea62029274582c9fa850e7587d 100644 (file)
@@ -10,6 +10,7 @@
 
 /** Provide the textual display of a system error number.
  * A string is always returned.
+ * On MS Windows the native Win32 errors are also translated.
  */
 extern const char * xstrerr(int error);
 
index d797d31b3b8e3356db7c5cae57d174d4dd83294e..18e62e7d40428e850a02d5af998ce16583cbbb53 100644 (file)
@@ -124,7 +124,6 @@ SQUIDCEXTERN int gettimeofday(struct timeval * ,void *);
 SQUIDCEXTERN int kill(pid_t, int);
 SQUIDCEXTERN int statfs(const char *, struct statfs *);
 SQUIDCEXTERN int truncate(const char *, off_t);
-SQUIDCEXTERN const char * wsastrerror(int);
 SQUIDCEXTERN struct passwd *getpwnam(char *);
 SQUIDCEXTERN struct group *getgrnam(char *);
 SQUIDCEXTERN uid_t geteuid(void);
@@ -135,7 +134,6 @@ SQUIDCEXTERN gid_t getgid(void);
 SQUIDCEXTERN gid_t getegid(void);
 SQUIDCEXTERN int setgid(gid_t);
 SQUIDCEXTERN int setegid(gid_t);
-SQUIDCEXTERN const char *WIN32_strerror(int);
 SQUIDCEXTERN void WIN32_maperror(unsigned long);
 #endif
 #endif /* SQUID_UTIL_H */
index c16bee9470735eac1885ecad894264d67a02524d..4665d7ffa73ad1e9eb3dba96b19a8fa6c335333c 100644 (file)
@@ -576,8 +576,7 @@ ipc_thread_1(void *in_params)
         hProcess = pi.hProcess;
     } else {
         pid = -1;
-        WIN32_maperror(GetLastError());
-        x = errno;
+        x = GetLastError();
     }
 
     dup2(t1, 0);