[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] strerror: avoid warnings about discarding "const"
From: |
Jim Meyering |
Subject: |
[PATCH] strerror: avoid warnings about discarding "const" |
Date: |
Fri, 16 Jan 2009 12:11:12 +0100 |
I'd like to push this today.
Speak now if you object ;-)
>From 7d9de4da85365b7b66d697f0b11ce93e416c7fd7 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Fri, 16 Jan 2009 12:09:48 +0100
Subject: [PATCH] strerror: avoid warnings about discarding "const"
* lib/strerror.c (rpl_strerror): Instead of returning a const
string from each and every "case", use a variable, and add a single
cast after the switch.
---
lib/strerror.c | 134 +++++++++++++++++++++++++++++---------------------------
1 files changed, 69 insertions(+), 65 deletions(-)
diff --git a/lib/strerror.c b/lib/strerror.c
index 787575f..8103c80 100644
--- a/lib/strerror.c
+++ b/lib/strerror.c
@@ -1,6 +1,6 @@
/* strerror.c --- POSIX compatible system error routine
- Copyright (C) 2007-2008 Free Software Foundation, Inc.
+ Copyright (C) 2007-2009 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
@@ -40,94 +40,95 @@
char *
rpl_strerror (int n)
{
+ char const *m = NULL;
/* These error messages are taken from glibc/sysdeps/gnu/errlist.c. */
switch (n)
{
# if GNULIB_defined_ETXTBSY
case ETXTBSY:
- return "Text file busy";
+ m = "Text file busy";
# endif
# if GNULIB_defined_ESOCK /* native Windows platforms */
/* EWOULDBLOCK is the same as EAGAIN. */
case EINPROGRESS:
- return "Operation now in progress";
+ m = "Operation now in progress";
case EALREADY:
- return "Operation already in progress";
+ m = "Operation already in progress";
case ENOTSOCK:
- return "Socket operation on non-socket";
+ m = "Socket operation on non-socket";
case EDESTADDRREQ:
- return "Destination address required";
+ m = "Destination address required";
case EMSGSIZE:
- return "Message too long";
+ m = "Message too long";
case EPROTOTYPE:
- return "Protocol wrong type for socket";
+ m = "Protocol wrong type for socket";
case ENOPROTOOPT:
- return "Protocol not available";
+ m = "Protocol not available";
case EPROTONOSUPPORT:
- return "Protocol not supported";
+ m = "Protocol not supported";
case ESOCKTNOSUPPORT:
- return "Socket type not supported";
+ m = "Socket type not supported";
case EOPNOTSUPP:
- return "Operation not supported";
+ m = "Operation not supported";
case EPFNOSUPPORT:
- return "Protocol family not supported";
+ m = "Protocol family not supported";
case EAFNOSUPPORT:
- return "Address family not supported by protocol";
+ m = "Address family not supported by protocol";
case EADDRINUSE:
- return "Address already in use";
+ m = "Address already in use";
case EADDRNOTAVAIL:
- return "Cannot assign requested address";
+ m = "Cannot assign requested address";
case ENETDOWN:
- return "Network is down";
+ m = "Network is down";
case ENETUNREACH:
- return "Network is unreachable";
+ m = "Network is unreachable";
case ENETRESET:
- return "Network dropped connection on reset";
+ m = "Network dropped connection on reset";
case ECONNABORTED:
- return "Software caused connection abort";
+ m = "Software caused connection abort";
case ECONNRESET:
- return "Connection reset by peer";
+ m = "Connection reset by peer";
case ENOBUFS:
- return "No buffer space available";
+ m = "No buffer space available";
case EISCONN:
- return "Transport endpoint is already connected";
+ m = "Transport endpoint is already connected";
case ENOTCONN:
- return "Transport endpoint is not connected";
+ m = "Transport endpoint is not connected";
case ESHUTDOWN:
- return "Cannot send after transport endpoint shutdown";
+ m = "Cannot send after transport endpoint shutdown";
case ETOOMANYREFS:
- return "Too many references: cannot splice";
+ m = "Too many references: cannot splice";
case ETIMEDOUT:
- return "Connection timed out";
+ m = "Connection timed out";
case ECONNREFUSED:
- return "Connection refused";
+ m = "Connection refused";
case ELOOP:
- return "Too many levels of symbolic links";
+ m = "Too many levels of symbolic links";
case EHOSTDOWN:
- return "Host is down";
+ m = "Host is down";
case EHOSTUNREACH:
- return "No route to host";
+ m = "No route to host";
case EPROCLIM:
- return "Too many processes";
+ m = "Too many processes";
case EUSERS:
- return "Too many users";
+ m = "Too many users";
case EDQUOT:
- return "Disk quota exceeded";
+ m = "Disk quota exceeded";
case ESTALE:
- return "Stale NFS file handle";
+ m = "Stale NFS file handle";
case EREMOTE:
- return "Object is remote";
+ m = "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";
+ m = "Overlapped operation aborted";
case WSA_IO_INCOMPLETE:
- return "Overlapped I/O event object not in signaled state";
+ m = "Overlapped I/O event object not in signaled state";
case WSA_IO_PENDING:
- return "Overlapped operations will complete later";
+ m = "Overlapped operations will complete later";
/* WSAEINTR maps to EINTR */
/* WSAEBADF maps to EBADF */
/* WSAEACCES maps to EACCES */
@@ -172,89 +173,92 @@ rpl_strerror (int n)
/* WSAESTALE is ESTALE */
/* WSAEREMOTE is EREMOTE */
case WSASYSNOTREADY:
- return "Network subsystem is unavailable";
+ m = "Network subsystem is unavailable";
case WSAVERNOTSUPPORTED:
- return "Winsock.dll version out of range";
+ m = "Winsock.dll version out of range";
case WSANOTINITIALISED:
- return "Successful WSAStartup not yet performed";
+ m = "Successful WSAStartup not yet performed";
case WSAEDISCON:
- return "Graceful shutdown in progress";
+ m = "Graceful shutdown in progress";
case WSAENOMORE: case WSA_E_NO_MORE:
- return "No more results";
+ m = "No more results";
case WSAECANCELLED: case WSA_E_CANCELLED:
- return "Call was canceled";
+ m = "Call was canceled";
case WSAEINVALIDPROCTABLE:
- return "Procedure call table is invalid";
+ m = "Procedure call table is invalid";
case WSAEINVALIDPROVIDER:
- return "Service provider is invalid";
+ m = "Service provider is invalid";
case WSAEPROVIDERFAILEDINIT:
- return "Service provider failed to initialize";
+ m = "Service provider failed to initialize";
case WSASYSCALLFAILURE:
- return "System call failure";
+ m = "System call failure";
case WSASERVICE_NOT_FOUND:
- return "Service not found";
+ m = "Service not found";
case WSATYPE_NOT_FOUND:
- return "Class type not found";
+ m = "Class type not found";
case WSAEREFUSED:
- return "Database query was refused";
+ m = "Database query was refused";
case WSAHOST_NOT_FOUND:
- return "Host not found";
+ m = "Host not found";
case WSATRY_AGAIN:
- return "Nonauthoritative host not found";
+ m = "Nonauthoritative host not found";
case WSANO_RECOVERY:
- return "Nonrecoverable error";
+ m = "Nonrecoverable error";
case WSANO_DATA:
- return "Valid name, no data record of requested type";
+ m = "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";
+ m = "No message of desired type";
# endif
# if GNULIB_defined_EIDRM
case EIDRM:
- return "Identifier removed";
+ m = "Identifier removed";
# endif
# if GNULIB_defined_ENOLINK
case ENOLINK:
- return "Link has been severed";
+ m = "Link has been severed";
# endif
# if GNULIB_defined_EPROTO
case EPROTO:
- return "Protocol error";
+ m = "Protocol error";
# endif
# if GNULIB_defined_EMULTIHOP
case EMULTIHOP:
- return "Multihop attempted";
+ m = "Multihop attempted";
# endif
# if GNULIB_defined_EBADMSG
case EBADMSG:
- return "Bad message";
+ m = "Bad message";
# endif
# if GNULIB_defined_EOVERFLOW
case EOVERFLOW:
- return "Value too large for defined data type";
+ m = "Value too large for defined data type";
# endif
# if GNULIB_defined_ENOTSUP
case ENOTSUP:
- return "Not supported";
+ m = "Not supported";
# endif
# if GNULIB_defined_
case ECANCELED:
- return "Operation canceled";
+ m = "Operation canceled";
# endif
}
+ if (m)
+ return (char *) m;
+
{
char *result = strerror (n);
--
1.6.1.258.g7ff14