]>
Commit | Line | Data |
---|---|---|
f7f3304a | 1 | #include "squid.h" |
25f98340 AJ |
2 | #include "compat/xstrerror.h" |
3 | ||
4 | #if HAVE_STRING_H | |
5 | #include <string.h> | |
6 | #endif | |
7 | ||
979f3ae6 AJ |
8 | #if _SQUID_WINDOWS_ |
9 | static struct _wsaerrtext { | |
10 | int err; | |
11 | const char *errconst; | |
12 | const char *errdesc; | |
13 | } _wsaerrtext[] = { | |
14 | ||
15 | { WSA_E_CANCELLED, "WSA_E_CANCELLED", "Lookup cancelled." }, | |
16 | { WSA_E_NO_MORE, "WSA_E_NO_MORE", "No more data available." }, | |
17 | { WSAEACCES, "WSAEACCES", "Permission denied." }, | |
18 | { WSAEADDRINUSE, "WSAEADDRINUSE", "Address already in use." }, | |
19 | { WSAEADDRNOTAVAIL, "WSAEADDRNOTAVAIL", "Cannot assign requested address." }, | |
20 | { WSAEAFNOSUPPORT, "WSAEAFNOSUPPORT", "Address family not supported by protocol family." }, | |
21 | { WSAEALREADY, "WSAEALREADY", "Operation already in progress." }, | |
22 | { WSAEBADF, "WSAEBADF", "Bad file number." }, | |
23 | { WSAECANCELLED, "WSAECANCELLED", "Operation cancelled." }, | |
24 | { WSAECONNABORTED, "WSAECONNABORTED", "Software caused connection abort." }, | |
25 | { WSAECONNREFUSED, "WSAECONNREFUSED", "Connection refused." }, | |
26 | { WSAECONNRESET, "WSAECONNRESET", "Connection reset by peer." }, | |
27 | { WSAEDESTADDRREQ, "WSAEDESTADDRREQ", "Destination address required." }, | |
28 | { WSAEDQUOT, "WSAEDQUOT", "Disk quota exceeded." }, | |
29 | { WSAEFAULT, "WSAEFAULT", "Bad address." }, | |
30 | { WSAEHOSTDOWN, "WSAEHOSTDOWN", "Host is down." }, | |
31 | { WSAEHOSTUNREACH, "WSAEHOSTUNREACH", "No route to host." }, | |
32 | { WSAEINPROGRESS, "WSAEINPROGRESS", "Operation now in progress." }, | |
33 | { WSAEINTR, "WSAEINTR", "Interrupted function call." }, | |
34 | { WSAEINVAL, "WSAEINVAL", "Invalid argument." }, | |
35 | { WSAEINVALIDPROCTABLE, "WSAEINVALIDPROCTABLE", "Invalid procedure table from service provider." }, | |
36 | { WSAEINVALIDPROVIDER, "WSAEINVALIDPROVIDER", "Invalid service provider version number." }, | |
37 | { WSAEISCONN, "WSAEISCONN", "Socket is already connected." }, | |
38 | { WSAELOOP, "WSAELOOP", "Too many levels of symbolic links." }, | |
39 | { WSAEMFILE, "WSAEMFILE", "Too many open files." }, | |
40 | { WSAEMSGSIZE, "WSAEMSGSIZE", "Message too long." }, | |
41 | { WSAENAMETOOLONG, "WSAENAMETOOLONG", "File name is too long." }, | |
42 | { WSAENETDOWN, "WSAENETDOWN", "Network is down." }, | |
43 | { WSAENETRESET, "WSAENETRESET", "Network dropped connection on reset." }, | |
44 | { WSAENETUNREACH, "WSAENETUNREACH", "Network is unreachable." }, | |
45 | { WSAENOBUFS, "WSAENOBUFS", "No buffer space available." }, | |
46 | { WSAENOMORE, "WSAENOMORE", "No more data available." }, | |
47 | { WSAENOPROTOOPT, "WSAENOPROTOOPT", "Bad protocol option." }, | |
48 | { WSAENOTCONN, "WSAENOTCONN", "Socket is not connected." }, | |
49 | { WSAENOTEMPTY, "WSAENOTEMPTY", "Directory is not empty." }, | |
50 | { WSAENOTSOCK, "WSAENOTSOCK", "Socket operation on nonsocket." }, | |
51 | { WSAEOPNOTSUPP, "WSAEOPNOTSUPP", "Operation not supported." }, | |
52 | { WSAEPFNOSUPPORT, "WSAEPFNOSUPPORT", "Protocol family not supported." }, | |
53 | { WSAEPROCLIM, "WSAEPROCLIM", "Too many processes." }, | |
54 | { WSAEPROTONOSUPPORT, "WSAEPROTONOSUPPORT", "Protocol not supported." }, | |
55 | { WSAEPROTOTYPE, "WSAEPROTOTYPE", "Protocol wrong type for socket." }, | |
56 | { WSAEPROVIDERFAILEDINIT, "WSAEPROVIDERFAILEDINIT", "Unable to initialise a service provider." }, | |
57 | { WSAEREFUSED, "WSAEREFUSED", "Refused." }, | |
58 | { WSAEREMOTE, "WSAEREMOTE", "Too many levels of remote in path." }, | |
59 | { WSAESHUTDOWN, "WSAESHUTDOWN", "Cannot send after socket shutdown." }, | |
60 | { WSAESOCKTNOSUPPORT, "WSAESOCKTNOSUPPORT", "Socket type not supported." }, | |
61 | { WSAESTALE, "WSAESTALE", "Stale NFS file handle." }, | |
62 | { WSAETIMEDOUT, "WSAETIMEDOUT", "Connection timed out." }, | |
63 | { WSAETOOMANYREFS, "WSAETOOMANYREFS", "Too many references." }, | |
64 | { WSAEUSERS, "WSAEUSERS", "Too many users." }, | |
65 | { WSAEWOULDBLOCK, "WSAEWOULDBLOCK", "Resource temporarily unavailable." }, | |
66 | { WSANOTINITIALISED, "WSANOTINITIALISED", "Successful WSAStartup not yet performed." }, | |
67 | { WSASERVICE_NOT_FOUND, "WSASERVICE_NOT_FOUND", "Service not found." }, | |
68 | { WSASYSCALLFAILURE, "WSASYSCALLFAILURE", "System call failure." }, | |
69 | { WSASYSNOTREADY, "WSASYSNOTREADY", "Network subsystem is unavailable." }, | |
70 | { WSATYPE_NOT_FOUND, "WSATYPE_NOT_FOUND", "Class type not found." }, | |
71 | { WSAVERNOTSUPPORTED, "WSAVERNOTSUPPORTED", "Winsock.dll version out of range." }, | |
72 | { WSAEDISCON, "WSAEDISCON", "Graceful shutdown in progress." } | |
73 | }; | |
74 | #endif | |
75 | ||
25f98340 AJ |
76 | const char * |
77 | xstrerr(int error) | |
78 | { | |
79 | static char xstrerror_buf[BUFSIZ]; | |
979f3ae6 AJ |
80 | |
81 | if (error == 0) | |
82 | return "(0) No error."; | |
83 | ||
84 | #if _SQUID_WINDOWS_ | |
85 | // Description of WSAGetLastError() | |
ee561c44 | 86 | for (size_t i = 0; i < sizeof(_wsaerrtext) / sizeof(struct _wsaerrtext); i++) { |
21e54359 FC |
87 | if (_wsaerrtext[i].err == error) { |
88 | // small optimization, save using a temporary buffer and two copies... | |
89 | snprintf(xstrerror_buf, BUFSIZ, "(%d) %s, %s", error, _wsaerrtext[i].errconst, _wsaerrtext[i].errdesc); | |
90 | return xstrerror_buf; | |
979f3ae6 AJ |
91 | } |
92 | } | |
93 | #endif | |
94 | ||
25f98340 AJ |
95 | const char *errmsg = strerror(error); |
96 | ||
97 | if (!errmsg || !*errmsg) | |
98 | errmsg = "Unknown error"; | |
99 | ||
100 | snprintf(xstrerror_buf, BUFSIZ, "(%d) %s", error, errmsg); | |
101 | ||
102 | return xstrerror_buf; | |
103 | } |