annotate m4/socklen.m4 @ 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 2081227303c5
children 8250f2777afc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14440
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
1 # socklen.m4 serial 10
14079
97fc9a21a8fb maint: update almost all copyright ranges to include 2011
Jim Meyering <meyering@redhat.com>
parents: 13588
diff changeset
2 dnl Copyright (C) 2005-2007, 2009-2011 Free Software Foundation, Inc.
6217
f73f33cda590 2005-09-08 Simon Josefsson <jas@extundo.com>
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
3 dnl This file is free software; the Free Software Foundation
f73f33cda590 2005-09-08 Simon Josefsson <jas@extundo.com>
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
4 dnl gives unlimited permission to copy and/or distribute it,
f73f33cda590 2005-09-08 Simon Josefsson <jas@extundo.com>
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
5 dnl with or without modifications, as long as this notice is preserved.
f73f33cda590 2005-09-08 Simon Josefsson <jas@extundo.com>
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
6
6572
df6195e003c4 * socklen.m4: Look in ws2tcpip.h too, for mingw32.
Simon Josefsson <simon@josefsson.org>
parents: 6468
diff changeset
7 dnl From Albert Chin, Windows fixes from Simon Josefsson.
6217
f73f33cda590 2005-09-08 Simon Josefsson <jas@extundo.com>
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
8
6468
c2f9aa6169d0 * socklen.m4 (gl_TYPE_SOCKLEN_T): Renamed from gl_SOCKLEN_T.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6258
diff changeset
9 dnl Check for socklen_t: historically on BSD it is an int, and in
c2f9aa6169d0 * socklen.m4 (gl_TYPE_SOCKLEN_T): Renamed from gl_SOCKLEN_T.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6258
diff changeset
10 dnl POSIX 1g it is a type of its own, but some platforms use different
13588
a17068cb741d sys_socket, netdb: Ensure socklen_t gets defined.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
11 dnl types for the argument to getsockopt, getpeername, etc.:
14437
9a53138b000a socklen: Update comment.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
12 dnl HP-UX 10.20, IRIX 6.5, OSF/1 4.0, Interix 3.5, BeOS.
13588
a17068cb741d sys_socket, netdb: Ensure socklen_t gets defined.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
13 dnl So we have to test to find something that will work.
6572
df6195e003c4 * socklen.m4: Look in ws2tcpip.h too, for mingw32.
Simon Josefsson <simon@josefsson.org>
parents: 6468
diff changeset
14
6468
c2f9aa6169d0 * socklen.m4 (gl_TYPE_SOCKLEN_T): Renamed from gl_SOCKLEN_T.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6258
diff changeset
15 AC_DEFUN([gl_TYPE_SOCKLEN_T],
14440
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
16 [AC_REQUIRE([gl_CHECK_SOCKET_HEADERS])dnl
6572
df6195e003c4 * socklen.m4: Look in ws2tcpip.h too, for mingw32.
Simon Josefsson <simon@josefsson.org>
parents: 6468
diff changeset
17 AC_CHECK_TYPE([socklen_t], ,
6468
c2f9aa6169d0 * socklen.m4 (gl_TYPE_SOCKLEN_T): Renamed from gl_SOCKLEN_T.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6258
diff changeset
18 [AC_MSG_CHECKING([for socklen_t equivalent])
8068
b659313aacd0 m4/socklen.m4: Fix typo.
Simon Josefsson <simon@josefsson.org>
parents: 6646
diff changeset
19 AC_CACHE_VAL([gl_cv_socklen_t_equiv],
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11987
diff changeset
20 [# Systems have either "struct sockaddr *" or
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11987
diff changeset
21 # "void *" as the second argument to getpeername
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11987
diff changeset
22 gl_cv_socklen_t_equiv=
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11987
diff changeset
23 for arg2 in "struct sockaddr" void; do
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11987
diff changeset
24 for t in int size_t "unsigned int" "long int" "unsigned long int"; do
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11987
diff changeset
25 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
11987
56ceeef91c22 Remove obsolete macros from several modules.
Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
parents: 9266
diff changeset
26 [[#include <sys/types.h>
56ceeef91c22 Remove obsolete macros from several modules.
Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
parents: 9266
diff changeset
27 #include <sys/socket.h>
6468
c2f9aa6169d0 * socklen.m4 (gl_TYPE_SOCKLEN_T): Renamed from gl_SOCKLEN_T.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6258
diff changeset
28
11987
56ceeef91c22 Remove obsolete macros from several modules.
Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
parents: 9266
diff changeset
29 int getpeername (int, $arg2 *, $t *);]],
56ceeef91c22 Remove obsolete macros from several modules.
Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
parents: 9266
diff changeset
30 [[$t len;
56ceeef91c22 Remove obsolete macros from several modules.
Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
parents: 9266
diff changeset
31 getpeername (0, 0, &len);]])],
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11987
diff changeset
32 [gl_cv_socklen_t_equiv="$t"])
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11987
diff changeset
33 test "$gl_cv_socklen_t_equiv" != "" && break
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11987
diff changeset
34 done
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11987
diff changeset
35 test "$gl_cv_socklen_t_equiv" != "" && break
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11987
diff changeset
36 done
6468
c2f9aa6169d0 * socklen.m4 (gl_TYPE_SOCKLEN_T): Renamed from gl_SOCKLEN_T.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6258
diff changeset
37 ])
c2f9aa6169d0 * socklen.m4 (gl_TYPE_SOCKLEN_T): Renamed from gl_SOCKLEN_T.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6258
diff changeset
38 if test "$gl_cv_socklen_t_equiv" = ""; then
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11987
diff changeset
39 AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
6468
c2f9aa6169d0 * socklen.m4 (gl_TYPE_SOCKLEN_T): Renamed from gl_SOCKLEN_T.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6258
diff changeset
40 fi
c2f9aa6169d0 * socklen.m4 (gl_TYPE_SOCKLEN_T): Renamed from gl_SOCKLEN_T.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6258
diff changeset
41 AC_MSG_RESULT([$gl_cv_socklen_t_equiv])
c2f9aa6169d0 * socklen.m4 (gl_TYPE_SOCKLEN_T): Renamed from gl_SOCKLEN_T.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6258
diff changeset
42 AC_DEFINE_UNQUOTED([socklen_t], [$gl_cv_socklen_t_equiv],
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11987
diff changeset
43 [type to use in place of socklen_t if not defined])],
14440
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
44 [gl_SOCKET_HEADERS])])
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
45
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
46 dnl On mingw32, socklen_t is in ws2tcpip.h ('int'), so we try to find
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
47 dnl it there too. But on Cygwin, wc2tcpip.h must not be included. Users
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
48 dnl of this module should use the same include pattern as gl_SOCKET_HEADERS.
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
49 dnl When you change this macro, keep also in sync:
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
50 dnl - gl_CHECK_SOCKET_HEADERS,
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
51 dnl - the Include section of modules/socklen.
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
52 AC_DEFUN([gl_SOCKET_HEADERS],
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
53 [
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
54 /* <sys/types.h> is not needed according to POSIX, but the
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
55 <sys/socket.h> in i386-unknown-freebsd4.10 and
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
56 powerpc-apple-darwin5.5 required it. */
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
57 #include <sys/types.h>
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
58 #if HAVE_SYS_SOCKET_H
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
59 # include <sys/socket.h>
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
60 #elif HAVE_WS2TCPIP_H
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
61 # include <ws2tcpip.h>
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
62 #endif
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
63 ])
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
64
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
65 dnl Tests for the existence of the header for socket facilities.
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
66 dnl Defines the C macros HAVE_SYS_SOCKET_H, HAVE_WS2TCPIP_H.
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
67 dnl This macro must match gl_SOCKET_HEADERS.
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
68 AC_DEFUN([gl_CHECK_SOCKET_HEADERS],
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
69 [AC_CHECK_HEADERS_ONCE([sys/socket.h])
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
70 if test $ac_cv_header_sys_socket_h = no; then
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
71 dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
72 dnl the check for those headers unconditional; yet cygwin reports
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
73 dnl that the headers are present but cannot be compiled (since on
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
74 dnl cygwin, all socket information should come from sys/socket.h).
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
75 AC_CHECK_HEADERS([ws2tcpip.h])
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
76 fi
2081227303c5 socklen: do not depend on sys_socket
Paul Eggert <eggert@cs.ucla.edu>
parents: 14437
diff changeset
77 ])