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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors