Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 492752
Collapse All | Expand All

(-)a/gl/Makefile.am (-1 / +19 lines)
Lines 21-27 Link Here
21
# the same distribution terms as the rest of that program.
21
# the same distribution terms as the rest of that program.
22
#
22
#
23
# Generated by gnulib-tool.
23
# Generated by gnulib-tool.
24
# 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
24
# 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
25
25
26
AUTOMAKE_OPTIONS = 1.9.6 gnits
26
AUTOMAKE_OPTIONS = 1.9.6 gnits
27
27
Lines 1218-1223 EXTRA_libgnu_la_SOURCES += strdup.c Link Here
1218
1218
1219
## end   gnulib module strdup-posix
1219
## end   gnulib module strdup-posix
1220
1220
1221
## begin gnulib module strerror
1222
1223
1224
EXTRA_DIST += strerror.c
1225
1226
EXTRA_libgnu_la_SOURCES += strerror.c
1227
1228
## end   gnulib module strerror
1229
1230
## begin gnulib module strerror-override
1231
1232
1233
EXTRA_DIST += strerror-override.c strerror-override.h
1234
1235
EXTRA_libgnu_la_SOURCES += strerror-override.c
1236
1237
## end   gnulib module strerror-override
1238
1221
## begin gnulib module string
1239
## begin gnulib module string
1222
1240
1223
BUILT_SOURCES += string.h
1241
BUILT_SOURCES += string.h
(-)a/gl/m4/gnulib-cache.m4 (-1 / +2 lines)
Lines 27-33 Link Here
27
27
28
28
29
# Specification in the form of a command-line invocation:
29
# Specification in the form of a command-line invocation:
30
#   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
30
#   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
31
31
32
# Specification in the form of a few gnulib-tool.m4 macro invocations:
32
# Specification in the form of a few gnulib-tool.m4 macro invocations:
33
gl_LOCAL_DIR([gl/override])
33
gl_LOCAL_DIR([gl/override])
Lines 78-83 gl_MODULES([ Link Here
78
  socklen
78
  socklen
79
  stdint
79
  stdint
80
  strcase
80
  strcase
81
  strerror
81
  strndup
82
  strndup
82
  strtok_r
83
  strtok_r
83
  strverscmp
84
  strverscmp
(-)a/gl/m4/gnulib-comp.m4 (-15 / +15 lines)
Lines 563-568 AC_SUBST([LTALLOCA]) Link Here
563
    gl_PREREQ_STRDUP
563
    gl_PREREQ_STRDUP
564
  fi
564
  fi
565
  gl_STRING_MODULE_INDICATOR([strdup])
565
  gl_STRING_MODULE_INDICATOR([strdup])
566
  gl_FUNC_STRERROR
567
  if test $REPLACE_STRERROR = 1; then
568
    AC_LIBOBJ([strerror])
569
  fi
570
  gl_MODULE_INDICATOR([strerror])
571
  gl_STRING_MODULE_INDICATOR([strerror])
572
  AC_REQUIRE([gl_HEADER_ERRNO_H])
573
  AC_REQUIRE([gl_FUNC_STRERROR_0])
574
  if test -n "$ERRNO_H" || test $REPLACE_STRERROR_0 = 1; then
575
    AC_LIBOBJ([strerror-override])
576
    gl_PREREQ_SYS_H_WINSOCK2
577
  fi
566
  gl_HEADER_STRING_H
578
  gl_HEADER_STRING_H
567
  gl_HEADER_STRINGS_H
579
  gl_HEADER_STRINGS_H
568
  gl_FUNC_STRNDUP
580
  gl_FUNC_STRNDUP
Lines 745-762 changequote([, ])dnl Link Here
745
  gl_SYS_STAT_MODULE_INDICATOR([stat])
757
  gl_SYS_STAT_MODULE_INDICATOR([stat])
746
  AC_REQUIRE([gt_TYPE_WCHAR_T])
758
  AC_REQUIRE([gt_TYPE_WCHAR_T])
747
  AC_REQUIRE([gt_TYPE_WINT_T])
759
  AC_REQUIRE([gt_TYPE_WINT_T])
748
  gl_FUNC_STRERROR
749
  if test $REPLACE_STRERROR = 1; then
750
    AC_LIBOBJ([strerror])
751
  fi
752
  gl_MODULE_INDICATOR([strerror])
753
  gl_STRING_MODULE_INDICATOR([strerror])
754
  AC_REQUIRE([gl_HEADER_ERRNO_H])
755
  AC_REQUIRE([gl_FUNC_STRERROR_0])
756
  if test -n "$ERRNO_H" || test $REPLACE_STRERROR_0 = 1; then
757
    AC_LIBOBJ([strerror-override])
758
    gl_PREREQ_SYS_H_WINSOCK2
759
  fi
760
  gl_FUNC_STRERROR_R
760
  gl_FUNC_STRERROR_R
761
  if test $HAVE_DECL_STRERROR_R = 0 || test $REPLACE_STRERROR_R = 1; then
761
  if test $HAVE_DECL_STRERROR_R = 0 || test $REPLACE_STRERROR_R = 1; then
762
    AC_LIBOBJ([strerror_r])
762
    AC_LIBOBJ([strerror_r])
Lines 966-971 AC_DEFUN([gl_FILE_LIST], [ Link Here
966
  lib/str-two-way.h
966
  lib/str-two-way.h
967
  lib/strcasecmp.c
967
  lib/strcasecmp.c
968
  lib/strdup.c
968
  lib/strdup.c
969
  lib/strerror-override.c
970
  lib/strerror-override.h
971
  lib/strerror.c
969
  lib/string.in.h
972
  lib/string.in.h
970
  lib/strings.in.h
973
  lib/strings.in.h
971
  lib/strncasecmp.c
974
  lib/strncasecmp.c
Lines 1285-1293 AC_DEFUN([gl_FILE_LIST], [ Link Here
1285
  tests=lib/pipe.c
1288
  tests=lib/pipe.c
1286
  tests=lib/same-inode.h
1289
  tests=lib/same-inode.h
1287
  tests=lib/stat.c
1290
  tests=lib/stat.c
1288
  tests=lib/strerror-override.c
1289
  tests=lib/strerror-override.h
1290
  tests=lib/strerror.c
1291
  tests=lib/strerror_r.c
1291
  tests=lib/strerror_r.c
1292
  tests=lib/symlink.c
1292
  tests=lib/symlink.c
1293
  tests=lib/sys_ioctl.in.h
1293
  tests=lib/sys_ioctl.in.h
(-)a/gl/strerror-override.c (+302 lines)
Line 0 Link Here
1
/* strerror-override.c --- POSIX compatible system error routine
2
3
   Copyright (C) 2010-2013 Free Software Foundation, Inc.
4
5
   This program is free software: you can redistribute it and/or modify
6
   it under the terms of the GNU Lesser General Public License as published by
7
   the Free Software Foundation; either version 2.1 of the License, or
8
   (at your option) any later version.
9
10
   This program is distributed in the hope that it will be useful,
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
   GNU Lesser General Public License for more details.
14
15
   You should have received a copy of the GNU Lesser General Public License
16
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
17
18
/* Written by Bruno Haible <bruno@clisp.org>, 2010.  */
19
20
#include <config.h>
21
22
#include "strerror-override.h"
23
24
#include <errno.h>
25
26
#if GNULIB_defined_EWINSOCK /* native Windows platforms */
27
# if HAVE_WINSOCK2_H
28
#  include <winsock2.h>
29
# endif
30
#endif
31
32
/* If ERRNUM maps to an errno value defined by gnulib, return a string
33
   describing the error.  Otherwise return NULL.  */
34
const char *
35
strerror_override (int errnum)
36
{
37
  /* These error messages are taken from glibc/sysdeps/gnu/errlist.c.  */
38
  switch (errnum)
39
    {
40
#if REPLACE_STRERROR_0
41
    case 0:
42
      return "Success";
43
#endif
44
45
#if GNULIB_defined_ESOCK /* native Windows platforms with older <errno.h> */
46
    case EINPROGRESS:
47
      return "Operation now in progress";
48
    case EALREADY:
49
      return "Operation already in progress";
50
    case ENOTSOCK:
51
      return "Socket operation on non-socket";
52
    case EDESTADDRREQ:
53
      return "Destination address required";
54
    case EMSGSIZE:
55
      return "Message too long";
56
    case EPROTOTYPE:
57
      return "Protocol wrong type for socket";
58
    case ENOPROTOOPT:
59
      return "Protocol not available";
60
    case EPROTONOSUPPORT:
61
      return "Protocol not supported";
62
    case EOPNOTSUPP:
63
      return "Operation not supported";
64
    case EAFNOSUPPORT:
65
      return "Address family not supported by protocol";
66
    case EADDRINUSE:
67
      return "Address already in use";
68
    case EADDRNOTAVAIL:
69
      return "Cannot assign requested address";
70
    case ENETDOWN:
71
      return "Network is down";
72
    case ENETUNREACH:
73
      return "Network is unreachable";
74
    case ECONNRESET:
75
      return "Connection reset by peer";
76
    case ENOBUFS:
77
      return "No buffer space available";
78
    case EISCONN:
79
      return "Transport endpoint is already connected";
80
    case ENOTCONN:
81
      return "Transport endpoint is not connected";
82
    case ETIMEDOUT:
83
      return "Connection timed out";
84
    case ECONNREFUSED:
85
      return "Connection refused";
86
    case ELOOP:
87
      return "Too many levels of symbolic links";
88
    case EHOSTUNREACH:
89
      return "No route to host";
90
    case EWOULDBLOCK:
91
      return "Operation would block";
92
#endif
93
#if GNULIB_defined_ESTREAMS /* native Windows platforms with older <errno.h> */
94
    case ETXTBSY:
95
      return "Text file busy";
96
    case ENODATA:
97
      return "No data available";
98
    case ENOSR:
99
      return "Out of streams resources";
100
    case ENOSTR:
101
      return "Device not a stream";
102
    case ETIME:
103
      return "Timer expired";
104
    case EOTHER:
105
      return "Other error";
106
#endif
107
#if GNULIB_defined_EWINSOCK /* native Windows platforms */
108
    case ESOCKTNOSUPPORT:
109
      return "Socket type not supported";
110
    case EPFNOSUPPORT:
111
      return "Protocol family not supported";
112
    case ESHUTDOWN:
113
      return "Cannot send after transport endpoint shutdown";
114
    case ETOOMANYREFS:
115
      return "Too many references: cannot splice";
116
    case EHOSTDOWN:
117
      return "Host is down";
118
    case EPROCLIM:
119
      return "Too many processes";
120
    case EUSERS:
121
      return "Too many users";
122
    case EDQUOT:
123
      return "Disk quota exceeded";
124
    case ESTALE:
125
      return "Stale NFS file handle";
126
    case EREMOTE:
127
      return "Object is remote";
128
# if HAVE_WINSOCK2_H
129
      /* WSA_INVALID_HANDLE maps to EBADF */
130
      /* WSA_NOT_ENOUGH_MEMORY maps to ENOMEM */
131
      /* WSA_INVALID_PARAMETER maps to EINVAL */
132
    case WSA_OPERATION_ABORTED:
133
      return "Overlapped operation aborted";
134
    case WSA_IO_INCOMPLETE:
135
      return "Overlapped I/O event object not in signaled state";
136
    case WSA_IO_PENDING:
137
      return "Overlapped operations will complete later";
138
      /* WSAEINTR maps to EINTR */
139
      /* WSAEBADF maps to EBADF */
140
      /* WSAEACCES maps to EACCES */
141
      /* WSAEFAULT maps to EFAULT */
142
      /* WSAEINVAL maps to EINVAL */
143
      /* WSAEMFILE maps to EMFILE */
144
      /* WSAEWOULDBLOCK maps to EWOULDBLOCK */
145
      /* WSAEINPROGRESS maps to EINPROGRESS */
146
      /* WSAEALREADY maps to EALREADY */
147
      /* WSAENOTSOCK maps to ENOTSOCK */
148
      /* WSAEDESTADDRREQ maps to EDESTADDRREQ */
149
      /* WSAEMSGSIZE maps to EMSGSIZE */
150
      /* WSAEPROTOTYPE maps to EPROTOTYPE */
151
      /* WSAENOPROTOOPT maps to ENOPROTOOPT */
152
      /* WSAEPROTONOSUPPORT maps to EPROTONOSUPPORT */
153
      /* WSAESOCKTNOSUPPORT is ESOCKTNOSUPPORT */
154
      /* WSAEOPNOTSUPP maps to EOPNOTSUPP */
155
      /* WSAEPFNOSUPPORT is EPFNOSUPPORT */
156
      /* WSAEAFNOSUPPORT maps to EAFNOSUPPORT */
157
      /* WSAEADDRINUSE maps to EADDRINUSE */
158
      /* WSAEADDRNOTAVAIL maps to EADDRNOTAVAIL */
159
      /* WSAENETDOWN maps to ENETDOWN */
160
      /* WSAENETUNREACH maps to ENETUNREACH */
161
      /* WSAENETRESET maps to ENETRESET */
162
      /* WSAECONNABORTED maps to ECONNABORTED */
163
      /* WSAECONNRESET maps to ECONNRESET */
164
      /* WSAENOBUFS maps to ENOBUFS */
165
      /* WSAEISCONN maps to EISCONN */
166
      /* WSAENOTCONN maps to ENOTCONN */
167
      /* WSAESHUTDOWN is ESHUTDOWN */
168
      /* WSAETOOMANYREFS is ETOOMANYREFS */
169
      /* WSAETIMEDOUT maps to ETIMEDOUT */
170
      /* WSAECONNREFUSED maps to ECONNREFUSED */
171
      /* WSAELOOP maps to ELOOP */
172
      /* WSAENAMETOOLONG maps to ENAMETOOLONG */
173
      /* WSAEHOSTDOWN is EHOSTDOWN */
174
      /* WSAEHOSTUNREACH maps to EHOSTUNREACH */
175
      /* WSAENOTEMPTY maps to ENOTEMPTY */
176
      /* WSAEPROCLIM is EPROCLIM */
177
      /* WSAEUSERS is EUSERS */
178
      /* WSAEDQUOT is EDQUOT */
179
      /* WSAESTALE is ESTALE */
180
      /* WSAEREMOTE is EREMOTE */
181
    case WSASYSNOTREADY:
182
      return "Network subsystem is unavailable";
183
    case WSAVERNOTSUPPORTED:
184
      return "Winsock.dll version out of range";
185
    case WSANOTINITIALISED:
186
      return "Successful WSAStartup not yet performed";
187
    case WSAEDISCON:
188
      return "Graceful shutdown in progress";
189
    case WSAENOMORE: case WSA_E_NO_MORE:
190
      return "No more results";
191
    case WSAECANCELLED: case WSA_E_CANCELLED:
192
      return "Call was canceled";
193
    case WSAEINVALIDPROCTABLE:
194
      return "Procedure call table is invalid";
195
    case WSAEINVALIDPROVIDER:
196
      return "Service provider is invalid";
197
    case WSAEPROVIDERFAILEDINIT:
198
      return "Service provider failed to initialize";
199
    case WSASYSCALLFAILURE:
200
      return "System call failure";
201
    case WSASERVICE_NOT_FOUND:
202
      return "Service not found";
203
    case WSATYPE_NOT_FOUND:
204
      return "Class type not found";
205
    case WSAEREFUSED:
206
      return "Database query was refused";
207
    case WSAHOST_NOT_FOUND:
208
      return "Host not found";
209
    case WSATRY_AGAIN:
210
      return "Nonauthoritative host not found";
211
    case WSANO_RECOVERY:
212
      return "Nonrecoverable error";
213
    case WSANO_DATA:
214
      return "Valid name, no data record of requested type";
215
      /* WSA_QOS_* omitted */
216
# endif
217
#endif
218
219
#if GNULIB_defined_ENOMSG
220
    case ENOMSG:
221
      return "No message of desired type";
222
#endif
223
224
#if GNULIB_defined_EIDRM
225
    case EIDRM:
226
      return "Identifier removed";
227
#endif
228
229
#if GNULIB_defined_ENOLINK
230
    case ENOLINK:
231
      return "Link has been severed";
232
#endif
233
234
#if GNULIB_defined_EPROTO
235
    case EPROTO:
236
      return "Protocol error";
237
#endif
238
239
#if GNULIB_defined_EMULTIHOP
240
    case EMULTIHOP:
241
      return "Multihop attempted";
242
#endif
243
244
#if GNULIB_defined_EBADMSG
245
    case EBADMSG:
246
      return "Bad message";
247
#endif
248
249
#if GNULIB_defined_EOVERFLOW
250
    case EOVERFLOW:
251
      return "Value too large for defined data type";
252
#endif
253
254
#if GNULIB_defined_ENOTSUP
255
    case ENOTSUP:
256
      return "Not supported";
257
#endif
258
259
#if GNULIB_defined_ENETRESET
260
    case ENETRESET:
261
      return "Network dropped connection on reset";
262
#endif
263
264
#if GNULIB_defined_ECONNABORTED
265
    case ECONNABORTED:
266
      return "Software caused connection abort";
267
#endif
268
269
#if GNULIB_defined_ESTALE
270
    case ESTALE:
271
      return "Stale NFS file handle";
272
#endif
273
274
#if GNULIB_defined_EDQUOT
275
    case EDQUOT:
276
      return "Disk quota exceeded";
277
#endif
278
279
#if GNULIB_defined_ECANCELED
280
    case ECANCELED:
281
      return "Operation canceled";
282
#endif
283
284
#if GNULIB_defined_EOWNERDEAD
285
    case EOWNERDEAD:
286
      return "Owner died";
287
#endif
288
289
#if GNULIB_defined_ENOTRECOVERABLE
290
    case ENOTRECOVERABLE:
291
      return "State not recoverable";
292
#endif
293
294
#if GNULIB_defined_EILSEQ
295
    case EILSEQ:
296
      return "Invalid or incomplete multibyte or wide character";
297
#endif
298
299
    default:
300
      return NULL;
301
    }
302
}
(-)a/gl/strerror-override.h (+56 lines)
Line 0 Link Here
1
/* strerror-override.h --- POSIX compatible system error routine
2
3
   Copyright (C) 2010-2013 Free Software Foundation, Inc.
4
5
   This program is free software: you can redistribute it and/or modify
6
   it under the terms of the GNU Lesser General Public License as published by
7
   the Free Software Foundation; either version 2.1 of the License, or
8
   (at your option) any later version.
9
10
   This program is distributed in the hope that it will be useful,
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
   GNU Lesser General Public License for more details.
14
15
   You should have received a copy of the GNU Lesser General Public License
16
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
17
18
#ifndef _GL_STRERROR_OVERRIDE_H
19
# define _GL_STRERROR_OVERRIDE_H
20
21
# include <errno.h>
22
# include <stddef.h>
23
24
/* Reasonable buffer size that should never trigger ERANGE; if this
25
   proves too small, we intentionally abort(), to remind us to fix
26
   this value.  */
27
# define STACKBUF_LEN 256
28
29
/* If ERRNUM maps to an errno value defined by gnulib, return a string
30
   describing the error.  Otherwise return NULL.  */
31
# if REPLACE_STRERROR_0 \
32
     || GNULIB_defined_ESOCK \
33
     || GNULIB_defined_ESTREAMS \
34
     || GNULIB_defined_EWINSOCK \
35
     || GNULIB_defined_ENOMSG \
36
     || GNULIB_defined_EIDRM \
37
     || GNULIB_defined_ENOLINK \
38
     || GNULIB_defined_EPROTO \
39
     || GNULIB_defined_EMULTIHOP \
40
     || GNULIB_defined_EBADMSG \
41
     || GNULIB_defined_EOVERFLOW \
42
     || GNULIB_defined_ENOTSUP \
43
     || GNULIB_defined_ENETRESET \
44
     || GNULIB_defined_ECONNABORTED \
45
     || GNULIB_defined_ESTALE \
46
     || GNULIB_defined_EDQUOT \
47
     || GNULIB_defined_ECANCELED \
48
     || GNULIB_defined_EOWNERDEAD \
49
     || GNULIB_defined_ENOTRECOVERABLE \
50
     || GNULIB_defined_EILSEQ
51
extern const char *strerror_override (int errnum) _GL_ATTRIBUTE_CONST;
52
# else
53
#  define strerror_override(ignored) NULL
54
# endif
55
56
#endif /* _GL_STRERROR_OVERRIDE_H */
(-)a/gl/strerror.c (+70 lines)
Line 0 Link Here
1
/* strerror.c --- POSIX compatible system error routine
2
3
   Copyright (C) 2007-2013 Free Software Foundation, Inc.
4
5
   This program is free software: you can redistribute it and/or modify
6
   it under the terms of the GNU Lesser General Public License as published by
7
   the Free Software Foundation; either version 2.1 of the License, or
8
   (at your option) any later version.
9
10
   This program is distributed in the hope that it will be useful,
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
   GNU Lesser General Public License for more details.
14
15
   You should have received a copy of the GNU Lesser General Public License
16
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
17
18
#include <config.h>
19
20
/* Specification.  */
21
#include <string.h>
22
23
#include <errno.h>
24
#include <stdio.h>
25
#include <stdlib.h>
26
#include <string.h>
27
28
#include "intprops.h"
29
#include "strerror-override.h"
30
#include "verify.h"
31
32
/* Use the system functions, not the gnulib overrides in this file.  */
33
#undef sprintf
34
35
char *
36
strerror (int n)
37
#undef strerror
38
{
39
  static char buf[STACKBUF_LEN];
40
  size_t len;
41
42
  /* Cast away const, due to the historical signature of strerror;
43
     callers should not be modifying the string.  */
44
  const char *msg = strerror_override (n);
45
  if (msg)
46
    return (char *) msg;
47
48
  msg = strerror (n);
49
50
  /* Our strerror_r implementation might use the system's strerror
51
     buffer, so all other clients of strerror have to see the error
52
     copied into a buffer that we manage.  This is not thread-safe,
53
     even if the system strerror is, but portable programs shouldn't
54
     be using strerror if they care about thread-safety.  */
55
  if (!msg || !*msg)
56
    {
57
      static char const fmt[] = "Unknown error %d";
58
      verify (sizeof buf >= sizeof (fmt) + INT_STRLEN_BOUND (n));
59
      sprintf (buf, fmt, n);
60
      errno = EINVAL;
61
      return buf;
62
    }
63
64
  /* Fix STACKBUF_LEN if this ever aborts.  */
65
  len = strlen (msg);
66
  if (sizeof buf <= len)
67
    abort ();
68
69
  return memcpy (buf, msg, len + 1);
70
}
(-)a/gl/tests/Makefile.am (-18 lines)
Lines 934-957 EXTRA_DIST += test-stdlib.c test-sys_wait.h Link Here
934
934
935
## end   gnulib module stdlib-tests
935
## end   gnulib module stdlib-tests
936
936
937
## begin gnulib module strerror
938
939
940
EXTRA_DIST += strerror.c
941
942
EXTRA_libtests_a_SOURCES += strerror.c
943
944
## end   gnulib module strerror
945
946
## begin gnulib module strerror-override
947
948
949
EXTRA_DIST += strerror-override.c strerror-override.h
950
951
EXTRA_libtests_a_SOURCES += strerror-override.c
952
953
## end   gnulib module strerror-override
954
955
## begin gnulib module strerror-tests
937
## begin gnulib module strerror-tests
956
938
957
TESTS += test-strerror
939
TESTS += test-strerror
(-)a/gl/tests/strerror-override.c (-302 lines)
Lines 1-302 Link Here
1
/* strerror-override.c --- POSIX compatible system error routine
2
3
   Copyright (C) 2010-2013 Free Software Foundation, Inc.
4
5
   This program is free software: you can redistribute it and/or modify
6
   it under the terms of the GNU General Public License as published by
7
   the Free Software Foundation; either version 3 of the License, or
8
   (at your option) any later version.
9
10
   This program is distributed in the hope that it will be useful,
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
   GNU General Public License for more details.
14
15
   You should have received a copy of the GNU General Public License
16
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
17
18
/* Written by Bruno Haible <bruno@clisp.org>, 2010.  */
19
20
#include <config.h>
21
22
#include "strerror-override.h"
23
24
#include <errno.h>
25
26
#if GNULIB_defined_EWINSOCK /* native Windows platforms */
27
# if HAVE_WINSOCK2_H
28
#  include <winsock2.h>
29
# endif
30
#endif
31
32
/* If ERRNUM maps to an errno value defined by gnulib, return a string
33
   describing the error.  Otherwise return NULL.  */
34
const char *
35
strerror_override (int errnum)
36
{
37
  /* These error messages are taken from glibc/sysdeps/gnu/errlist.c.  */
38
  switch (errnum)
39
    {
40
#if REPLACE_STRERROR_0
41
    case 0:
42
      return "Success";
43
#endif
44
45
#if GNULIB_defined_ESOCK /* native Windows platforms with older <errno.h> */
46
    case EINPROGRESS:
47
      return "Operation now in progress";
48
    case EALREADY:
49
      return "Operation already in progress";
50
    case ENOTSOCK:
51
      return "Socket operation on non-socket";
52
    case EDESTADDRREQ:
53
      return "Destination address required";
54
    case EMSGSIZE:
55
      return "Message too long";
56
    case EPROTOTYPE:
57
      return "Protocol wrong type for socket";
58
    case ENOPROTOOPT:
59
      return "Protocol not available";
60
    case EPROTONOSUPPORT:
61
      return "Protocol not supported";
62
    case EOPNOTSUPP:
63
      return "Operation not supported";
64
    case EAFNOSUPPORT:
65
      return "Address family not supported by protocol";
66
    case EADDRINUSE:
67
      return "Address already in use";
68
    case EADDRNOTAVAIL:
69
      return "Cannot assign requested address";
70
    case ENETDOWN:
71
      return "Network is down";
72
    case ENETUNREACH:
73
      return "Network is unreachable";
74
    case ECONNRESET:
75
      return "Connection reset by peer";
76
    case ENOBUFS:
77
      return "No buffer space available";
78
    case EISCONN:
79
      return "Transport endpoint is already connected";
80
    case ENOTCONN:
81
      return "Transport endpoint is not connected";
82
    case ETIMEDOUT:
83
      return "Connection timed out";
84
    case ECONNREFUSED:
85
      return "Connection refused";
86
    case ELOOP:
87
      return "Too many levels of symbolic links";
88
    case EHOSTUNREACH:
89
      return "No route to host";
90
    case EWOULDBLOCK:
91
      return "Operation would block";
92
#endif
93
#if GNULIB_defined_ESTREAMS /* native Windows platforms with older <errno.h> */
94
    case ETXTBSY:
95
      return "Text file busy";
96
    case ENODATA:
97
      return "No data available";
98
    case ENOSR:
99
      return "Out of streams resources";
100
    case ENOSTR:
101
      return "Device not a stream";
102
    case ETIME:
103
      return "Timer expired";
104
    case EOTHER:
105
      return "Other error";
106
#endif
107
#if GNULIB_defined_EWINSOCK /* native Windows platforms */
108
    case ESOCKTNOSUPPORT:
109
      return "Socket type not supported";
110
    case EPFNOSUPPORT:
111
      return "Protocol family not supported";
112
    case ESHUTDOWN:
113
      return "Cannot send after transport endpoint shutdown";
114
    case ETOOMANYREFS:
115
      return "Too many references: cannot splice";
116
    case EHOSTDOWN:
117
      return "Host is down";
118
    case EPROCLIM:
119
      return "Too many processes";
120
    case EUSERS:
121
      return "Too many users";
122
    case EDQUOT:
123
      return "Disk quota exceeded";
124
    case ESTALE:
125
      return "Stale NFS file handle";
126
    case EREMOTE:
127
      return "Object is remote";
128
# if HAVE_WINSOCK2_H
129
      /* WSA_INVALID_HANDLE maps to EBADF */
130
      /* WSA_NOT_ENOUGH_MEMORY maps to ENOMEM */
131
      /* WSA_INVALID_PARAMETER maps to EINVAL */
132
    case WSA_OPERATION_ABORTED:
133
      return "Overlapped operation aborted";
134
    case WSA_IO_INCOMPLETE:
135
      return "Overlapped I/O event object not in signaled state";
136
    case WSA_IO_PENDING:
137
      return "Overlapped operations will complete later";
138
      /* WSAEINTR maps to EINTR */
139
      /* WSAEBADF maps to EBADF */
140
      /* WSAEACCES maps to EACCES */
141
      /* WSAEFAULT maps to EFAULT */
142
      /* WSAEINVAL maps to EINVAL */
143
      /* WSAEMFILE maps to EMFILE */
144
      /* WSAEWOULDBLOCK maps to EWOULDBLOCK */
145
      /* WSAEINPROGRESS maps to EINPROGRESS */
146
      /* WSAEALREADY maps to EALREADY */
147
      /* WSAENOTSOCK maps to ENOTSOCK */
148
      /* WSAEDESTADDRREQ maps to EDESTADDRREQ */
149
      /* WSAEMSGSIZE maps to EMSGSIZE */
150
      /* WSAEPROTOTYPE maps to EPROTOTYPE */
151
      /* WSAENOPROTOOPT maps to ENOPROTOOPT */
152
      /* WSAEPROTONOSUPPORT maps to EPROTONOSUPPORT */
153
      /* WSAESOCKTNOSUPPORT is ESOCKTNOSUPPORT */
154
      /* WSAEOPNOTSUPP maps to EOPNOTSUPP */
155
      /* WSAEPFNOSUPPORT is EPFNOSUPPORT */
156
      /* WSAEAFNOSUPPORT maps to EAFNOSUPPORT */
157
      /* WSAEADDRINUSE maps to EADDRINUSE */
158
      /* WSAEADDRNOTAVAIL maps to EADDRNOTAVAIL */
159
      /* WSAENETDOWN maps to ENETDOWN */
160
      /* WSAENETUNREACH maps to ENETUNREACH */
161
      /* WSAENETRESET maps to ENETRESET */
162
      /* WSAECONNABORTED maps to ECONNABORTED */
163
      /* WSAECONNRESET maps to ECONNRESET */
164
      /* WSAENOBUFS maps to ENOBUFS */
165
      /* WSAEISCONN maps to EISCONN */
166
      /* WSAENOTCONN maps to ENOTCONN */
167
      /* WSAESHUTDOWN is ESHUTDOWN */
168
      /* WSAETOOMANYREFS is ETOOMANYREFS */
169
      /* WSAETIMEDOUT maps to ETIMEDOUT */
170
      /* WSAECONNREFUSED maps to ECONNREFUSED */
171
      /* WSAELOOP maps to ELOOP */
172
      /* WSAENAMETOOLONG maps to ENAMETOOLONG */
173
      /* WSAEHOSTDOWN is EHOSTDOWN */
174
      /* WSAEHOSTUNREACH maps to EHOSTUNREACH */
175
      /* WSAENOTEMPTY maps to ENOTEMPTY */
176
      /* WSAEPROCLIM is EPROCLIM */
177
      /* WSAEUSERS is EUSERS */
178
      /* WSAEDQUOT is EDQUOT */
179
      /* WSAESTALE is ESTALE */
180
      /* WSAEREMOTE is EREMOTE */
181
    case WSASYSNOTREADY:
182
      return "Network subsystem is unavailable";
183
    case WSAVERNOTSUPPORTED:
184
      return "Winsock.dll version out of range";
185
    case WSANOTINITIALISED:
186
      return "Successful WSAStartup not yet performed";
187
    case WSAEDISCON:
188
      return "Graceful shutdown in progress";
189
    case WSAENOMORE: case WSA_E_NO_MORE:
190
      return "No more results";
191
    case WSAECANCELLED: case WSA_E_CANCELLED:
192
      return "Call was canceled";
193
    case WSAEINVALIDPROCTABLE:
194
      return "Procedure call table is invalid";
195
    case WSAEINVALIDPROVIDER:
196
      return "Service provider is invalid";
197
    case WSAEPROVIDERFAILEDINIT:
198
      return "Service provider failed to initialize";
199
    case WSASYSCALLFAILURE:
200
      return "System call failure";
201
    case WSASERVICE_NOT_FOUND:
202
      return "Service not found";
203
    case WSATYPE_NOT_FOUND:
204
      return "Class type not found";
205
    case WSAEREFUSED:
206
      return "Database query was refused";
207
    case WSAHOST_NOT_FOUND:
208
      return "Host not found";
209
    case WSATRY_AGAIN:
210
      return "Nonauthoritative host not found";
211
    case WSANO_RECOVERY:
212
      return "Nonrecoverable error";
213
    case WSANO_DATA:
214
      return "Valid name, no data record of requested type";
215
      /* WSA_QOS_* omitted */
216
# endif
217
#endif
218
219
#if GNULIB_defined_ENOMSG
220
    case ENOMSG:
221
      return "No message of desired type";
222
#endif
223
224
#if GNULIB_defined_EIDRM
225
    case EIDRM:
226
      return "Identifier removed";
227
#endif
228
229
#if GNULIB_defined_ENOLINK
230
    case ENOLINK:
231
      return "Link has been severed";
232
#endif
233
234
#if GNULIB_defined_EPROTO
235
    case EPROTO:
236
      return "Protocol error";
237
#endif
238
239
#if GNULIB_defined_EMULTIHOP
240
    case EMULTIHOP:
241
      return "Multihop attempted";
242
#endif
243
244
#if GNULIB_defined_EBADMSG
245
    case EBADMSG:
246
      return "Bad message";
247
#endif
248
249
#if GNULIB_defined_EOVERFLOW
250
    case EOVERFLOW:
251
      return "Value too large for defined data type";
252
#endif
253
254
#if GNULIB_defined_ENOTSUP
255
    case ENOTSUP:
256
      return "Not supported";
257
#endif
258
259
#if GNULIB_defined_ENETRESET
260
    case ENETRESET:
261
      return "Network dropped connection on reset";
262
#endif
263
264
#if GNULIB_defined_ECONNABORTED
265
    case ECONNABORTED:
266
      return "Software caused connection abort";
267
#endif
268
269
#if GNULIB_defined_ESTALE
270
    case ESTALE:
271
      return "Stale NFS file handle";
272
#endif
273
274
#if GNULIB_defined_EDQUOT
275
    case EDQUOT:
276
      return "Disk quota exceeded";
277
#endif
278
279
#if GNULIB_defined_ECANCELED
280
    case ECANCELED:
281
      return "Operation canceled";
282
#endif
283
284
#if GNULIB_defined_EOWNERDEAD
285
    case EOWNERDEAD:
286
      return "Owner died";
287
#endif
288
289
#if GNULIB_defined_ENOTRECOVERABLE
290
    case ENOTRECOVERABLE:
291
      return "State not recoverable";
292
#endif
293
294
#if GNULIB_defined_EILSEQ
295
    case EILSEQ:
296
      return "Invalid or incomplete multibyte or wide character";
297
#endif
298
299
    default:
300
      return NULL;
301
    }
302
}
(-)a/gl/tests/strerror-override.h (-56 lines)
Lines 1-56 Link Here
1
/* strerror-override.h --- POSIX compatible system error routine
2
3
   Copyright (C) 2010-2013 Free Software Foundation, Inc.
4
5
   This program is free software: you can redistribute it and/or modify
6
   it under the terms of the GNU General Public License as published by
7
   the Free Software Foundation; either version 3 of the License, or
8
   (at your option) any later version.
9
10
   This program is distributed in the hope that it will be useful,
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
   GNU General Public License for more details.
14
15
   You should have received a copy of the GNU General Public License
16
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
17
18
#ifndef _GL_STRERROR_OVERRIDE_H
19
# define _GL_STRERROR_OVERRIDE_H
20
21
# include <errno.h>
22
# include <stddef.h>
23
24
/* Reasonable buffer size that should never trigger ERANGE; if this
25
   proves too small, we intentionally abort(), to remind us to fix
26
   this value.  */
27
# define STACKBUF_LEN 256
28
29
/* If ERRNUM maps to an errno value defined by gnulib, return a string
30
   describing the error.  Otherwise return NULL.  */
31
# if REPLACE_STRERROR_0 \
32
     || GNULIB_defined_ESOCK \
33
     || GNULIB_defined_ESTREAMS \
34
     || GNULIB_defined_EWINSOCK \
35
     || GNULIB_defined_ENOMSG \
36
     || GNULIB_defined_EIDRM \
37
     || GNULIB_defined_ENOLINK \
38
     || GNULIB_defined_EPROTO \
39
     || GNULIB_defined_EMULTIHOP \
40
     || GNULIB_defined_EBADMSG \
41
     || GNULIB_defined_EOVERFLOW \
42
     || GNULIB_defined_ENOTSUP \
43
     || GNULIB_defined_ENETRESET \
44
     || GNULIB_defined_ECONNABORTED \
45
     || GNULIB_defined_ESTALE \
46
     || GNULIB_defined_EDQUOT \
47
     || GNULIB_defined_ECANCELED \
48
     || GNULIB_defined_EOWNERDEAD \
49
     || GNULIB_defined_ENOTRECOVERABLE \
50
     || GNULIB_defined_EILSEQ
51
extern const char *strerror_override (int errnum) _GL_ATTRIBUTE_CONST;
52
# else
53
#  define strerror_override(ignored) NULL
54
# endif
55
56
#endif /* _GL_STRERROR_OVERRIDE_H */
(-)a/gl/tests/strerror.c (-71 lines)
Lines 1-70 Link Here
1
/* strerror.c --- POSIX compatible system error routine
2
3
   Copyright (C) 2007-2013 Free Software Foundation, Inc.
4
5
   This program is free software: you can redistribute it and/or modify
6
   it under the terms of the GNU General Public License as published by
7
   the Free Software Foundation; either version 3 of the License, or
8
   (at your option) any later version.
9
10
   This program is distributed in the hope that it will be useful,
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
   GNU General Public License for more details.
14
15
   You should have received a copy of the GNU General Public License
16
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
17
18
#include <config.h>
19
20
/* Specification.  */
21
#include <string.h>
22
23
#include <errno.h>
24
#include <stdio.h>
25
#include <stdlib.h>
26
#include <string.h>
27
28
#include "intprops.h"
29
#include "strerror-override.h"
30
#include "verify.h"
31
32
/* Use the system functions, not the gnulib overrides in this file.  */
33
#undef sprintf
34
35
char *
36
strerror (int n)
37
#undef strerror
38
{
39
  static char buf[STACKBUF_LEN];
40
  size_t len;
41
42
  /* Cast away const, due to the historical signature of strerror;
43
     callers should not be modifying the string.  */
44
  const char *msg = strerror_override (n);
45
  if (msg)
46
    return (char *) msg;
47
48
  msg = strerror (n);
49
50
  /* Our strerror_r implementation might use the system's strerror
51
     buffer, so all other clients of strerror have to see the error
52
     copied into a buffer that we manage.  This is not thread-safe,
53
     even if the system strerror is, but portable programs shouldn't
54
     be using strerror if they care about thread-safety.  */
55
  if (!msg || !*msg)
56
    {
57
      static char const fmt[] = "Unknown error %d";
58
      verify (sizeof buf >= sizeof (fmt) + INT_STRLEN_BOUND (n));
59
      sprintf (buf, fmt, n);
60
      errno = EINVAL;
61
      return buf;
62
    }
63
64
  /* Fix STACKBUF_LEN if this ever aborts.  */
65
  len = strlen (msg);
66
  if (sizeof buf <= len)
67
    abort ();
68
69
  return memcpy (buf, msg, len + 1);
70
}
71
- 

Return to bug 492752