view m4/poll.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 4efb4fb07ff2
children 3a4d1597833c
line wrap: on
line source

# poll.m4 serial 14
dnl Copyright (c) 2003, 2005-2007, 2009-2011 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.

AC_DEFUN([gl_FUNC_POLL],
[
  AC_REQUIRE([gl_POLL_H])
  if test "$ac_cv_header_poll_h" = no; then
    ac_cv_func_poll=no
    gl_cv_func_poll=no
  else
    AC_CHECK_FUNC([poll],
      [# Check whether poll() works on special files (like /dev/null) and
       # and ttys (like /dev/tty). On MacOS X 10.4.0 and AIX 5.3, it doesn't.
       AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <fcntl.h>
#include <poll.h>
         int main()
         {
           int result = 0;
           struct pollfd ufd;
           /* Try /dev/null for reading.  */
           ufd.fd = open ("/dev/null", O_RDONLY);
           /* If /dev/null does not exist, it's not MacOS X nor AIX. */
           if (ufd.fd >= 0)
             {
               ufd.events = POLLIN;
               ufd.revents = 0;
               if (!(poll (&ufd, 1, 0) == 1 && ufd.revents == POLLIN))
                 result |= 1;
             }
           /* Try /dev/null for writing.  */
           ufd.fd = open ("/dev/null", O_WRONLY);
           /* If /dev/null does not exist, it's not MacOS X nor AIX. */
           if (ufd.fd >= 0)
             {
               ufd.events = POLLOUT;
               ufd.revents = 0;
               if (!(poll (&ufd, 1, 0) == 1 && ufd.revents == POLLOUT))
                 result |= 2;
             }
           /* Trying /dev/tty may be too environment dependent.  */
           return result;
         }]])],
         [gl_cv_func_poll=yes],
         [gl_cv_func_poll=no],
         [# When cross-compiling, assume that poll() works everywhere except on
          # MacOS X or AIX, regardless of its version.
          AC_EGREP_CPP([MacOSX], [
#if (defined(__APPLE__) && defined(__MACH__)) || defined(_AIX)
This is MacOSX or AIX
#endif
], [gl_cv_func_poll=no], [gl_cv_func_poll=yes])])])
  fi
  if test $gl_cv_func_poll != yes; then
    AC_CHECK_FUNC([poll], [ac_cv_func_poll=yes], [ac_cv_func_poll=no])
    if test $ac_cv_func_poll = no; then
      HAVE_POLL=0
    else
      REPLACE_POLL=1
    fi
  fi
  if test $HAVE_POLL = 0 || test $REPLACE_POLL = 1; then
    :
  else
    AC_DEFINE([HAVE_POLL], [1],
      [Define to 1 if you have the 'poll' function and it works.])
  fi
])

# Prerequisites of lib/poll.c.
AC_DEFUN([gl_PREREQ_POLL],
[
  AC_CHECK_HEADERS_ONCE([sys/ioctl.h sys/filio.h])
])