Back to index

nagios-plugins  1.4.16
strerror.c
Go to the documentation of this file.
00001 /* strerror.c --- POSIX compatible system error routine
00002 
00003    Copyright (C) 2007-2010 Free Software Foundation, Inc.
00004 
00005    This program is free software: you can redistribute it and/or modify
00006    it under the terms of the GNU General Public License as published by
00007    the Free Software Foundation; either version 3 of the License, or
00008    (at your option) any later version.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014 
00015    You should have received a copy of the GNU General Public License
00016    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00017 
00018 #include <config.h>
00019 
00020 #include <string.h>
00021 
00022 #if REPLACE_STRERROR
00023 
00024 # include <errno.h>
00025 # include <stdio.h>
00026 
00027 # if GNULIB_defined_ESOCK /* native Windows platforms */
00028 #  if HAVE_WINSOCK2_H
00029 #   include <winsock2.h>
00030 #  endif
00031 # endif
00032 
00033 # include "intprops.h"
00034 
00035 /* Use the system functions, not the gnulib overrides in this file.  */
00036 # undef sprintf
00037 
00038 # undef strerror
00039 # if ! HAVE_DECL_STRERROR
00040 #  define strerror(n) NULL
00041 # endif
00042 
00043 char *
00044 rpl_strerror (int n)
00045 {
00046   char const *msg = NULL;
00047   /* These error messages are taken from glibc/sysdeps/gnu/errlist.c.  */
00048   switch (n)
00049     {
00050 # if GNULIB_defined_ETXTBSY
00051     case ETXTBSY:
00052       msg = "Text file busy";
00053       break;
00054 # endif
00055 
00056 # if GNULIB_defined_ESOCK /* native Windows platforms */
00057     /* EWOULDBLOCK is the same as EAGAIN.  */
00058     case EINPROGRESS:
00059       msg = "Operation now in progress";
00060       break;
00061     case EALREADY:
00062       msg = "Operation already in progress";
00063       break;
00064     case ENOTSOCK:
00065       msg = "Socket operation on non-socket";
00066       break;
00067     case EDESTADDRREQ:
00068       msg = "Destination address required";
00069       break;
00070     case EMSGSIZE:
00071       msg = "Message too long";
00072       break;
00073     case EPROTOTYPE:
00074       msg = "Protocol wrong type for socket";
00075       break;
00076     case ENOPROTOOPT:
00077       msg = "Protocol not available";
00078       break;
00079     case EPROTONOSUPPORT:
00080       msg = "Protocol not supported";
00081       break;
00082     case ESOCKTNOSUPPORT:
00083       msg = "Socket type not supported";
00084       break;
00085     case EOPNOTSUPP:
00086       msg = "Operation not supported";
00087       break;
00088     case EPFNOSUPPORT:
00089       msg = "Protocol family not supported";
00090       break;
00091     case EAFNOSUPPORT:
00092       msg = "Address family not supported by protocol";
00093       break;
00094     case EADDRINUSE:
00095       msg = "Address already in use";
00096       break;
00097     case EADDRNOTAVAIL:
00098       msg = "Cannot assign requested address";
00099       break;
00100     case ENETDOWN:
00101       msg = "Network is down";
00102       break;
00103     case ENETUNREACH:
00104       msg = "Network is unreachable";
00105       break;
00106     case ENETRESET:
00107       msg = "Network dropped connection on reset";
00108       break;
00109     case ECONNABORTED:
00110       msg = "Software caused connection abort";
00111       break;
00112     case ECONNRESET:
00113       msg = "Connection reset by peer";
00114       break;
00115     case ENOBUFS:
00116       msg = "No buffer space available";
00117       break;
00118     case EISCONN:
00119       msg = "Transport endpoint is already connected";
00120       break;
00121     case ENOTCONN:
00122       msg = "Transport endpoint is not connected";
00123       break;
00124     case ESHUTDOWN:
00125       msg = "Cannot send after transport endpoint shutdown";
00126       break;
00127     case ETOOMANYREFS:
00128       msg = "Too many references: cannot splice";
00129       break;
00130     case ETIMEDOUT:
00131       msg = "Connection timed out";
00132       break;
00133     case ECONNREFUSED:
00134       msg = "Connection refused";
00135       break;
00136     case ELOOP:
00137       msg = "Too many levels of symbolic links";
00138       break;
00139     case EHOSTDOWN:
00140       msg = "Host is down";
00141       break;
00142     case EHOSTUNREACH:
00143       msg = "No route to host";
00144       break;
00145     case EPROCLIM:
00146       msg = "Too many processes";
00147       break;
00148     case EUSERS:
00149       msg = "Too many users";
00150       break;
00151     case EDQUOT:
00152       msg = "Disk quota exceeded";
00153       break;
00154     case ESTALE:
00155       msg = "Stale NFS file handle";
00156       break;
00157     case EREMOTE:
00158       msg = "Object is remote";
00159       break;
00160 #  if HAVE_WINSOCK2_H
00161     /* WSA_INVALID_HANDLE maps to EBADF */
00162     /* WSA_NOT_ENOUGH_MEMORY maps to ENOMEM */
00163     /* WSA_INVALID_PARAMETER maps to EINVAL */
00164     case WSA_OPERATION_ABORTED:
00165       msg = "Overlapped operation aborted";
00166       break;
00167     case WSA_IO_INCOMPLETE:
00168       msg = "Overlapped I/O event object not in signaled state";
00169       break;
00170     case WSA_IO_PENDING:
00171       msg = "Overlapped operations will complete later";
00172       break;
00173     /* WSAEINTR maps to EINTR */
00174     /* WSAEBADF maps to EBADF */
00175     /* WSAEACCES maps to EACCES */
00176     /* WSAEFAULT maps to EFAULT */
00177     /* WSAEINVAL maps to EINVAL */
00178     /* WSAEMFILE maps to EMFILE */
00179     /* WSAEWOULDBLOCK maps to EWOULDBLOCK */
00180     /* WSAEINPROGRESS is EINPROGRESS */
00181     /* WSAEALREADY is EALREADY */
00182     /* WSAENOTSOCK is ENOTSOCK */
00183     /* WSAEDESTADDRREQ is EDESTADDRREQ */
00184     /* WSAEMSGSIZE is EMSGSIZE */
00185     /* WSAEPROTOTYPE is EPROTOTYPE */
00186     /* WSAENOPROTOOPT is ENOPROTOOPT */
00187     /* WSAEPROTONOSUPPORT is EPROTONOSUPPORT */
00188     /* WSAESOCKTNOSUPPORT is ESOCKTNOSUPPORT */
00189     /* WSAEOPNOTSUPP is EOPNOTSUPP */
00190     /* WSAEPFNOSUPPORT is EPFNOSUPPORT */
00191     /* WSAEAFNOSUPPORT is EAFNOSUPPORT */
00192     /* WSAEADDRINUSE is EADDRINUSE */
00193     /* WSAEADDRNOTAVAIL is EADDRNOTAVAIL */
00194     /* WSAENETDOWN is ENETDOWN */
00195     /* WSAENETUNREACH is ENETUNREACH */
00196     /* WSAENETRESET is ENETRESET */
00197     /* WSAECONNABORTED is ECONNABORTED */
00198     /* WSAECONNRESET is ECONNRESET */
00199     /* WSAENOBUFS is ENOBUFS */
00200     /* WSAEISCONN is EISCONN */
00201     /* WSAENOTCONN is ENOTCONN */
00202     /* WSAESHUTDOWN is ESHUTDOWN */
00203     /* WSAETOOMANYREFS is ETOOMANYREFS */
00204     /* WSAETIMEDOUT is ETIMEDOUT */
00205     /* WSAECONNREFUSED is ECONNREFUSED */
00206     /* WSAELOOP is ELOOP */
00207     /* WSAENAMETOOLONG maps to ENAMETOOLONG */
00208     /* WSAEHOSTDOWN is EHOSTDOWN */
00209     /* WSAEHOSTUNREACH is EHOSTUNREACH */
00210     /* WSAENOTEMPTY maps to ENOTEMPTY */
00211     /* WSAEPROCLIM is EPROCLIM */
00212     /* WSAEUSERS is EUSERS */
00213     /* WSAEDQUOT is EDQUOT */
00214     /* WSAESTALE is ESTALE */
00215     /* WSAEREMOTE is EREMOTE */
00216     case WSASYSNOTREADY:
00217       msg = "Network subsystem is unavailable";
00218       break;
00219     case WSAVERNOTSUPPORTED:
00220       msg = "Winsock.dll version out of range";
00221       break;
00222     case WSANOTINITIALISED:
00223       msg = "Successful WSAStartup not yet performed";
00224       break;
00225     case WSAEDISCON:
00226       msg = "Graceful shutdown in progress";
00227       break;
00228     case WSAENOMORE: case WSA_E_NO_MORE:
00229       msg = "No more results";
00230       break;
00231     case WSAECANCELLED: case WSA_E_CANCELLED:
00232       msg = "Call was canceled";
00233       break;
00234     case WSAEINVALIDPROCTABLE:
00235       msg = "Procedure call table is invalid";
00236       break;
00237     case WSAEINVALIDPROVIDER:
00238       msg = "Service provider is invalid";
00239       break;
00240     case WSAEPROVIDERFAILEDINIT:
00241       msg = "Service provider failed to initialize";
00242       break;
00243     case WSASYSCALLFAILURE:
00244       msg = "System call failure";
00245       break;
00246     case WSASERVICE_NOT_FOUND:
00247       msg = "Service not found";
00248       break;
00249     case WSATYPE_NOT_FOUND:
00250       msg = "Class type not found";
00251       break;
00252     case WSAEREFUSED:
00253       msg = "Database query was refused";
00254       break;
00255     case WSAHOST_NOT_FOUND:
00256       msg = "Host not found";
00257       break;
00258     case WSATRY_AGAIN:
00259       msg = "Nonauthoritative host not found";
00260       break;
00261     case WSANO_RECOVERY:
00262       msg = "Nonrecoverable error";
00263       break;
00264     case WSANO_DATA:
00265       msg = "Valid name, no data record of requested type";
00266       break;
00267     /* WSA_QOS_* omitted */
00268 #  endif
00269 # endif
00270 
00271 # if GNULIB_defined_ENOMSG
00272     case ENOMSG:
00273       msg = "No message of desired type";
00274       break;
00275 # endif
00276 
00277 # if GNULIB_defined_EIDRM
00278     case EIDRM:
00279       msg = "Identifier removed";
00280       break;
00281 # endif
00282 
00283 # if GNULIB_defined_ENOLINK
00284     case ENOLINK:
00285       msg = "Link has been severed";
00286       break;
00287 # endif
00288 
00289 # if GNULIB_defined_EPROTO
00290     case EPROTO:
00291       msg = "Protocol error";
00292       break;
00293 # endif
00294 
00295 # if GNULIB_defined_EMULTIHOP
00296     case EMULTIHOP:
00297       msg = "Multihop attempted";
00298       break;
00299 # endif
00300 
00301 # if GNULIB_defined_EBADMSG
00302     case EBADMSG:
00303       msg = "Bad message";
00304       break;
00305 # endif
00306 
00307 # if GNULIB_defined_EOVERFLOW
00308     case EOVERFLOW:
00309       msg = "Value too large for defined data type";
00310       break;
00311 # endif
00312 
00313 # if GNULIB_defined_ENOTSUP
00314     case ENOTSUP:
00315       msg = "Not supported";
00316       break;
00317 # endif
00318 
00319 # if GNULIB_defined_ESTALE
00320     case ESTALE:
00321       msg = "Stale NFS file handle";
00322       break;
00323 # endif
00324 
00325 # if GNULIB_defined_ECANCELED
00326     case ECANCELED:
00327       msg = "Operation canceled";
00328       break;
00329 # endif
00330     }
00331 
00332   if (msg)
00333     return (char *) msg;
00334 
00335   {
00336     char *result = strerror (n);
00337 
00338     if (result == NULL || result[0] == '\0')
00339       {
00340         static char const fmt[] = "Unknown error (%d)";
00341         static char msg_buf[sizeof fmt + INT_STRLEN_BOUND (n)];
00342         sprintf (msg_buf, fmt, n);
00343         return msg_buf;
00344       }
00345 
00346     return result;
00347   }
00348 }
00349 
00350 #endif