view m4/isinf.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 85f546d97fb5
children 9d4b273deacd
line wrap: on
line source

# isinf.m4 serial 5
dnl Copyright (C) 2007-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_ISINF],
[
  AC_REQUIRE([gl_MATH_H_DEFAULTS])
  dnl Persuade glibc <math.h> to declare isinf.
  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
  AC_CHECK_DECLS([isinf], , , [#include <math.h>])
  if test "$ac_cv_have_decl_isinf" = yes; then
    gl_CHECK_MATH_LIB([ISINF_LIBM], [x = isinf (x) + isinf ((float) x);])
    if test "$ISINF_LIBM" != missing; then
      dnl Test whether isinf() on 'long double' works.
      gl_ISINFL_WORKS
      case "$gl_cv_func_isinfl_works" in
        *yes) ;;
        *)    ISINF_LIBM=missing;;
      esac
    fi
  fi
  if test "$ac_cv_have_decl_isinf" != yes ||
     test "$ISINF_LIBM" = missing; then
    REPLACE_ISINF=1
    dnl No libraries are needed to link lib/isinf.c.
    ISINF_LIBM=
  fi
  AC_SUBST([ISINF_LIBM])
])

dnl Test whether isinf() correctly returns false for LDBL_MAX.
AC_DEFUN([gl_ISINFL_WORKS],
[
  AC_REQUIRE([AC_PROG_CC])
  AC_REQUIRE([gl_BIGENDIAN])
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  AC_CACHE_CHECK([whether isinf(long double) works], [gl_cv_func_isinfl_works],
    [
      AC_RUN_IFELSE([AC_LANG_PROGRAM([[#include <float.h>
                                       #include <math.h>]],
                                     [[return !!isinf(LDBL_MAX);]])],
                    [gl_cv_func_isinfl_works=yes],
                    [gl_cv_func_isinfl_works=no],
                    [gl_cv_func_isinfl_works="guessing no"])
    ])
])