comparison modules/strerror-override @ 15308:a3ba680ad389

strerror_r: fix OpenBSD behavior on 0 OpenBSD treats strerror_r(0,,) as a success, but with a message "Undefined error: 0"; while this is distinct from strerror_r(-1,,) returning "Unknown error: -1", it does not imply success. Meanwhile, if buf is short enough for ERANGE, then we can't use strstr to look for "Unknown" or "Undefined" in the resulting message, like we had been doing for strerror(). Fix this by shifting the burden - now the strerror-override code guarantees that 0 will have an override when needed. * lib/strerror-override.c (strerror_override): Also override 0 when needed. * lib/strerror-override.h (strerror_override): Likewise. * lib/strerror.c (strerror): Simplify, now that 0 override is done earlier. * lib/strerror_r.c (strerror_r): Likewise. * m4/strerror.m4 (gl_FUNC_STRERROR): Split detection of 0 behavior... (gl_FUNC_STRERROR_0): ...into new macro. * m4/strerror_r.m4 (gl_FUNC_STRERROR_R): Replace strerror_r if 0 is overridden. (gl_FUNC_STRERROR_R_WORKS): Avoid extra tests if 0 is broken. * modules/strerror-override (Files): Add strerror.m4. (configure.ac): Also provide override for 0 when needed. * doc/posix-functions/strerror.texi (strerror): Document this. * doc/posix-functions/perror.texi (perror): Likewise. Signed-off-by: Eric Blake <eblake@redhat.com>
author Eric Blake <eblake@redhat.com>
date Tue, 21 Jun 2011 08:50:51 -0600
parents 262fbc6e4790
children
comparison
equal deleted inserted replaced
15307:eaa30c92de91 15308:a3ba680ad389
3 3
4 Files: 4 Files:
5 lib/strerror-override.h 5 lib/strerror-override.h
6 lib/strerror-override.c 6 lib/strerror-override.c
7 m4/sys_socket_h.m4 7 m4/sys_socket_h.m4
8 m4/strerror.m4
8 9
9 Depends-on: 10 Depends-on:
10 errno 11 errno
11 12
12 configure.ac: 13 configure.ac:
13 AC_REQUIRE([gl_HEADER_ERRNO_H]) 14 AC_REQUIRE([gl_HEADER_ERRNO_H])
14 if test -n "$ERRNO_H"; then 15 AC_REQUIRE([gl_FUNC_STRERROR_0])
16 if test -n "$ERRNO_H" || test $REPLACE_STRERROR_0 = 1; then
15 AC_LIBOBJ([strerror-override]) 17 AC_LIBOBJ([strerror-override])
16 gl_PREREQ_SYS_H_WINSOCK2 18 gl_PREREQ_SYS_H_WINSOCK2
17 fi 19 fi
18 20
19 Makefile.am: 21 Makefile.am: