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};
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)
#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)
/** 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);
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);
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 */
hProcess = pi.hProcess;
} else {
pid = -1;
- WIN32_maperror(GetLastError());
- x = errno;
+ x = GetLastError();
}
dup2(t1, 0);