"Fossies" - the Fresh Open Source Software Archive

Member "gcal-4.1/m4/strerror_r.m4" (22 Jan 2017, 7461 Bytes) of package /linux/misc/gcal-4.1.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "strerror_r.m4": 4_vs_4.1.

    1 # strerror_r.m4 serial 18
    2 dnl Copyright (C) 2002, 2007-2017 Free Software Foundation, Inc.
    3 dnl This file is free software; the Free Software Foundation
    4 dnl gives unlimited permission to copy and/or distribute it,
    5 dnl with or without modifications, as long as this notice is preserved.
    6 
    7 AC_DEFUN([gl_FUNC_STRERROR_R],
    8 [
    9   AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
   10   AC_REQUIRE([gl_FUNC_STRERROR_R_WORKS])
   11 
   12   dnl Persuade Solaris <string.h> to declare strerror_r().
   13   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
   14 
   15   dnl Some systems don't declare strerror_r() if _THREAD_SAFE and _REENTRANT
   16   dnl are not defined.
   17   AC_CHECK_DECL([strerror_r],
   18     [HAVE_DECL_STRERROR_R=1], [HAVE_DECL_STRERROR_R=0])
   19   AC_DEFINE_UNQUOTED([HAVE_DECL_STRERROR_R_ORIG], [$HAVE_DECL_STRERROR_R],
   20     [Define to 1 if you have the declaration of 'strerror_r' in the system include files, or to 0 otherwise.])
   21 
   22   if test $ac_cv_func_strerror_r = yes; then
   23     if test "$ERRNO_H:$REPLACE_STRERROR_0" = :0; then
   24       if test $gl_cv_func_strerror_r_posix_signature = yes; then
   25         case "$gl_cv_func_strerror_r_works" in
   26           dnl The system's strerror_r has bugs.  Replace it.
   27           *no) REPLACE_STRERROR_R=1 ;;
   28         esac
   29       else
   30         dnl The system's strerror_r() has a wrong signature. Replace it.
   31         REPLACE_STRERROR_R=1
   32       fi
   33     else
   34       dnl The system's strerror_r() cannot know about the new errno values we
   35       dnl add to <errno.h>, or any fix for strerror(0). Replace it.
   36       REPLACE_STRERROR_R=1
   37     fi
   38   fi
   39 
   40   # Overwrite the findings of AC_FUNC_STRERROR_R (for code that uses that).
   41   AC_REQUIRE([AC_FUNC_STRERROR_R])
   42 ])
   43 
   44 # If this module is in use, we unconditionally want POSIX semantics; so
   45 # replace autoconf's macro with a version that does not probe
   46 AC_DEFUN([AC_FUNC_STRERROR_R], [
   47   AC_DEFINE([HAVE_DECL_STRERROR_R], [1],
   48     [Define to 1, since you should have the declaration of strerror_r.])
   49   AC_DEFINE([HAVE_STRERROR_R], [1],
   50     [Define to 1, since you should have the function strerror_r.])
   51   AC_DEFINE([STRERROR_R_CHAR_P], [0],
   52     [Define to 0, since strerror_r should not return char *.])
   53 ])
   54 
   55 # Prerequisites of lib/strerror_r.c.
   56 AC_DEFUN([gl_PREREQ_STRERROR_R], [
   57   dnl glibc >= 2.3.4 and cygwin 1.7.9 have a function __xpg_strerror_r.
   58   AC_CHECK_FUNCS_ONCE([__xpg_strerror_r])
   59   AC_CHECK_FUNCS_ONCE([catgets])
   60   AC_CHECK_FUNCS_ONCE([snprintf])
   61 ])
   62 
   63 # Detect if strerror_r works, but without affecting whether a replacement
   64 # strerror_r will be used.
   65 AC_DEFUN([gl_FUNC_STRERROR_R_WORKS],
   66 [
   67   AC_REQUIRE([gl_HEADER_ERRNO_H])
   68   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
   69   AC_REQUIRE([gl_FUNC_STRERROR_0])
   70 
   71   AC_CHECK_FUNC([strerror_r])
   72   if test $ac_cv_func_strerror_r = yes; then
   73     if test "$ERRNO_H:$REPLACE_STRERROR_0" = :0; then
   74       dnl The POSIX prototype is:  int strerror_r (int, char *, size_t);
   75       dnl glibc, Cygwin:           char *strerror_r (int, char *, size_t);
   76       dnl AIX 5.1, OSF/1 5.1:      int strerror_r (int, char *, int);
   77       AC_CACHE_CHECK([for strerror_r with POSIX signature],
   78         [gl_cv_func_strerror_r_posix_signature],
   79         [AC_COMPILE_IFELSE(
   80            [AC_LANG_PROGRAM(
   81               [[#include <string.h>
   82                 int strerror_r (int, char *, size_t);
   83               ]],
   84               [])],
   85            [gl_cv_func_strerror_r_posix_signature=yes],
   86            [gl_cv_func_strerror_r_posix_signature=no])
   87         ])
   88       if test $gl_cv_func_strerror_r_posix_signature = yes; then
   89         dnl AIX 6.1 strerror_r fails by returning -1, not an error number.
   90         dnl HP-UX 11.31 strerror_r always fails when the buffer length argument
   91         dnl is less than 80.
   92         dnl FreeBSD 8.s strerror_r claims failure on 0
   93         dnl Mac OS X 10.5 strerror_r treats 0 like -1
   94         dnl Solaris 10 strerror_r corrupts errno on failure
   95         AC_CACHE_CHECK([whether strerror_r works],
   96           [gl_cv_func_strerror_r_works],
   97           [AC_RUN_IFELSE(
   98              [AC_LANG_PROGRAM(
   99                 [[#include <errno.h>
  100                   #include <string.h>
  101                 ]],
  102                 [[int result = 0;
  103                   char buf[79];
  104                   if (strerror_r (EACCES, buf, 0) < 0)
  105                     result |= 1;
  106                   errno = 0;
  107                   if (strerror_r (EACCES, buf, sizeof buf) != 0)
  108                     result |= 2;
  109                   strcpy (buf, "Unknown");
  110                   if (strerror_r (0, buf, sizeof buf) != 0)
  111                     result |= 4;
  112                   if (errno)
  113                     result |= 8;
  114                   if (strstr (buf, "nknown") || strstr (buf, "ndefined"))
  115                     result |= 0x10;
  116                   errno = 0;
  117                   *buf = 0;
  118                   if (strerror_r (-3, buf, sizeof buf) < 0)
  119                     result |= 0x20;
  120                   if (errno)
  121                     result |= 0x40;
  122                   if (!*buf)
  123                     result |= 0x80;
  124                   return result;
  125                 ]])],
  126              [gl_cv_func_strerror_r_works=yes],
  127              [gl_cv_func_strerror_r_works=no],
  128              [
  129 changequote(,)dnl
  130               case "$host_os" in
  131                        # Guess no on AIX.
  132                 aix*)  gl_cv_func_strerror_r_works="guessing no";;
  133                        # Guess no on HP-UX.
  134                 hpux*) gl_cv_func_strerror_r_works="guessing no";;
  135                        # Guess no on BSD variants.
  136                 *bsd*)  gl_cv_func_strerror_r_works="guessing no";;
  137                        # Guess yes otherwise.
  138                 *)     gl_cv_func_strerror_r_works="guessing yes";;
  139               esac
  140 changequote([,])dnl
  141              ])
  142           ])
  143       else
  144         dnl The system's strerror() has a wrong signature.
  145         dnl glibc >= 2.3.4 and cygwin 1.7.9 have a function __xpg_strerror_r.
  146         AC_CHECK_FUNCS_ONCE([__xpg_strerror_r])
  147         dnl In glibc < 2.14, __xpg_strerror_r does not populate buf on failure.
  148         dnl In cygwin < 1.7.10, __xpg_strerror_r clobbers strerror's buffer.
  149         if test $ac_cv_func___xpg_strerror_r = yes; then
  150           AC_CACHE_CHECK([whether __xpg_strerror_r works],
  151             [gl_cv_func_strerror_r_works],
  152             [AC_RUN_IFELSE(
  153                [AC_LANG_PROGRAM(
  154                   [[#include <errno.h>
  155                     #include <string.h>
  156                     extern
  157                     #ifdef __cplusplus
  158                     "C"
  159                     #endif
  160                     int __xpg_strerror_r(int, char *, size_t);
  161                   ]],
  162                   [[int result = 0;
  163                     char buf[256] = "^";
  164                     char copy[256];
  165                     char *str = strerror (-1);
  166                     strcpy (copy, str);
  167                     if (__xpg_strerror_r (-2, buf, 1) == 0)
  168                       result |= 1;
  169                     if (*buf)
  170                       result |= 2;
  171                     __xpg_strerror_r (-2, buf, 256);
  172                     if (strcmp (str, copy))
  173                       result |= 4;
  174                     return result;
  175                   ]])],
  176                [gl_cv_func_strerror_r_works=yes],
  177                [gl_cv_func_strerror_r_works=no],
  178                [dnl Guess no on all platforms that have __xpg_strerror_r,
  179                 dnl at least until fixed glibc and cygwin are more common.
  180                 gl_cv_func_strerror_r_works="guessing no"
  181                ])
  182             ])
  183         fi
  184       fi
  185     fi
  186   fi
  187 ])