1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
/*
* Copyright (C) 1996-2025 The Squid Software Foundation and contributors
*
* Squid software is distributed under GPLv2+ license and includes
* contributions from numerous individuals and organizations.
* Please see the COPYING and CONTRIBUTORS files for details.
*/
#include "squid.h"
#include "compat/xstrerror.h"
#include <cstring>
#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()
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)
errmsg = "Unknown error";
snprintf(xstrerror_buf, BUFSIZ, "(%d) %s", error, errmsg);
return xstrerror_buf;
}
|