2N/A/* strerror.c --- POSIX compatible system error routine
2N/A
2N/A Copyright (C) 2007-2010 Free Software Foundation, Inc.
2N/A
2N/A This program is free software: you can redistribute it and/or modify
2N/A it under the terms of the GNU General Public License as published by
2N/A the Free Software Foundation; either version 3 of the License, or
2N/A (at your option) any later version.
2N/A
2N/A This program is distributed in the hope that it will be useful,
2N/A but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A GNU General Public License for more details.
2N/A
2N/A You should have received a copy of the GNU General Public License
2N/A along with this program. If not, see <http://www.gnu.org/licenses/>. */
2N/A
2N/A#include <config.h>
2N/A
2N/A#include <string.h>
2N/A
2N/A#if REPLACE_STRERROR
2N/A
2N/A# include <errno.h>
2N/A# include <stdio.h>
2N/A
2N/A# if GNULIB_defined_ESOCK /* native Windows platforms */
2N/A# if HAVE_WINSOCK2_H
2N/A# include <winsock2.h>
2N/A# endif
2N/A# endif
2N/A
2N/A# include "intprops.h"
2N/A
2N/A/* Use the system functions, not the gnulib overrides in this file. */
2N/A# undef sprintf
2N/A
2N/A# undef strerror
2N/A# if ! HAVE_DECL_STRERROR
2N/A# define strerror(n) NULL
2N/A# endif
2N/A
2N/Achar *
2N/Arpl_strerror (int n)
2N/A{
2N/A char const *msg = NULL;
2N/A /* These error messages are taken from glibc/sysdeps/gnu/errlist.c. */
2N/A switch (n)
2N/A {
2N/A# if GNULIB_defined_ETXTBSY
2N/A case ETXTBSY:
2N/A msg = "Text file busy";
2N/A break;
2N/A# endif
2N/A
2N/A# if GNULIB_defined_ESOCK /* native Windows platforms */
2N/A /* EWOULDBLOCK is the same as EAGAIN. */
2N/A case EINPROGRESS:
2N/A msg = "Operation now in progress";
2N/A break;
2N/A case EALREADY:
2N/A msg = "Operation already in progress";
2N/A break;
2N/A case ENOTSOCK:
2N/A msg = "Socket operation on non-socket";
2N/A break;
2N/A case EDESTADDRREQ:
2N/A msg = "Destination address required";
2N/A break;
2N/A case EMSGSIZE:
2N/A msg = "Message too long";
2N/A break;
2N/A case EPROTOTYPE:
2N/A msg = "Protocol wrong type for socket";
2N/A break;
2N/A case ENOPROTOOPT:
2N/A msg = "Protocol not available";
2N/A break;
2N/A case EPROTONOSUPPORT:
2N/A msg = "Protocol not supported";
2N/A break;
2N/A case ESOCKTNOSUPPORT:
2N/A msg = "Socket type not supported";
2N/A break;
2N/A case EOPNOTSUPP:
2N/A msg = "Operation not supported";
2N/A break;
2N/A case EPFNOSUPPORT:
2N/A msg = "Protocol family not supported";
2N/A break;
2N/A case EAFNOSUPPORT:
2N/A msg = "Address family not supported by protocol";
2N/A break;
2N/A case EADDRINUSE:
2N/A msg = "Address already in use";
2N/A break;
2N/A case EADDRNOTAVAIL:
2N/A msg = "Cannot assign requested address";
2N/A break;
2N/A case ENETDOWN:
2N/A msg = "Network is down";
2N/A break;
2N/A case ENETUNREACH:
2N/A msg = "Network is unreachable";
2N/A break;
2N/A case ENETRESET:
2N/A msg = "Network dropped connection on reset";
2N/A break;
2N/A case ECONNABORTED:
2N/A msg = "Software caused connection abort";
2N/A break;
2N/A case ECONNRESET:
2N/A msg = "Connection reset by peer";
2N/A break;
2N/A case ENOBUFS:
2N/A msg = "No buffer space available";
2N/A break;
2N/A case EISCONN:
2N/A msg = "Transport endpoint is already connected";
2N/A break;
2N/A case ENOTCONN:
2N/A msg = "Transport endpoint is not connected";
2N/A break;
2N/A case ESHUTDOWN:
2N/A msg = "Cannot send after transport endpoint shutdown";
2N/A break;
2N/A case ETOOMANYREFS:
2N/A msg = "Too many references: cannot splice";
2N/A break;
2N/A case ETIMEDOUT:
2N/A msg = "Connection timed out";
2N/A break;
2N/A case ECONNREFUSED:
2N/A msg = "Connection refused";
2N/A break;
2N/A case ELOOP:
2N/A msg = "Too many levels of symbolic links";
2N/A break;
2N/A case EHOSTDOWN:
2N/A msg = "Host is down";
2N/A break;
2N/A case EHOSTUNREACH:
2N/A msg = "No route to host";
2N/A break;
2N/A case EPROCLIM:
2N/A msg = "Too many processes";
2N/A break;
2N/A case EUSERS:
2N/A msg = "Too many users";
2N/A break;
2N/A case EDQUOT:
2N/A msg = "Disk quota exceeded";
2N/A break;
2N/A case ESTALE:
2N/A msg = "Stale NFS file handle";
2N/A break;
2N/A case EREMOTE:
2N/A msg = "Object is remote";
2N/A break;
2N/A# if HAVE_WINSOCK2_H
2N/A /* WSA_INVALID_HANDLE maps to EBADF */
2N/A /* WSA_NOT_ENOUGH_MEMORY maps to ENOMEM */
2N/A /* WSA_INVALID_PARAMETER maps to EINVAL */
2N/A case WSA_OPERATION_ABORTED:
2N/A msg = "Overlapped operation aborted";
2N/A break;
2N/A case WSA_IO_INCOMPLETE:
2N/A msg = "Overlapped I/O event object not in signaled state";
2N/A break;
2N/A case WSA_IO_PENDING:
2N/A msg = "Overlapped operations will complete later";
2N/A break;
2N/A /* WSAEINTR maps to EINTR */
2N/A /* WSAEBADF maps to EBADF */
2N/A /* WSAEACCES maps to EACCES */
2N/A /* WSAEFAULT maps to EFAULT */
2N/A /* WSAEINVAL maps to EINVAL */
2N/A /* WSAEMFILE maps to EMFILE */
2N/A /* WSAEWOULDBLOCK maps to EWOULDBLOCK */
2N/A /* WSAEINPROGRESS is EINPROGRESS */
2N/A /* WSAEALREADY is EALREADY */
2N/A /* WSAENOTSOCK is ENOTSOCK */
2N/A /* WSAEDESTADDRREQ is EDESTADDRREQ */
2N/A /* WSAEMSGSIZE is EMSGSIZE */
2N/A /* WSAEPROTOTYPE is EPROTOTYPE */
2N/A /* WSAENOPROTOOPT is ENOPROTOOPT */
2N/A /* WSAEPROTONOSUPPORT is EPROTONOSUPPORT */
2N/A /* WSAESOCKTNOSUPPORT is ESOCKTNOSUPPORT */
2N/A /* WSAEOPNOTSUPP is EOPNOTSUPP */
2N/A /* WSAEPFNOSUPPORT is EPFNOSUPPORT */
2N/A /* WSAEAFNOSUPPORT is EAFNOSUPPORT */
2N/A /* WSAEADDRINUSE is EADDRINUSE */
2N/A /* WSAEADDRNOTAVAIL is EADDRNOTAVAIL */
2N/A /* WSAENETDOWN is ENETDOWN */
2N/A /* WSAENETUNREACH is ENETUNREACH */
2N/A /* WSAENETRESET is ENETRESET */
2N/A /* WSAECONNABORTED is ECONNABORTED */
2N/A /* WSAECONNRESET is ECONNRESET */
2N/A /* WSAENOBUFS is ENOBUFS */
2N/A /* WSAEISCONN is EISCONN */
2N/A /* WSAENOTCONN is ENOTCONN */
2N/A /* WSAESHUTDOWN is ESHUTDOWN */
2N/A /* WSAETOOMANYREFS is ETOOMANYREFS */
2N/A /* WSAETIMEDOUT is ETIMEDOUT */
2N/A /* WSAECONNREFUSED is ECONNREFUSED */
2N/A /* WSAELOOP is ELOOP */
2N/A /* WSAENAMETOOLONG maps to ENAMETOOLONG */
2N/A /* WSAEHOSTDOWN is EHOSTDOWN */
2N/A /* WSAEHOSTUNREACH is EHOSTUNREACH */
2N/A /* WSAENOTEMPTY maps to ENOTEMPTY */
2N/A /* WSAEPROCLIM is EPROCLIM */
2N/A /* WSAEUSERS is EUSERS */
2N/A /* WSAEDQUOT is EDQUOT */
2N/A /* WSAESTALE is ESTALE */
2N/A /* WSAEREMOTE is EREMOTE */
2N/A case WSASYSNOTREADY:
2N/A msg = "Network subsystem is unavailable";
2N/A break;
2N/A case WSAVERNOTSUPPORTED:
2N/A msg = "Winsock.dll version out of range";
2N/A break;
2N/A case WSANOTINITIALISED:
2N/A msg = "Successful WSAStartup not yet performed";
2N/A break;
2N/A case WSAEDISCON:
2N/A msg = "Graceful shutdown in progress";
2N/A break;
2N/A case WSAENOMORE: case WSA_E_NO_MORE:
2N/A msg = "No more results";
2N/A break;
2N/A case WSAECANCELLED: case WSA_E_CANCELLED:
2N/A msg = "Call was canceled";
2N/A break;
2N/A case WSAEINVALIDPROCTABLE:
2N/A msg = "Procedure call table is invalid";
2N/A break;
2N/A case WSAEINVALIDPROVIDER:
2N/A msg = "Service provider is invalid";
2N/A break;
2N/A case WSAEPROVIDERFAILEDINIT:
2N/A msg = "Service provider failed to initialize";
2N/A break;
2N/A case WSASYSCALLFAILURE:
2N/A msg = "System call failure";
2N/A break;
2N/A case WSASERVICE_NOT_FOUND:
2N/A msg = "Service not found";
2N/A break;
2N/A case WSATYPE_NOT_FOUND:
2N/A msg = "Class type not found";
2N/A break;
2N/A case WSAEREFUSED:
2N/A msg = "Database query was refused";
2N/A break;
2N/A case WSAHOST_NOT_FOUND:
2N/A msg = "Host not found";
2N/A break;
2N/A case WSATRY_AGAIN:
2N/A msg = "Nonauthoritative host not found";
2N/A break;
2N/A case WSANO_RECOVERY:
2N/A msg = "Nonrecoverable error";
2N/A break;
2N/A case WSANO_DATA:
2N/A msg = "Valid name, no data record of requested type";
2N/A break;
2N/A /* WSA_QOS_* omitted */
2N/A# endif
2N/A# endif
2N/A
2N/A# if GNULIB_defined_ENOMSG
2N/A case ENOMSG:
2N/A msg = "No message of desired type";
2N/A break;
2N/A# endif
2N/A
2N/A# if GNULIB_defined_EIDRM
2N/A case EIDRM:
2N/A msg = "Identifier removed";
2N/A break;
2N/A# endif
2N/A
2N/A# if GNULIB_defined_ENOLINK
2N/A case ENOLINK:
2N/A msg = "Link has been severed";
2N/A break;
2N/A# endif
2N/A
2N/A# if GNULIB_defined_EPROTO
2N/A case EPROTO:
2N/A msg = "Protocol error";
2N/A break;
2N/A# endif
2N/A
2N/A# if GNULIB_defined_EMULTIHOP
2N/A case EMULTIHOP:
2N/A msg = "Multihop attempted";
2N/A break;
2N/A# endif
2N/A
2N/A# if GNULIB_defined_EBADMSG
2N/A case EBADMSG:
2N/A msg = "Bad message";
2N/A break;
2N/A# endif
2N/A
2N/A# if GNULIB_defined_EOVERFLOW
2N/A case EOVERFLOW:
2N/A msg = "Value too large for defined data type";
2N/A break;
2N/A# endif
2N/A
2N/A# if GNULIB_defined_ENOTSUP
2N/A case ENOTSUP:
2N/A msg = "Not supported";
2N/A break;
2N/A# endif
2N/A
2N/A# if GNULIB_defined_ESTALE
2N/A case ESTALE:
2N/A msg = "Stale NFS file handle";
2N/A break;
2N/A# endif
2N/A
2N/A# if GNULIB_defined_ECANCELED
2N/A case ECANCELED:
2N/A msg = "Operation canceled";
2N/A break;
2N/A# endif
2N/A }
2N/A
2N/A if (msg)
2N/A return (char *) msg;
2N/A
2N/A {
2N/A char *result = strerror (n);
2N/A
2N/A if (result == NULL || result[0] == '\0')
2N/A {
2N/A static char const fmt[] = "Unknown error (%d)";
2N/A static char msg_buf[sizeof fmt + INT_STRLEN_BOUND (n)];
2N/A sprintf (msg_buf, fmt, n);
2N/A return msg_buf;
2N/A }
2N/A
2N/A return result;
2N/A }
2N/A}
2N/A
2N/A#endif