From 346e323228f5cc71664c2f49541f816f88914342 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Sat, 23 Nov 2013 17:19:10 +0100 Subject: [PATCH] Added strerror module. --- gl/Makefile.am | 20 +++- gl/m4/gnulib-cache.m4 | 3 +- gl/m4/gnulib-comp.m4 | 30 ++-- gl/strerror-override.c | 302 ++++++++++++++++++++++++++++++++++++++++++ gl/strerror-override.h | 56 ++++++++ gl/strerror.c | 70 ++++++++++ gl/tests/Makefile.am | 18 --- gl/tests/strerror-override.c | 302 ------------------------------------------ gl/tests/strerror-override.h | 56 -------- gl/tests/strerror.c | 70 ---------- 10 files changed, 464 insertions(+), 463 deletions(-) create mode 100644 gl/strerror-override.c create mode 100644 gl/strerror-override.h create mode 100644 gl/strerror.c delete mode 100644 gl/tests/strerror-override.c delete mode 100644 gl/tests/strerror-override.h delete mode 100644 gl/tests/strerror.c diff --git a/gl/Makefile.am b/gl/Makefile.am index 43e17e9..9e3c3e1 100644 --- a/gl/Makefile.am +++ b/gl/Makefile.am @@ -21,7 +21,7 @@ # the same distribution terms as the rest of that program. # # Generated by gnulib-tool. -# Reproduce by: gnulib-tool --import --dir=. --local-dir=gl/override --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --with-tests --avoid=alignof-tests --avoid=lock-tests --avoid=lseek-tests --lgpl=2 --no-conditional-dependencies --libtool --macro-prefix=gl --no-vc-files accept alloca base64 bind byteswap c-ctype close connect extensions func gendocs getaddrinfo getpass gettext gettimeofday hash-pjw-bare havelib iconv inet_ntop inet_pton intprops lib-msvc-compat lib-symbol-versions listen maintainer-makefile manywarnings memmem-simple minmax netdb netinet_in pmccabe2html read-file recv recvfrom select send sendto servent setsockopt shutdown snprintf socket sockets socklen stdint strcase strndup strtok_r strverscmp sys_socket sys_stat time_r u64 unistd valgrind-tests vasprintf vsnprintf warnings +# Reproduce by: gnulib-tool --import --dir=. --local-dir=gl/override --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --with-tests --avoid=alignof-tests --avoid=lock-tests --avoid=lseek-tests --lgpl=2 --no-conditional-dependencies --libtool --macro-prefix=gl --no-vc-files accept alloca base64 bind byteswap c-ctype close connect extensions func gendocs getaddrinfo getpass gettext gettimeofday hash-pjw-bare havelib iconv inet_ntop inet_pton intprops lib-msvc-compat lib-symbol-versions listen maintainer-makefile manywarnings memmem-simple minmax netdb netinet_in pmccabe2html read-file recv recvfrom select send sendto servent setsockopt shutdown snprintf socket sockets socklen stdint strcase strerror strndup strtok_r strverscmp sys_socket sys_stat time_r u64 unistd valgrind-tests vasprintf vsnprintf warnings AUTOMAKE_OPTIONS = 1.9.6 gnits @@ -1218,6 +1218,24 @@ EXTRA_libgnu_la_SOURCES += strdup.c ## end gnulib module strdup-posix +## begin gnulib module strerror + + +EXTRA_DIST += strerror.c + +EXTRA_libgnu_la_SOURCES += strerror.c + +## end gnulib module strerror + +## begin gnulib module strerror-override + + +EXTRA_DIST += strerror-override.c strerror-override.h + +EXTRA_libgnu_la_SOURCES += strerror-override.c + +## end gnulib module strerror-override + ## begin gnulib module string BUILT_SOURCES += string.h diff --git a/gl/m4/gnulib-cache.m4 b/gl/m4/gnulib-cache.m4 index 6540575..65b9743 100644 --- a/gl/m4/gnulib-cache.m4 +++ b/gl/m4/gnulib-cache.m4 @@ -27,7 +27,7 @@ # Specification in the form of a command-line invocation: -# gnulib-tool --import --dir=. --local-dir=gl/override --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --with-tests --avoid=alignof-tests --avoid=lock-tests --avoid=lseek-tests --lgpl=2 --no-conditional-dependencies --libtool --macro-prefix=gl --no-vc-files accept alloca base64 bind byteswap c-ctype close connect extensions func gendocs getaddrinfo getpass gettext gettimeofday hash-pjw-bare havelib iconv inet_ntop inet_pton intprops lib-msvc-compat lib-symbol-versions listen maintainer-makefile manywarnings memmem-simple minmax netdb netinet_in pmccabe2html read-file recv recvfrom select send sendto servent setsockopt shutdown snprintf socket sockets socklen stdint strcase strndup strtok_r strverscmp sys_socket sys_stat time_r u64 unistd valgrind-tests vasprintf vsnprintf warnings +# gnulib-tool --import --dir=. --local-dir=gl/override --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --with-tests --avoid=alignof-tests --avoid=lock-tests --avoid=lseek-tests --lgpl=2 --no-conditional-dependencies --libtool --macro-prefix=gl --no-vc-files accept alloca base64 bind byteswap c-ctype close connect extensions func gendocs getaddrinfo getpass gettext gettimeofday hash-pjw-bare havelib iconv inet_ntop inet_pton intprops lib-msvc-compat lib-symbol-versions listen maintainer-makefile manywarnings memmem-simple minmax netdb netinet_in pmccabe2html read-file recv recvfrom select send sendto servent setsockopt shutdown snprintf socket sockets socklen stdint strcase strerror strndup strtok_r strverscmp sys_socket sys_stat time_r u64 unistd valgrind-tests vasprintf vsnprintf warnings # Specification in the form of a few gnulib-tool.m4 macro invocations: gl_LOCAL_DIR([gl/override]) @@ -78,6 +78,7 @@ gl_MODULES([ socklen stdint strcase + strerror strndup strtok_r strverscmp diff --git a/gl/m4/gnulib-comp.m4 b/gl/m4/gnulib-comp.m4 index 8ced96a..c1381bf 100644 --- a/gl/m4/gnulib-comp.m4 +++ b/gl/m4/gnulib-comp.m4 @@ -563,6 +563,18 @@ AC_SUBST([LTALLOCA]) gl_PREREQ_STRDUP fi gl_STRING_MODULE_INDICATOR([strdup]) + gl_FUNC_STRERROR + if test $REPLACE_STRERROR = 1; then + AC_LIBOBJ([strerror]) + fi + gl_MODULE_INDICATOR([strerror]) + gl_STRING_MODULE_INDICATOR([strerror]) + AC_REQUIRE([gl_HEADER_ERRNO_H]) + AC_REQUIRE([gl_FUNC_STRERROR_0]) + if test -n "$ERRNO_H" || test $REPLACE_STRERROR_0 = 1; then + AC_LIBOBJ([strerror-override]) + gl_PREREQ_SYS_H_WINSOCK2 + fi gl_HEADER_STRING_H gl_HEADER_STRINGS_H gl_FUNC_STRNDUP @@ -745,18 +757,6 @@ changequote([, ])dnl gl_SYS_STAT_MODULE_INDICATOR([stat]) AC_REQUIRE([gt_TYPE_WCHAR_T]) AC_REQUIRE([gt_TYPE_WINT_T]) - gl_FUNC_STRERROR - if test $REPLACE_STRERROR = 1; then - AC_LIBOBJ([strerror]) - fi - gl_MODULE_INDICATOR([strerror]) - gl_STRING_MODULE_INDICATOR([strerror]) - AC_REQUIRE([gl_HEADER_ERRNO_H]) - AC_REQUIRE([gl_FUNC_STRERROR_0]) - if test -n "$ERRNO_H" || test $REPLACE_STRERROR_0 = 1; then - AC_LIBOBJ([strerror-override]) - gl_PREREQ_SYS_H_WINSOCK2 - fi gl_FUNC_STRERROR_R if test $HAVE_DECL_STRERROR_R = 0 || test $REPLACE_STRERROR_R = 1; then AC_LIBOBJ([strerror_r]) @@ -966,6 +966,9 @@ AC_DEFUN([gl_FILE_LIST], [ lib/str-two-way.h lib/strcasecmp.c lib/strdup.c + lib/strerror-override.c + lib/strerror-override.h + lib/strerror.c lib/string.in.h lib/strings.in.h lib/strncasecmp.c @@ -1285,9 +1288,6 @@ AC_DEFUN([gl_FILE_LIST], [ tests=lib/pipe.c tests=lib/same-inode.h tests=lib/stat.c - tests=lib/strerror-override.c - tests=lib/strerror-override.h - tests=lib/strerror.c tests=lib/strerror_r.c tests=lib/symlink.c tests=lib/sys_ioctl.in.h diff --git a/gl/strerror-override.c b/gl/strerror-override.c new file mode 100644 index 0000000..dcceaa5 --- /dev/null +++ b/gl/strerror-override.c @@ -0,0 +1,302 @@ +/* strerror-override.c --- POSIX compatible system error routine + + Copyright (C) 2010-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . */ + +/* Written by Bruno Haible , 2010. */ + +#include + +#include "strerror-override.h" + +#include + +#if GNULIB_defined_EWINSOCK /* native Windows platforms */ +# if HAVE_WINSOCK2_H +# include +# endif +#endif + +/* If ERRNUM maps to an errno value defined by gnulib, return a string + describing the error. Otherwise return NULL. */ +const char * +strerror_override (int errnum) +{ + /* These error messages are taken from glibc/sysdeps/gnu/errlist.c. */ + switch (errnum) + { +#if REPLACE_STRERROR_0 + case 0: + return "Success"; +#endif + +#if GNULIB_defined_ESOCK /* native Windows platforms with older */ + case EINPROGRESS: + return "Operation now in progress"; + case EALREADY: + return "Operation already in progress"; + case ENOTSOCK: + return "Socket operation on non-socket"; + case EDESTADDRREQ: + return "Destination address required"; + case EMSGSIZE: + return "Message too long"; + case EPROTOTYPE: + return "Protocol wrong type for socket"; + case ENOPROTOOPT: + return "Protocol not available"; + case EPROTONOSUPPORT: + return "Protocol not supported"; + case EOPNOTSUPP: + return "Operation not supported"; + case EAFNOSUPPORT: + return "Address family not supported by protocol"; + case EADDRINUSE: + return "Address already in use"; + case EADDRNOTAVAIL: + return "Cannot assign requested address"; + case ENETDOWN: + return "Network is down"; + case ENETUNREACH: + return "Network is unreachable"; + case ECONNRESET: + return "Connection reset by peer"; + case ENOBUFS: + return "No buffer space available"; + case EISCONN: + return "Transport endpoint is already connected"; + case ENOTCONN: + return "Transport endpoint is not connected"; + case ETIMEDOUT: + return "Connection timed out"; + case ECONNREFUSED: + return "Connection refused"; + case ELOOP: + return "Too many levels of symbolic links"; + case EHOSTUNREACH: + return "No route to host"; + case EWOULDBLOCK: + return "Operation would block"; +#endif +#if GNULIB_defined_ESTREAMS /* native Windows platforms with older */ + case ETXTBSY: + return "Text file busy"; + case ENODATA: + return "No data available"; + case ENOSR: + return "Out of streams resources"; + case ENOSTR: + return "Device not a stream"; + case ETIME: + return "Timer expired"; + case EOTHER: + return "Other error"; +#endif +#if GNULIB_defined_EWINSOCK /* native Windows platforms */ + case ESOCKTNOSUPPORT: + return "Socket type not supported"; + case EPFNOSUPPORT: + return "Protocol family not supported"; + case ESHUTDOWN: + return "Cannot send after transport endpoint shutdown"; + case ETOOMANYREFS: + return "Too many references: cannot splice"; + case EHOSTDOWN: + return "Host is down"; + case EPROCLIM: + return "Too many processes"; + case EUSERS: + return "Too many users"; + case EDQUOT: + return "Disk quota exceeded"; + case ESTALE: + return "Stale NFS file handle"; + case EREMOTE: + return "Object is remote"; +# if HAVE_WINSOCK2_H + /* WSA_INVALID_HANDLE maps to EBADF */ + /* WSA_NOT_ENOUGH_MEMORY maps to ENOMEM */ + /* WSA_INVALID_PARAMETER maps to EINVAL */ + case WSA_OPERATION_ABORTED: + return "Overlapped operation aborted"; + case WSA_IO_INCOMPLETE: + return "Overlapped I/O event object not in signaled state"; + case WSA_IO_PENDING: + return "Overlapped operations will complete later"; + /* WSAEINTR maps to EINTR */ + /* WSAEBADF maps to EBADF */ + /* WSAEACCES maps to EACCES */ + /* WSAEFAULT maps to EFAULT */ + /* WSAEINVAL maps to EINVAL */ + /* WSAEMFILE maps to EMFILE */ + /* WSAEWOULDBLOCK maps to EWOULDBLOCK */ + /* WSAEINPROGRESS maps to EINPROGRESS */ + /* WSAEALREADY maps to EALREADY */ + /* WSAENOTSOCK maps to ENOTSOCK */ + /* WSAEDESTADDRREQ maps to EDESTADDRREQ */ + /* WSAEMSGSIZE maps to EMSGSIZE */ + /* WSAEPROTOTYPE maps to EPROTOTYPE */ + /* WSAENOPROTOOPT maps to ENOPROTOOPT */ + /* WSAEPROTONOSUPPORT maps to EPROTONOSUPPORT */ + /* WSAESOCKTNOSUPPORT is ESOCKTNOSUPPORT */ + /* WSAEOPNOTSUPP maps to EOPNOTSUPP */ + /* WSAEPFNOSUPPORT is EPFNOSUPPORT */ + /* WSAEAFNOSUPPORT maps to EAFNOSUPPORT */ + /* WSAEADDRINUSE maps to EADDRINUSE */ + /* WSAEADDRNOTAVAIL maps to EADDRNOTAVAIL */ + /* WSAENETDOWN maps to ENETDOWN */ + /* WSAENETUNREACH maps to ENETUNREACH */ + /* WSAENETRESET maps to ENETRESET */ + /* WSAECONNABORTED maps to ECONNABORTED */ + /* WSAECONNRESET maps to ECONNRESET */ + /* WSAENOBUFS maps to ENOBUFS */ + /* WSAEISCONN maps to EISCONN */ + /* WSAENOTCONN maps to ENOTCONN */ + /* WSAESHUTDOWN is ESHUTDOWN */ + /* WSAETOOMANYREFS is ETOOMANYREFS */ + /* WSAETIMEDOUT maps to ETIMEDOUT */ + /* WSAECONNREFUSED maps to ECONNREFUSED */ + /* WSAELOOP maps to ELOOP */ + /* WSAENAMETOOLONG maps to ENAMETOOLONG */ + /* WSAEHOSTDOWN is EHOSTDOWN */ + /* WSAEHOSTUNREACH maps to EHOSTUNREACH */ + /* WSAENOTEMPTY maps to ENOTEMPTY */ + /* WSAEPROCLIM is EPROCLIM */ + /* WSAEUSERS is EUSERS */ + /* WSAEDQUOT is EDQUOT */ + /* WSAESTALE is ESTALE */ + /* WSAEREMOTE is EREMOTE */ + case WSASYSNOTREADY: + return "Network subsystem is unavailable"; + case WSAVERNOTSUPPORTED: + return "Winsock.dll version out of range"; + case WSANOTINITIALISED: + return "Successful WSAStartup not yet performed"; + case WSAEDISCON: + return "Graceful shutdown in progress"; + case WSAENOMORE: case WSA_E_NO_MORE: + return "No more results"; + case WSAECANCELLED: case WSA_E_CANCELLED: + return "Call was canceled"; + case WSAEINVALIDPROCTABLE: + return "Procedure call table is invalid"; + case WSAEINVALIDPROVIDER: + return "Service provider is invalid"; + case WSAEPROVIDERFAILEDINIT: + return "Service provider failed to initialize"; + case WSASYSCALLFAILURE: + return "System call failure"; + case WSASERVICE_NOT_FOUND: + return "Service not found"; + case WSATYPE_NOT_FOUND: + return "Class type not found"; + case WSAEREFUSED: + return "Database query was refused"; + case WSAHOST_NOT_FOUND: + return "Host not found"; + case WSATRY_AGAIN: + return "Nonauthoritative host not found"; + case WSANO_RECOVERY: + return "Nonrecoverable error"; + case WSANO_DATA: + return "Valid name, no data record of requested type"; + /* WSA_QOS_* omitted */ +# endif +#endif + +#if GNULIB_defined_ENOMSG + case ENOMSG: + return "No message of desired type"; +#endif + +#if GNULIB_defined_EIDRM + case EIDRM: + return "Identifier removed"; +#endif + +#if GNULIB_defined_ENOLINK + case ENOLINK: + return "Link has been severed"; +#endif + +#if GNULIB_defined_EPROTO + case EPROTO: + return "Protocol error"; +#endif + +#if GNULIB_defined_EMULTIHOP + case EMULTIHOP: + return "Multihop attempted"; +#endif + +#if GNULIB_defined_EBADMSG + case EBADMSG: + return "Bad message"; +#endif + +#if GNULIB_defined_EOVERFLOW + case EOVERFLOW: + return "Value too large for defined data type"; +#endif + +#if GNULIB_defined_ENOTSUP + case ENOTSUP: + return "Not supported"; +#endif + +#if GNULIB_defined_ENETRESET + case ENETRESET: + return "Network dropped connection on reset"; +#endif + +#if GNULIB_defined_ECONNABORTED + case ECONNABORTED: + return "Software caused connection abort"; +#endif + +#if GNULIB_defined_ESTALE + case ESTALE: + return "Stale NFS file handle"; +#endif + +#if GNULIB_defined_EDQUOT + case EDQUOT: + return "Disk quota exceeded"; +#endif + +#if GNULIB_defined_ECANCELED + case ECANCELED: + return "Operation canceled"; +#endif + +#if GNULIB_defined_EOWNERDEAD + case EOWNERDEAD: + return "Owner died"; +#endif + +#if GNULIB_defined_ENOTRECOVERABLE + case ENOTRECOVERABLE: + return "State not recoverable"; +#endif + +#if GNULIB_defined_EILSEQ + case EILSEQ: + return "Invalid or incomplete multibyte or wide character"; +#endif + + default: + return NULL; + } +} diff --git a/gl/strerror-override.h b/gl/strerror-override.h new file mode 100644 index 0000000..64b4be3 --- /dev/null +++ b/gl/strerror-override.h @@ -0,0 +1,56 @@ +/* strerror-override.h --- POSIX compatible system error routine + + Copyright (C) 2010-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . */ + +#ifndef _GL_STRERROR_OVERRIDE_H +# define _GL_STRERROR_OVERRIDE_H + +# include +# include + +/* Reasonable buffer size that should never trigger ERANGE; if this + proves too small, we intentionally abort(), to remind us to fix + this value. */ +# define STACKBUF_LEN 256 + +/* If ERRNUM maps to an errno value defined by gnulib, return a string + describing the error. Otherwise return NULL. */ +# if REPLACE_STRERROR_0 \ + || GNULIB_defined_ESOCK \ + || GNULIB_defined_ESTREAMS \ + || GNULIB_defined_EWINSOCK \ + || GNULIB_defined_ENOMSG \ + || GNULIB_defined_EIDRM \ + || GNULIB_defined_ENOLINK \ + || GNULIB_defined_EPROTO \ + || GNULIB_defined_EMULTIHOP \ + || GNULIB_defined_EBADMSG \ + || GNULIB_defined_EOVERFLOW \ + || GNULIB_defined_ENOTSUP \ + || GNULIB_defined_ENETRESET \ + || GNULIB_defined_ECONNABORTED \ + || GNULIB_defined_ESTALE \ + || GNULIB_defined_EDQUOT \ + || GNULIB_defined_ECANCELED \ + || GNULIB_defined_EOWNERDEAD \ + || GNULIB_defined_ENOTRECOVERABLE \ + || GNULIB_defined_EILSEQ +extern const char *strerror_override (int errnum) _GL_ATTRIBUTE_CONST; +# else +# define strerror_override(ignored) NULL +# endif + +#endif /* _GL_STRERROR_OVERRIDE_H */ diff --git a/gl/strerror.c b/gl/strerror.c new file mode 100644 index 0000000..54e3a14 --- /dev/null +++ b/gl/strerror.c @@ -0,0 +1,70 @@ +/* strerror.c --- POSIX compatible system error routine + + Copyright (C) 2007-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include + +#include +#include +#include +#include + +#include "intprops.h" +#include "strerror-override.h" +#include "verify.h" + +/* Use the system functions, not the gnulib overrides in this file. */ +#undef sprintf + +char * +strerror (int n) +#undef strerror +{ + static char buf[STACKBUF_LEN]; + size_t len; + + /* Cast away const, due to the historical signature of strerror; + callers should not be modifying the string. */ + const char *msg = strerror_override (n); + if (msg) + return (char *) msg; + + msg = strerror (n); + + /* Our strerror_r implementation might use the system's strerror + buffer, so all other clients of strerror have to see the error + copied into a buffer that we manage. This is not thread-safe, + even if the system strerror is, but portable programs shouldn't + be using strerror if they care about thread-safety. */ + if (!msg || !*msg) + { + static char const fmt[] = "Unknown error %d"; + verify (sizeof buf >= sizeof (fmt) + INT_STRLEN_BOUND (n)); + sprintf (buf, fmt, n); + errno = EINVAL; + return buf; + } + + /* Fix STACKBUF_LEN if this ever aborts. */ + len = strlen (msg); + if (sizeof buf <= len) + abort (); + + return memcpy (buf, msg, len + 1); +} diff --git a/gl/tests/Makefile.am b/gl/tests/Makefile.am index 7fcd478..3f73f31 100644 --- a/gl/tests/Makefile.am +++ b/gl/tests/Makefile.am @@ -934,24 +934,6 @@ EXTRA_DIST += test-stdlib.c test-sys_wait.h ## end gnulib module stdlib-tests -## begin gnulib module strerror - - -EXTRA_DIST += strerror.c - -EXTRA_libtests_a_SOURCES += strerror.c - -## end gnulib module strerror - -## begin gnulib module strerror-override - - -EXTRA_DIST += strerror-override.c strerror-override.h - -EXTRA_libtests_a_SOURCES += strerror-override.c - -## end gnulib module strerror-override - ## begin gnulib module strerror-tests TESTS += test-strerror diff --git a/gl/tests/strerror-override.c b/gl/tests/strerror-override.c deleted file mode 100644 index d0ed2fb..0000000 --- a/gl/tests/strerror-override.c +++ /dev/null @@ -1,302 +0,0 @@ -/* strerror-override.c --- POSIX compatible system error routine - - Copyright (C) 2010-2013 Free Software Foundation, Inc. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - -/* Written by Bruno Haible , 2010. */ - -#include - -#include "strerror-override.h" - -#include - -#if GNULIB_defined_EWINSOCK /* native Windows platforms */ -# if HAVE_WINSOCK2_H -# include -# endif -#endif - -/* If ERRNUM maps to an errno value defined by gnulib, return a string - describing the error. Otherwise return NULL. */ -const char * -strerror_override (int errnum) -{ - /* These error messages are taken from glibc/sysdeps/gnu/errlist.c. */ - switch (errnum) - { -#if REPLACE_STRERROR_0 - case 0: - return "Success"; -#endif - -#if GNULIB_defined_ESOCK /* native Windows platforms with older */ - case EINPROGRESS: - return "Operation now in progress"; - case EALREADY: - return "Operation already in progress"; - case ENOTSOCK: - return "Socket operation on non-socket"; - case EDESTADDRREQ: - return "Destination address required"; - case EMSGSIZE: - return "Message too long"; - case EPROTOTYPE: - return "Protocol wrong type for socket"; - case ENOPROTOOPT: - return "Protocol not available"; - case EPROTONOSUPPORT: - return "Protocol not supported"; - case EOPNOTSUPP: - return "Operation not supported"; - case EAFNOSUPPORT: - return "Address family not supported by protocol"; - case EADDRINUSE: - return "Address already in use"; - case EADDRNOTAVAIL: - return "Cannot assign requested address"; - case ENETDOWN: - return "Network is down"; - case ENETUNREACH: - return "Network is unreachable"; - case ECONNRESET: - return "Connection reset by peer"; - case ENOBUFS: - return "No buffer space available"; - case EISCONN: - return "Transport endpoint is already connected"; - case ENOTCONN: - return "Transport endpoint is not connected"; - case ETIMEDOUT: - return "Connection timed out"; - case ECONNREFUSED: - return "Connection refused"; - case ELOOP: - return "Too many levels of symbolic links"; - case EHOSTUNREACH: - return "No route to host"; - case EWOULDBLOCK: - return "Operation would block"; -#endif -#if GNULIB_defined_ESTREAMS /* native Windows platforms with older */ - case ETXTBSY: - return "Text file busy"; - case ENODATA: - return "No data available"; - case ENOSR: - return "Out of streams resources"; - case ENOSTR: - return "Device not a stream"; - case ETIME: - return "Timer expired"; - case EOTHER: - return "Other error"; -#endif -#if GNULIB_defined_EWINSOCK /* native Windows platforms */ - case ESOCKTNOSUPPORT: - return "Socket type not supported"; - case EPFNOSUPPORT: - return "Protocol family not supported"; - case ESHUTDOWN: - return "Cannot send after transport endpoint shutdown"; - case ETOOMANYREFS: - return "Too many references: cannot splice"; - case EHOSTDOWN: - return "Host is down"; - case EPROCLIM: - return "Too many processes"; - case EUSERS: - return "Too many users"; - case EDQUOT: - return "Disk quota exceeded"; - case ESTALE: - return "Stale NFS file handle"; - case EREMOTE: - return "Object is remote"; -# if HAVE_WINSOCK2_H - /* WSA_INVALID_HANDLE maps to EBADF */ - /* WSA_NOT_ENOUGH_MEMORY maps to ENOMEM */ - /* WSA_INVALID_PARAMETER maps to EINVAL */ - case WSA_OPERATION_ABORTED: - return "Overlapped operation aborted"; - case WSA_IO_INCOMPLETE: - return "Overlapped I/O event object not in signaled state"; - case WSA_IO_PENDING: - return "Overlapped operations will complete later"; - /* WSAEINTR maps to EINTR */ - /* WSAEBADF maps to EBADF */ - /* WSAEACCES maps to EACCES */ - /* WSAEFAULT maps to EFAULT */ - /* WSAEINVAL maps to EINVAL */ - /* WSAEMFILE maps to EMFILE */ - /* WSAEWOULDBLOCK maps to EWOULDBLOCK */ - /* WSAEINPROGRESS maps to EINPROGRESS */ - /* WSAEALREADY maps to EALREADY */ - /* WSAENOTSOCK maps to ENOTSOCK */ - /* WSAEDESTADDRREQ maps to EDESTADDRREQ */ - /* WSAEMSGSIZE maps to EMSGSIZE */ - /* WSAEPROTOTYPE maps to EPROTOTYPE */ - /* WSAENOPROTOOPT maps to ENOPROTOOPT */ - /* WSAEPROTONOSUPPORT maps to EPROTONOSUPPORT */ - /* WSAESOCKTNOSUPPORT is ESOCKTNOSUPPORT */ - /* WSAEOPNOTSUPP maps to EOPNOTSUPP */ - /* WSAEPFNOSUPPORT is EPFNOSUPPORT */ - /* WSAEAFNOSUPPORT maps to EAFNOSUPPORT */ - /* WSAEADDRINUSE maps to EADDRINUSE */ - /* WSAEADDRNOTAVAIL maps to EADDRNOTAVAIL */ - /* WSAENETDOWN maps to ENETDOWN */ - /* WSAENETUNREACH maps to ENETUNREACH */ - /* WSAENETRESET maps to ENETRESET */ - /* WSAECONNABORTED maps to ECONNABORTED */ - /* WSAECONNRESET maps to ECONNRESET */ - /* WSAENOBUFS maps to ENOBUFS */ - /* WSAEISCONN maps to EISCONN */ - /* WSAENOTCONN maps to ENOTCONN */ - /* WSAESHUTDOWN is ESHUTDOWN */ - /* WSAETOOMANYREFS is ETOOMANYREFS */ - /* WSAETIMEDOUT maps to ETIMEDOUT */ - /* WSAECONNREFUSED maps to ECONNREFUSED */ - /* WSAELOOP maps to ELOOP */ - /* WSAENAMETOOLONG maps to ENAMETOOLONG */ - /* WSAEHOSTDOWN is EHOSTDOWN */ - /* WSAEHOSTUNREACH maps to EHOSTUNREACH */ - /* WSAENOTEMPTY maps to ENOTEMPTY */ - /* WSAEPROCLIM is EPROCLIM */ - /* WSAEUSERS is EUSERS */ - /* WSAEDQUOT is EDQUOT */ - /* WSAESTALE is ESTALE */ - /* WSAEREMOTE is EREMOTE */ - case WSASYSNOTREADY: - return "Network subsystem is unavailable"; - case WSAVERNOTSUPPORTED: - return "Winsock.dll version out of range"; - case WSANOTINITIALISED: - return "Successful WSAStartup not yet performed"; - case WSAEDISCON: - return "Graceful shutdown in progress"; - case WSAENOMORE: case WSA_E_NO_MORE: - return "No more results"; - case WSAECANCELLED: case WSA_E_CANCELLED: - return "Call was canceled"; - case WSAEINVALIDPROCTABLE: - return "Procedure call table is invalid"; - case WSAEINVALIDPROVIDER: - return "Service provider is invalid"; - case WSAEPROVIDERFAILEDINIT: - return "Service provider failed to initialize"; - case WSASYSCALLFAILURE: - return "System call failure"; - case WSASERVICE_NOT_FOUND: - return "Service not found"; - case WSATYPE_NOT_FOUND: - return "Class type not found"; - case WSAEREFUSED: - return "Database query was refused"; - case WSAHOST_NOT_FOUND: - return "Host not found"; - case WSATRY_AGAIN: - return "Nonauthoritative host not found"; - case WSANO_RECOVERY: - return "Nonrecoverable error"; - case WSANO_DATA: - return "Valid name, no data record of requested type"; - /* WSA_QOS_* omitted */ -# endif -#endif - -#if GNULIB_defined_ENOMSG - case ENOMSG: - return "No message of desired type"; -#endif - -#if GNULIB_defined_EIDRM - case EIDRM: - return "Identifier removed"; -#endif - -#if GNULIB_defined_ENOLINK - case ENOLINK: - return "Link has been severed"; -#endif - -#if GNULIB_defined_EPROTO - case EPROTO: - return "Protocol error"; -#endif - -#if GNULIB_defined_EMULTIHOP - case EMULTIHOP: - return "Multihop attempted"; -#endif - -#if GNULIB_defined_EBADMSG - case EBADMSG: - return "Bad message"; -#endif - -#if GNULIB_defined_EOVERFLOW - case EOVERFLOW: - return "Value too large for defined data type"; -#endif - -#if GNULIB_defined_ENOTSUP - case ENOTSUP: - return "Not supported"; -#endif - -#if GNULIB_defined_ENETRESET - case ENETRESET: - return "Network dropped connection on reset"; -#endif - -#if GNULIB_defined_ECONNABORTED - case ECONNABORTED: - return "Software caused connection abort"; -#endif - -#if GNULIB_defined_ESTALE - case ESTALE: - return "Stale NFS file handle"; -#endif - -#if GNULIB_defined_EDQUOT - case EDQUOT: - return "Disk quota exceeded"; -#endif - -#if GNULIB_defined_ECANCELED - case ECANCELED: - return "Operation canceled"; -#endif - -#if GNULIB_defined_EOWNERDEAD - case EOWNERDEAD: - return "Owner died"; -#endif - -#if GNULIB_defined_ENOTRECOVERABLE - case ENOTRECOVERABLE: - return "State not recoverable"; -#endif - -#if GNULIB_defined_EILSEQ - case EILSEQ: - return "Invalid or incomplete multibyte or wide character"; -#endif - - default: - return NULL; - } -} diff --git a/gl/tests/strerror-override.h b/gl/tests/strerror-override.h deleted file mode 100644 index 0d086b8..0000000 --- a/gl/tests/strerror-override.h +++ /dev/null @@ -1,56 +0,0 @@ -/* strerror-override.h --- POSIX compatible system error routine - - Copyright (C) 2010-2013 Free Software Foundation, Inc. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - -#ifndef _GL_STRERROR_OVERRIDE_H -# define _GL_STRERROR_OVERRIDE_H - -# include -# include - -/* Reasonable buffer size that should never trigger ERANGE; if this - proves too small, we intentionally abort(), to remind us to fix - this value. */ -# define STACKBUF_LEN 256 - -/* If ERRNUM maps to an errno value defined by gnulib, return a string - describing the error. Otherwise return NULL. */ -# if REPLACE_STRERROR_0 \ - || GNULIB_defined_ESOCK \ - || GNULIB_defined_ESTREAMS \ - || GNULIB_defined_EWINSOCK \ - || GNULIB_defined_ENOMSG \ - || GNULIB_defined_EIDRM \ - || GNULIB_defined_ENOLINK \ - || GNULIB_defined_EPROTO \ - || GNULIB_defined_EMULTIHOP \ - || GNULIB_defined_EBADMSG \ - || GNULIB_defined_EOVERFLOW \ - || GNULIB_defined_ENOTSUP \ - || GNULIB_defined_ENETRESET \ - || GNULIB_defined_ECONNABORTED \ - || GNULIB_defined_ESTALE \ - || GNULIB_defined_EDQUOT \ - || GNULIB_defined_ECANCELED \ - || GNULIB_defined_EOWNERDEAD \ - || GNULIB_defined_ENOTRECOVERABLE \ - || GNULIB_defined_EILSEQ -extern const char *strerror_override (int errnum) _GL_ATTRIBUTE_CONST; -# else -# define strerror_override(ignored) NULL -# endif - -#endif /* _GL_STRERROR_OVERRIDE_H */ diff --git a/gl/tests/strerror.c b/gl/tests/strerror.c deleted file mode 100644 index 80a2f2e..0000000 --- a/gl/tests/strerror.c +++ /dev/null @@ -1,70 +0,0 @@ -/* strerror.c --- POSIX compatible system error routine - - Copyright (C) 2007-2013 Free Software Foundation, Inc. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - -#include - -/* Specification. */ -#include - -#include -#include -#include -#include - -#include "intprops.h" -#include "strerror-override.h" -#include "verify.h" - -/* Use the system functions, not the gnulib overrides in this file. */ -#undef sprintf - -char * -strerror (int n) -#undef strerror -{ - static char buf[STACKBUF_LEN]; - size_t len; - - /* Cast away const, due to the historical signature of strerror; - callers should not be modifying the string. */ - const char *msg = strerror_override (n); - if (msg) - return (char *) msg; - - msg = strerror (n); - - /* Our strerror_r implementation might use the system's strerror - buffer, so all other clients of strerror have to see the error - copied into a buffer that we manage. This is not thread-safe, - even if the system strerror is, but portable programs shouldn't - be using strerror if they care about thread-safety. */ - if (!msg || !*msg) - { - static char const fmt[] = "Unknown error %d"; - verify (sizeof buf >= sizeof (fmt) + INT_STRLEN_BOUND (n)); - sprintf (buf, fmt, n); - errno = EINVAL; - return buf; - } - - /* Fix STACKBUF_LEN if this ever aborts. */ - len = strlen (msg); - if (sizeof buf <= len) - abort (); - - return memcpy (buf, msg, len + 1); -} -- 1.7.1