Blame m4/printf.m4

Packit Service a2489d
# printf.m4 serial 58
Packit Service a2489d
dnl Copyright (C) 2003, 2007-2018 Free Software Foundation, Inc.
Packit Service a2489d
dnl This file is free software; the Free Software Foundation
Packit Service a2489d
dnl gives unlimited permission to copy and/or distribute it,
Packit Service a2489d
dnl with or without modifications, as long as this notice is preserved.
Packit Service a2489d
Packit Service a2489d
dnl Test whether the *printf family of functions supports the 'j', 'z', 't',
Packit Service a2489d
dnl 'L' size specifiers. (ISO C99, POSIX:2001)
Packit Service a2489d
dnl Result is gl_cv_func_printf_sizes_c99.
Packit Service a2489d
Packit Service a2489d
AC_DEFUN([gl_PRINTF_SIZES_C99],
Packit Service a2489d
[
Packit Service a2489d
  AC_REQUIRE([AC_PROG_CC])
Packit Service a2489d
  AC_REQUIRE([gl_AC_HEADER_STDINT_H])
Packit Service a2489d
  AC_REQUIRE([gl_AC_HEADER_INTTYPES_H])
Packit Service a2489d
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit Service a2489d
  AC_CACHE_CHECK([whether printf supports size specifiers as in C99],
Packit Service a2489d
    [gl_cv_func_printf_sizes_c99],
Packit Service a2489d
    [
Packit Service a2489d
      AC_RUN_IFELSE(
Packit Service a2489d
        [AC_LANG_SOURCE([[
Packit Service a2489d
#include <stddef.h>
Packit Service a2489d
#include <stdio.h>
Packit Service a2489d
#include <string.h>
Packit Service a2489d
#include <sys/types.h>
Packit Service a2489d
#if HAVE_STDINT_H_WITH_UINTMAX
Packit Service a2489d
# include <stdint.h>
Packit Service a2489d
#endif
Packit Service a2489d
#if HAVE_INTTYPES_H_WITH_UINTMAX
Packit Service a2489d
# include <inttypes.h>
Packit Service a2489d
#endif
Packit Service a2489d
static char buf[100];
Packit Service a2489d
int main ()
Packit Service a2489d
{
Packit Service a2489d
  int result = 0;
Packit Service a2489d
#if HAVE_STDINT_H_WITH_UINTMAX || HAVE_INTTYPES_H_WITH_UINTMAX
Packit Service a2489d
  buf[0] = '\0';
Packit Service a2489d
  if (sprintf (buf, "%ju %d", (uintmax_t) 12345671, 33, 44, 55) < 0
Packit Service a2489d
      || strcmp (buf, "12345671 33") != 0)
Packit Service a2489d
    result |= 1;
Packit Service a2489d
#else
Packit Service a2489d
  result |= 1;
Packit Service a2489d
#endif
Packit Service a2489d
  buf[0] = '\0';
Packit Service a2489d
  if (sprintf (buf, "%zu %d", (size_t) 12345672, 33, 44, 55) < 0
Packit Service a2489d
      || strcmp (buf, "12345672 33") != 0)
Packit Service a2489d
    result |= 2;
Packit Service a2489d
  buf[0] = '\0';
Packit Service a2489d
  if (sprintf (buf, "%tu %d", (ptrdiff_t) 12345673, 33, 44, 55) < 0
Packit Service a2489d
      || strcmp (buf, "12345673 33") != 0)
Packit Service a2489d
    result |= 4;
Packit Service a2489d
  buf[0] = '\0';
Packit Service a2489d
  if (sprintf (buf, "%Lg %d", (long double) 1.5, 33, 44, 55) < 0
Packit Service a2489d
      || strcmp (buf, "1.5 33") != 0)
Packit Service a2489d
    result |= 8;
Packit Service a2489d
  return result;
Packit Service a2489d
}]])],
Packit Service a2489d
        [gl_cv_func_printf_sizes_c99=yes],
Packit Service a2489d
        [gl_cv_func_printf_sizes_c99=no],
Packit Service a2489d
        [
Packit Service a2489d
         case "$host_os" in
Packit Service a2489d
changequote(,)dnl
Packit Service a2489d
                                 # Guess yes on glibc systems.
Packit Service a2489d
           *-gnu* | gnu*)        gl_cv_func_printf_sizes_c99="guessing yes";;
Packit Service a2489d
                                 # Guess yes on FreeBSD >= 5.
Packit Service a2489d
           freebsd[1-4].*)       gl_cv_func_printf_sizes_c99="guessing no";;
Packit Service a2489d
           freebsd* | kfreebsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
Packit Service a2489d
                                 # Guess yes on Mac OS X >= 10.3.
Packit Service a2489d
           darwin[1-6].*)        gl_cv_func_printf_sizes_c99="guessing no";;
Packit Service a2489d
           darwin*)              gl_cv_func_printf_sizes_c99="guessing yes";;
Packit Service a2489d
                                 # Guess yes on OpenBSD >= 3.9.
Packit Service a2489d
           openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
Packit Service a2489d
                                 gl_cv_func_printf_sizes_c99="guessing no";;
Packit Service a2489d
           openbsd*)             gl_cv_func_printf_sizes_c99="guessing yes";;
Packit Service a2489d
                                 # Guess yes on Solaris >= 2.10.
Packit Service a2489d
           solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";;
Packit Service a2489d
           solaris*)             gl_cv_func_printf_sizes_c99="guessing no";;
Packit Service a2489d
                                 # Guess yes on NetBSD >= 3.
Packit Service a2489d
           netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
Packit Service a2489d
                                 gl_cv_func_printf_sizes_c99="guessing no";;
Packit Service a2489d
           netbsd*)              gl_cv_func_printf_sizes_c99="guessing yes";;
Packit Service a2489d
changequote([,])dnl
Packit Service a2489d
                                 # Guess yes on MSVC, no on mingw.
Packit Service a2489d
           mingw*)               AC_EGREP_CPP([Known], [
Packit Service a2489d
#ifdef _MSC_VER
Packit Service a2489d
 Known
Packit Service a2489d
#endif
Packit Service a2489d
                                   ],
Packit Service a2489d
                                   [gl_cv_func_printf_sizes_c99="guessing yes"],
Packit Service a2489d
                                   [gl_cv_func_printf_sizes_c99="guessing no"])
Packit Service a2489d
                                 ;;
Packit Service a2489d
                                 # If we don't know, assume the worst.
Packit Service a2489d
           *)                    gl_cv_func_printf_sizes_c99="guessing no";;
Packit Service a2489d
         esac
Packit Service a2489d
        ])
Packit Service a2489d
    ])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl Test whether the *printf family of functions supports 'long double'
Packit Service a2489d
dnl arguments together with the 'L' size specifier. (ISO C99, POSIX:2001)
Packit Service a2489d
dnl Result is gl_cv_func_printf_long_double.
Packit Service a2489d
Packit Service a2489d
AC_DEFUN([gl_PRINTF_LONG_DOUBLE],
Packit Service a2489d
[
Packit Service a2489d
  AC_REQUIRE([AC_PROG_CC])
Packit Service a2489d
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit Service a2489d
  AC_CACHE_CHECK([whether printf supports 'long double' arguments],
Packit Service a2489d
    [gl_cv_func_printf_long_double],
Packit Service a2489d
    [
Packit Service a2489d
      AC_RUN_IFELSE(
Packit Service a2489d
        [AC_LANG_SOURCE([[
Packit Service a2489d
#include <stdio.h>
Packit Service a2489d
#include <string.h>
Packit Service a2489d
static char buf[10000];
Packit Service a2489d
int main ()
Packit Service a2489d
{
Packit Service a2489d
  int result = 0;
Packit Service a2489d
  buf[0] = '\0';
Packit Service a2489d
  if (sprintf (buf, "%Lf %d", 1.75L, 33, 44, 55) < 0
Packit Service a2489d
      || strcmp (buf, "1.750000 33") != 0)
Packit Service a2489d
    result |= 1;
Packit Service a2489d
  buf[0] = '\0';
Packit Service a2489d
  if (sprintf (buf, "%Le %d", 1.75L, 33, 44, 55) < 0
Packit Service a2489d
      || strcmp (buf, "1.750000e+00 33") != 0)
Packit Service a2489d
    result |= 2;
Packit Service a2489d
  buf[0] = '\0';
Packit Service a2489d
  if (sprintf (buf, "%Lg %d", 1.75L, 33, 44, 55) < 0
Packit Service a2489d
      || strcmp (buf, "1.75 33") != 0)
Packit Service a2489d
    result |= 4;
Packit Service a2489d
  return result;
Packit Service a2489d
}]])],
Packit Service a2489d
        [gl_cv_func_printf_long_double=yes],
Packit Service a2489d
        [gl_cv_func_printf_long_double=no],
Packit Service a2489d
        [case "$host_os" in
Packit Service a2489d
           beos*)  gl_cv_func_printf_long_double="guessing no";;
Packit Service a2489d
                   # Guess yes on MSVC, no on mingw.
Packit Service a2489d
           mingw*) AC_EGREP_CPP([Known], [
Packit Service a2489d
#ifdef _MSC_VER
Packit Service a2489d
 Known
Packit Service a2489d
#endif
Packit Service a2489d
                     ],
Packit Service a2489d
                     [gl_cv_func_printf_long_double="guessing yes"],
Packit Service a2489d
                     [gl_cv_func_printf_long_double="guessing no"])
Packit Service a2489d
                   ;;
Packit Service a2489d
           *)      gl_cv_func_printf_long_double="guessing yes";;
Packit Service a2489d
         esac
Packit Service a2489d
        ])
Packit Service a2489d
    ])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl Test whether the *printf family of functions supports infinite and NaN
Packit Service a2489d
dnl 'double' arguments and negative zero arguments in the %f, %e, %g
Packit Service a2489d
dnl directives. (ISO C99, POSIX:2001)
Packit Service a2489d
dnl Result is gl_cv_func_printf_infinite.
Packit Service a2489d
Packit Service a2489d
AC_DEFUN([gl_PRINTF_INFINITE],
Packit Service a2489d
[
Packit Service a2489d
  AC_REQUIRE([AC_PROG_CC])
Packit Service a2489d
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit Service a2489d
  AC_CACHE_CHECK([whether printf supports infinite 'double' arguments],
Packit Service a2489d
    [gl_cv_func_printf_infinite],
Packit Service a2489d
    [
Packit Service a2489d
      AC_RUN_IFELSE(
Packit Service a2489d
        [AC_LANG_SOURCE([[
Packit Service a2489d
#include <stdio.h>
Packit Service a2489d
#include <string.h>
Packit Service a2489d
static int
Packit Service a2489d
strisnan (const char *string, size_t start_index, size_t end_index)
Packit Service a2489d
{
Packit Service a2489d
  if (start_index < end_index)
Packit Service a2489d
    {
Packit Service a2489d
      if (string[start_index] == '-')
Packit Service a2489d
        start_index++;
Packit Service a2489d
      if (start_index + 3 <= end_index
Packit Service a2489d
          && memcmp (string + start_index, "nan", 3) == 0)
Packit Service a2489d
        {
Packit Service a2489d
          start_index += 3;
Packit Service a2489d
          if (start_index == end_index
Packit Service a2489d
              || (string[start_index] == '(' && string[end_index - 1] == ')'))
Packit Service a2489d
            return 1;
Packit Service a2489d
        }
Packit Service a2489d
    }
Packit Service a2489d
  return 0;
Packit Service a2489d
}
Packit Service a2489d
static int
Packit Service a2489d
have_minus_zero ()
Packit Service a2489d
{
Packit Service a2489d
  static double plus_zero = 0.0;
Packit Service a2489d
  double minus_zero = - plus_zero;
Packit Service a2489d
  return memcmp (&plus_zero, &minus_zero, sizeof (double)) != 0;
Packit Service a2489d
}
Packit Service a2489d
static char buf[10000];
Packit Service a2489d
static double zero = 0.0;
Packit Service a2489d
int main ()
Packit Service a2489d
{
Packit Service a2489d
  int result = 0;
Packit Service a2489d
  if (sprintf (buf, "%f", 1.0 / zero) < 0
Packit Service a2489d
      || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
Packit Service a2489d
    result |= 1;
Packit Service a2489d
  if (sprintf (buf, "%f", -1.0 / zero) < 0
Packit Service a2489d
      || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
Packit Service a2489d
    result |= 1;
Packit Service a2489d
  if (sprintf (buf, "%f", zero / zero) < 0
Packit Service a2489d
      || !strisnan (buf, 0, strlen (buf)))
Packit Service a2489d
    result |= 2;
Packit Service a2489d
  if (sprintf (buf, "%e", 1.0 / zero) < 0
Packit Service a2489d
      || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
Packit Service a2489d
    result |= 4;
Packit Service a2489d
  if (sprintf (buf, "%e", -1.0 / zero) < 0
Packit Service a2489d
      || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
Packit Service a2489d
    result |= 4;
Packit Service a2489d
  if (sprintf (buf, "%e", zero / zero) < 0
Packit Service a2489d
      || !strisnan (buf, 0, strlen (buf)))
Packit Service a2489d
    result |= 8;
Packit Service a2489d
  if (sprintf (buf, "%g", 1.0 / zero) < 0
Packit Service a2489d
      || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
Packit Service a2489d
    result |= 16;
Packit Service a2489d
  if (sprintf (buf, "%g", -1.0 / zero) < 0
Packit Service a2489d
      || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
Packit Service a2489d
    result |= 16;
Packit Service a2489d
  if (sprintf (buf, "%g", zero / zero) < 0
Packit Service a2489d
      || !strisnan (buf, 0, strlen (buf)))
Packit Service a2489d
    result |= 32;
Packit Service a2489d
  /* This test fails on HP-UX 10.20.  */
Packit Service a2489d
  if (have_minus_zero ())
Packit Service a2489d
    if (sprintf (buf, "%g", - zero) < 0
Packit Service a2489d
        || strcmp (buf, "-0") != 0)
Packit Service a2489d
    result |= 64;
Packit Service a2489d
  return result;
Packit Service a2489d
}]])],
Packit Service a2489d
        [gl_cv_func_printf_infinite=yes],
Packit Service a2489d
        [gl_cv_func_printf_infinite=no],
Packit Service a2489d
        [
Packit Service a2489d
         case "$host_os" in
Packit Service a2489d
changequote(,)dnl
Packit Service a2489d
                                 # Guess yes on glibc systems.
Packit Service a2489d
           *-gnu* | gnu*)        gl_cv_func_printf_infinite="guessing yes";;
Packit Service a2489d
                                 # Guess yes on FreeBSD >= 6.
Packit Service a2489d
           freebsd[1-5].*)       gl_cv_func_printf_infinite="guessing no";;
Packit Service a2489d
           freebsd* | kfreebsd*) gl_cv_func_printf_infinite="guessing yes";;
Packit Service a2489d
                                 # Guess yes on Mac OS X >= 10.3.
Packit Service a2489d
           darwin[1-6].*)        gl_cv_func_printf_infinite="guessing no";;
Packit Service a2489d
           darwin*)              gl_cv_func_printf_infinite="guessing yes";;
Packit Service a2489d
                                 # Guess yes on HP-UX >= 11.
Packit Service a2489d
           hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite="guessing no";;
Packit Service a2489d
           hpux*)                gl_cv_func_printf_infinite="guessing yes";;
Packit Service a2489d
                                 # Guess yes on NetBSD >= 3.
Packit Service a2489d
           netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
Packit Service a2489d
                                 gl_cv_func_printf_infinite="guessing no";;
Packit Service a2489d
           netbsd*)              gl_cv_func_printf_infinite="guessing yes";;
Packit Service a2489d
                                 # Guess yes on BeOS.
Packit Service a2489d
           beos*)                gl_cv_func_printf_infinite="guessing yes";;
Packit Service a2489d
changequote([,])dnl
Packit Service a2489d
                                 # Guess yes on MSVC, no on mingw.
Packit Service a2489d
           mingw*)               AC_EGREP_CPP([Known], [
Packit Service a2489d
#ifdef _MSC_VER
Packit Service a2489d
 Known
Packit Service a2489d
#endif
Packit Service a2489d
                                   ],
Packit Service a2489d
                                   [gl_cv_func_printf_infinite="guessing yes"],
Packit Service a2489d
                                   [gl_cv_func_printf_infinite="guessing no"])
Packit Service a2489d
                                 ;;
Packit Service a2489d
                                 # If we don't know, assume the worst.
Packit Service a2489d
           *)                    gl_cv_func_printf_infinite="guessing no";;
Packit Service a2489d
         esac
Packit Service a2489d
        ])
Packit Service a2489d
    ])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl Test whether the *printf family of functions supports infinite and NaN
Packit Service a2489d
dnl 'long double' arguments in the %f, %e, %g directives. (ISO C99, POSIX:2001)
Packit Service a2489d
dnl Result is gl_cv_func_printf_infinite_long_double.
Packit Service a2489d
Packit Service a2489d
AC_DEFUN([gl_PRINTF_INFINITE_LONG_DOUBLE],
Packit Service a2489d
[
Packit Service a2489d
  AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
Packit Service a2489d
  AC_REQUIRE([AC_PROG_CC])
Packit Service a2489d
  AC_REQUIRE([gl_BIGENDIAN])
Packit Service a2489d
  AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
Packit Service a2489d
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit Service a2489d
  dnl The user can set or unset the variable gl_printf_safe to indicate
Packit Service a2489d
  dnl that he wishes a safe handling of non-IEEE-754 'long double' values.
Packit Service a2489d
  if test -n "$gl_printf_safe"; then
Packit Service a2489d
    AC_DEFINE([CHECK_PRINTF_SAFE], [1],
Packit Service a2489d
      [Define if you wish *printf() functions that have a safe handling of
Packit Service a2489d
       non-IEEE-754 'long double' values.])
Packit Service a2489d
  fi
Packit Service a2489d
  case "$gl_cv_func_printf_long_double" in
Packit Service a2489d
    *yes)
Packit Service a2489d
      AC_CACHE_CHECK([whether printf supports infinite 'long double' arguments],
Packit Service a2489d
        [gl_cv_func_printf_infinite_long_double],
Packit Service a2489d
        [
Packit Service a2489d
          AC_RUN_IFELSE(
Packit Service a2489d
            [AC_LANG_SOURCE([[
Packit Service a2489d
]GL_NOCRASH[
Packit Service a2489d
#include <float.h>
Packit Service a2489d
#include <stdio.h>
Packit Service a2489d
#include <string.h>
Packit Service a2489d
static int
Packit Service a2489d
strisnan (const char *string, size_t start_index, size_t end_index)
Packit Service a2489d
{
Packit Service a2489d
  if (start_index < end_index)
Packit Service a2489d
    {
Packit Service a2489d
      if (string[start_index] == '-')
Packit Service a2489d
        start_index++;
Packit Service a2489d
      if (start_index + 3 <= end_index
Packit Service a2489d
          && memcmp (string + start_index, "nan", 3) == 0)
Packit Service a2489d
        {
Packit Service a2489d
          start_index += 3;
Packit Service a2489d
          if (start_index == end_index
Packit Service a2489d
              || (string[start_index] == '(' && string[end_index - 1] == ')'))
Packit Service a2489d
            return 1;
Packit Service a2489d
        }
Packit Service a2489d
    }
Packit Service a2489d
  return 0;
Packit Service a2489d
}
Packit Service a2489d
static char buf[10000];
Packit Service a2489d
static long double zeroL = 0.0L;
Packit Service a2489d
int main ()
Packit Service a2489d
{
Packit Service a2489d
  int result = 0;
Packit Service a2489d
  nocrash_init();
Packit Service a2489d
  if (sprintf (buf, "%Lf", 1.0L / zeroL) < 0
Packit Service a2489d
      || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
Packit Service a2489d
    result |= 1;
Packit Service a2489d
  if (sprintf (buf, "%Lf", -1.0L / zeroL) < 0
Packit Service a2489d
      || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
Packit Service a2489d
    result |= 1;
Packit Service a2489d
  if (sprintf (buf, "%Lf", zeroL / zeroL) < 0
Packit Service a2489d
      || !strisnan (buf, 0, strlen (buf)))
Packit Service a2489d
    result |= 1;
Packit Service a2489d
  if (sprintf (buf, "%Le", 1.0L / zeroL) < 0
Packit Service a2489d
      || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
Packit Service a2489d
    result |= 1;
Packit Service a2489d
  if (sprintf (buf, "%Le", -1.0L / zeroL) < 0
Packit Service a2489d
      || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
Packit Service a2489d
    result |= 1;
Packit Service a2489d
  if (sprintf (buf, "%Le", zeroL / zeroL) < 0
Packit Service a2489d
      || !strisnan (buf, 0, strlen (buf)))
Packit Service a2489d
    result |= 1;
Packit Service a2489d
  if (sprintf (buf, "%Lg", 1.0L / zeroL) < 0
Packit Service a2489d
      || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
Packit Service a2489d
    result |= 1;
Packit Service a2489d
  if (sprintf (buf, "%Lg", -1.0L / zeroL) < 0
Packit Service a2489d
      || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
Packit Service a2489d
    result |= 1;
Packit Service a2489d
  if (sprintf (buf, "%Lg", zeroL / zeroL) < 0
Packit Service a2489d
      || !strisnan (buf, 0, strlen (buf)))
Packit Service a2489d
    result |= 1;
Packit Service a2489d
#if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
Packit Service a2489d
/* Representation of an 80-bit 'long double' as an initializer for a sequence
Packit Service a2489d
   of 'unsigned int' words.  */
Packit Service a2489d
# ifdef WORDS_BIGENDIAN
Packit Service a2489d
#  define LDBL80_WORDS(exponent,manthi,mantlo) \
Packit Service a2489d
     { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
Packit Service a2489d
       ((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16),   \
Packit Service a2489d
       (unsigned int) (mantlo) << 16                                        \
Packit Service a2489d
     }
Packit Service a2489d
# else
Packit Service a2489d
#  define LDBL80_WORDS(exponent,manthi,mantlo) \
Packit Service a2489d
     { mantlo, manthi, exponent }
Packit Service a2489d
# endif
Packit Service a2489d
  { /* Quiet NaN.  */
Packit Service a2489d
    static union { unsigned int word[4]; long double value; } x =
Packit Service a2489d
      { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
Packit Service a2489d
    if (sprintf (buf, "%Lf", x.value) < 0
Packit Service a2489d
        || !strisnan (buf, 0, strlen (buf)))
Packit Service a2489d
      result |= 2;
Packit Service a2489d
    if (sprintf (buf, "%Le", x.value) < 0
Packit Service a2489d
        || !strisnan (buf, 0, strlen (buf)))
Packit Service a2489d
      result |= 2;
Packit Service a2489d
    if (sprintf (buf, "%Lg", x.value) < 0
Packit Service a2489d
        || !strisnan (buf, 0, strlen (buf)))
Packit Service a2489d
      result |= 2;
Packit Service a2489d
  }
Packit Service a2489d
  {
Packit Service a2489d
    /* Signalling NaN.  */
Packit Service a2489d
    static union { unsigned int word[4]; long double value; } x =
Packit Service a2489d
      { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
Packit Service a2489d
    if (sprintf (buf, "%Lf", x.value) < 0
Packit Service a2489d
        || !strisnan (buf, 0, strlen (buf)))
Packit Service a2489d
      result |= 2;
Packit Service a2489d
    if (sprintf (buf, "%Le", x.value) < 0
Packit Service a2489d
        || !strisnan (buf, 0, strlen (buf)))
Packit Service a2489d
      result |= 2;
Packit Service a2489d
    if (sprintf (buf, "%Lg", x.value) < 0
Packit Service a2489d
        || !strisnan (buf, 0, strlen (buf)))
Packit Service a2489d
      result |= 2;
Packit Service a2489d
  }
Packit Service a2489d
  { /* Pseudo-NaN.  */
Packit Service a2489d
    static union { unsigned int word[4]; long double value; } x =
Packit Service a2489d
      { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
Packit Service a2489d
    if (sprintf (buf, "%Lf", x.value) <= 0)
Packit Service a2489d
      result |= 4;
Packit Service a2489d
    if (sprintf (buf, "%Le", x.value) <= 0)
Packit Service a2489d
      result |= 4;
Packit Service a2489d
    if (sprintf (buf, "%Lg", x.value) <= 0)
Packit Service a2489d
      result |= 4;
Packit Service a2489d
  }
Packit Service a2489d
  { /* Pseudo-Infinity.  */
Packit Service a2489d
    static union { unsigned int word[4]; long double value; } x =
Packit Service a2489d
      { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
Packit Service a2489d
    if (sprintf (buf, "%Lf", x.value) <= 0)
Packit Service a2489d
      result |= 8;
Packit Service a2489d
    if (sprintf (buf, "%Le", x.value) <= 0)
Packit Service a2489d
      result |= 8;
Packit Service a2489d
    if (sprintf (buf, "%Lg", x.value) <= 0)
Packit Service a2489d
      result |= 8;
Packit Service a2489d
  }
Packit Service a2489d
  { /* Pseudo-Zero.  */
Packit Service a2489d
    static union { unsigned int word[4]; long double value; } x =
Packit Service a2489d
      { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
Packit Service a2489d
    if (sprintf (buf, "%Lf", x.value) <= 0)
Packit Service a2489d
      result |= 16;
Packit Service a2489d
    if (sprintf (buf, "%Le", x.value) <= 0)
Packit Service a2489d
      result |= 16;
Packit Service a2489d
    if (sprintf (buf, "%Lg", x.value) <= 0)
Packit Service a2489d
      result |= 16;
Packit Service a2489d
  }
Packit Service a2489d
  { /* Unnormalized number.  */
Packit Service a2489d
    static union { unsigned int word[4]; long double value; } x =
Packit Service a2489d
      { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
Packit Service a2489d
    if (sprintf (buf, "%Lf", x.value) <= 0)
Packit Service a2489d
      result |= 32;
Packit Service a2489d
    if (sprintf (buf, "%Le", x.value) <= 0)
Packit Service a2489d
      result |= 32;
Packit Service a2489d
    if (sprintf (buf, "%Lg", x.value) <= 0)
Packit Service a2489d
      result |= 32;
Packit Service a2489d
  }
Packit Service a2489d
  { /* Pseudo-Denormal.  */
Packit Service a2489d
    static union { unsigned int word[4]; long double value; } x =
Packit Service a2489d
      { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
Packit Service a2489d
    if (sprintf (buf, "%Lf", x.value) <= 0)
Packit Service a2489d
      result |= 64;
Packit Service a2489d
    if (sprintf (buf, "%Le", x.value) <= 0)
Packit Service a2489d
      result |= 64;
Packit Service a2489d
    if (sprintf (buf, "%Lg", x.value) <= 0)
Packit Service a2489d
      result |= 64;
Packit Service a2489d
  }
Packit Service a2489d
#endif
Packit Service a2489d
  return result;
Packit Service a2489d
}]])],
Packit Service a2489d
            [gl_cv_func_printf_infinite_long_double=yes],
Packit Service a2489d
            [gl_cv_func_printf_infinite_long_double=no],
Packit Service a2489d
            [case "$host_cpu" in
Packit Service a2489d
                                     # Guess no on ia64, x86_64, i386.
Packit Service a2489d
               ia64 | x86_64 | i*86) gl_cv_func_printf_infinite_long_double="guessing no";;
Packit Service a2489d
               *)
Packit Service a2489d
                 case "$host_os" in
Packit Service a2489d
changequote(,)dnl
Packit Service a2489d
                                         # Guess yes on glibc systems.
Packit Service a2489d
                   *-gnu* | gnu*)        gl_cv_func_printf_infinite_long_double="guessing yes";;
Packit Service a2489d
                                         # Guess yes on FreeBSD >= 6.
Packit Service a2489d
                   freebsd[1-5].*)       gl_cv_func_printf_infinite_long_double="guessing no";;
Packit Service a2489d
                   freebsd* | kfreebsd*) gl_cv_func_printf_infinite_long_double="guessing yes";;
Packit Service a2489d
                                         # Guess yes on HP-UX >= 11.
Packit Service a2489d
                   hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite_long_double="guessing no";;
Packit Service a2489d
                   hpux*)                gl_cv_func_printf_infinite_long_double="guessing yes";;
Packit Service a2489d
changequote([,])dnl
Packit Service a2489d
                                         # Guess yes on MSVC, no on mingw.
Packit Service a2489d
                   mingw*)               AC_EGREP_CPP([Known], [
Packit Service a2489d
#ifdef _MSC_VER
Packit Service a2489d
 Known
Packit Service a2489d
#endif
Packit Service a2489d
                                           ],
Packit Service a2489d
                                           [gl_cv_func_printf_infinite_long_double="guessing yes"],
Packit Service a2489d
                                           [gl_cv_func_printf_infinite_long_double="guessing no"])
Packit Service a2489d
                                         ;;
Packit Service a2489d
                                         # If we don't know, assume the worst.
Packit Service a2489d
                   *)                    gl_cv_func_printf_infinite_long_double="guessing no";;
Packit Service a2489d
                 esac
Packit Service a2489d
                 ;;
Packit Service a2489d
             esac
Packit Service a2489d
            ])
Packit Service a2489d
        ])
Packit Service a2489d
      ;;
Packit Service a2489d
    *)
Packit Service a2489d
      gl_cv_func_printf_infinite_long_double="irrelevant"
Packit Service a2489d
      ;;
Packit Service a2489d
  esac
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl Test whether the *printf family of functions supports the 'a' and 'A'
Packit Service a2489d
dnl conversion specifier for hexadecimal output of floating-point numbers.
Packit Service a2489d
dnl (ISO C99, POSIX:2001)
Packit Service a2489d
dnl Result is gl_cv_func_printf_directive_a.
Packit Service a2489d
Packit Service a2489d
AC_DEFUN([gl_PRINTF_DIRECTIVE_A],
Packit Service a2489d
[
Packit Service a2489d
  AC_REQUIRE([AC_PROG_CC])
Packit Service a2489d
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit Service a2489d
  AC_CACHE_CHECK([whether printf supports the 'a' and 'A' directives],
Packit Service a2489d
    [gl_cv_func_printf_directive_a],
Packit Service a2489d
    [
Packit Service a2489d
      AC_RUN_IFELSE(
Packit Service a2489d
        [AC_LANG_SOURCE([[
Packit Service a2489d
#include <stdio.h>
Packit Service a2489d
#include <string.h>
Packit Service a2489d
static char buf[100];
Packit Service a2489d
static double zero = 0.0;
Packit Service a2489d
int main ()
Packit Service a2489d
{
Packit Service a2489d
  int result = 0;
Packit Service a2489d
  if (sprintf (buf, "%a %d", 3.1416015625, 33, 44, 55) < 0
Packit Service a2489d
      || (strcmp (buf, "0x1.922p+1 33") != 0
Packit Service a2489d
          && strcmp (buf, "0x3.244p+0 33") != 0
Packit Service a2489d
          && strcmp (buf, "0x6.488p-1 33") != 0
Packit Service a2489d
          && strcmp (buf, "0xc.91p-2 33") != 0))
Packit Service a2489d
    result |= 1;
Packit Service a2489d
  if (sprintf (buf, "%A %d", -3.1416015625, 33, 44, 55) < 0
Packit Service a2489d
      || (strcmp (buf, "-0X1.922P+1 33") != 0
Packit Service a2489d
          && strcmp (buf, "-0X3.244P+0 33") != 0
Packit Service a2489d
          && strcmp (buf, "-0X6.488P-1 33") != 0
Packit Service a2489d
          && strcmp (buf, "-0XC.91P-2 33") != 0))
Packit Service a2489d
    result |= 2;
Packit Service a2489d
  /* This catches a FreeBSD 6.1 bug: it doesn't round.  */
Packit Service a2489d
  if (sprintf (buf, "%.2a %d", 1.51, 33, 44, 55) < 0
Packit Service a2489d
      || (strcmp (buf, "0x1.83p+0 33") != 0
Packit Service a2489d
          && strcmp (buf, "0x3.05p-1 33") != 0
Packit Service a2489d
          && strcmp (buf, "0x6.0ap-2 33") != 0
Packit Service a2489d
          && strcmp (buf, "0xc.14p-3 33") != 0))
Packit Service a2489d
    result |= 4;
Packit Service a2489d
  /* This catches a Mac OS X 10.12.4 (Darwin 16.5) bug: it doesn't round.  */
Packit Service a2489d
  if (sprintf (buf, "%.0a %d", 1.51, 33, 44, 55) < 0
Packit Service a2489d
      || (strcmp (buf, "0x2p+0 33") != 0
Packit Service a2489d
          && strcmp (buf, "0x3p-1 33") != 0
Packit Service a2489d
          && strcmp (buf, "0x6p-2 33") != 0
Packit Service a2489d
          && strcmp (buf, "0xcp-3 33") != 0))
Packit Service a2489d
    result |= 4;
Packit Service a2489d
  /* This catches a FreeBSD 6.1 bug.  See
Packit Service a2489d
     <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */
Packit Service a2489d
  if (sprintf (buf, "%010a %d", 1.0 / zero, 33, 44, 55) < 0
Packit Service a2489d
      || buf[0] == '0')
Packit Service a2489d
    result |= 8;
Packit Service a2489d
  /* This catches a Mac OS X 10.3.9 (Darwin 7.9) bug.  */
Packit Service a2489d
  if (sprintf (buf, "%.1a", 1.999) < 0
Packit Service a2489d
      || (strcmp (buf, "0x1.0p+1") != 0
Packit Service a2489d
          && strcmp (buf, "0x2.0p+0") != 0
Packit Service a2489d
          && strcmp (buf, "0x4.0p-1") != 0
Packit Service a2489d
          && strcmp (buf, "0x8.0p-2") != 0))
Packit Service a2489d
    result |= 16;
Packit Service a2489d
  /* This catches the same Mac OS X 10.3.9 (Darwin 7.9) bug and also a
Packit Service a2489d
     glibc 2.4 bug <https://sourceware.org/bugzilla/show_bug.cgi?id=2908>.  */
Packit Service a2489d
  if (sprintf (buf, "%.1La", 1.999L) < 0
Packit Service a2489d
      || (strcmp (buf, "0x1.0p+1") != 0
Packit Service a2489d
          && strcmp (buf, "0x2.0p+0") != 0
Packit Service a2489d
          && strcmp (buf, "0x4.0p-1") != 0
Packit Service a2489d
          && strcmp (buf, "0x8.0p-2") != 0))
Packit Service a2489d
    result |= 32;
Packit Service a2489d
  return result;
Packit Service a2489d
}]])],
Packit Service a2489d
        [gl_cv_func_printf_directive_a=yes],
Packit Service a2489d
        [gl_cv_func_printf_directive_a=no],
Packit Service a2489d
        [
Packit Service a2489d
         case "$host_os" in
Packit Service a2489d
                                 # Guess yes on glibc >= 2.5 systems.
Packit Service a2489d
           *-gnu* | gnu*)
Packit Service a2489d
             AC_EGREP_CPP([BZ2908], [
Packit Service a2489d
               #include <features.h>
Packit Service a2489d
               #ifdef __GNU_LIBRARY__
Packit Service a2489d
                #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 5) || (__GLIBC__ > 2)) && !defined __UCLIBC__
Packit Service a2489d
                 BZ2908
Packit Service a2489d
                #endif
Packit Service a2489d
               #endif
Packit Service a2489d
               ],
Packit Service a2489d
               [gl_cv_func_printf_directive_a="guessing yes"],
Packit Service a2489d
               [gl_cv_func_printf_directive_a="guessing no"])
Packit Service a2489d
             ;;
Packit Service a2489d
                                 # Guess no on native Windows.
Packit Service a2489d
           mingw*)               gl_cv_func_printf_directive_a="guessing no";;
Packit Service a2489d
                                 # If we don't know, assume the worst.
Packit Service a2489d
           *)                    gl_cv_func_printf_directive_a="guessing no";;
Packit Service a2489d
         esac
Packit Service a2489d
        ])
Packit Service a2489d
    ])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl Test whether the *printf family of functions supports the %F format
Packit Service a2489d
dnl directive. (ISO C99, POSIX:2001)
Packit Service a2489d
dnl Result is gl_cv_func_printf_directive_f.
Packit Service a2489d
Packit Service a2489d
AC_DEFUN([gl_PRINTF_DIRECTIVE_F],
Packit Service a2489d
[
Packit Service a2489d
  AC_REQUIRE([AC_PROG_CC])
Packit Service a2489d
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit Service a2489d
  AC_CACHE_CHECK([whether printf supports the 'F' directive],
Packit Service a2489d
    [gl_cv_func_printf_directive_f],
Packit Service a2489d
    [
Packit Service a2489d
      AC_RUN_IFELSE(
Packit Service a2489d
        [AC_LANG_SOURCE([[
Packit Service a2489d
#include <stdio.h>
Packit Service a2489d
#include <string.h>
Packit Service a2489d
static char buf[100];
Packit Service a2489d
static double zero = 0.0;
Packit Service a2489d
int main ()
Packit Service a2489d
{
Packit Service a2489d
  int result = 0;
Packit Service a2489d
  if (sprintf (buf, "%F %d", 1234567.0, 33, 44, 55) < 0
Packit Service a2489d
      || strcmp (buf, "1234567.000000 33") != 0)
Packit Service a2489d
    result |= 1;
Packit Service a2489d
  if (sprintf (buf, "%F", 1.0 / zero) < 0
Packit Service a2489d
      || (strcmp (buf, "INF") != 0 && strcmp (buf, "INFINITY") != 0))
Packit Service a2489d
    result |= 2;
Packit Service a2489d
  /* This catches a Cygwin 1.5.x bug.  */
Packit Service a2489d
  if (sprintf (buf, "%.F", 1234.0) < 0
Packit Service a2489d
      || strcmp (buf, "1234") != 0)
Packit Service a2489d
    result |= 4;
Packit Service a2489d
  return result;
Packit Service a2489d
}]])],
Packit Service a2489d
        [gl_cv_func_printf_directive_f=yes],
Packit Service a2489d
        [gl_cv_func_printf_directive_f=no],
Packit Service a2489d
        [
Packit Service a2489d
         case "$host_os" in
Packit Service a2489d
changequote(,)dnl
Packit Service a2489d
                                 # Guess yes on glibc systems.
Packit Service a2489d
           *-gnu* | gnu*)        gl_cv_func_printf_directive_f="guessing yes";;
Packit Service a2489d
                                 # Guess yes on FreeBSD >= 6.
Packit Service a2489d
           freebsd[1-5].*)       gl_cv_func_printf_directive_f="guessing no";;
Packit Service a2489d
           freebsd* | kfreebsd*) gl_cv_func_printf_directive_f="guessing yes";;
Packit Service a2489d
                                 # Guess yes on Mac OS X >= 10.3.
Packit Service a2489d
           darwin[1-6].*)        gl_cv_func_printf_directive_f="guessing no";;
Packit Service a2489d
           darwin*)              gl_cv_func_printf_directive_f="guessing yes";;
Packit Service a2489d
                                 # Guess yes on Solaris >= 2.10.
Packit Service a2489d
           solaris2.[1-9][0-9]*) gl_cv_func_printf_directive_f="guessing yes";;
Packit Service a2489d
           solaris*)             gl_cv_func_printf_directive_f="guessing no";;
Packit Service a2489d
changequote([,])dnl
Packit Service a2489d
                                 # Guess yes on MSVC, no on mingw.
Packit Service a2489d
           mingw*)               AC_EGREP_CPP([Known], [
Packit Service a2489d
#ifdef _MSC_VER
Packit Service a2489d
 Known
Packit Service a2489d
#endif
Packit Service a2489d
                                   ],
Packit Service a2489d
                                   [gl_cv_func_printf_directive_f="guessing yes"],
Packit Service a2489d
                                   [gl_cv_func_printf_directive_f="guessing no"])
Packit Service a2489d
                                 ;;
Packit Service a2489d
                                 # If we don't know, assume the worst.
Packit Service a2489d
           *)                    gl_cv_func_printf_directive_f="guessing no";;
Packit Service a2489d
         esac
Packit Service a2489d
        ])
Packit Service a2489d
    ])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl Test whether the *printf family of functions supports the %n format
Packit Service a2489d
dnl directive. (ISO C99, POSIX:2001)
Packit Service a2489d
dnl Result is gl_cv_func_printf_directive_n.
Packit Service a2489d
Packit Service a2489d
AC_DEFUN([gl_PRINTF_DIRECTIVE_N],
Packit Service a2489d
[
Packit Service a2489d
  AC_REQUIRE([AC_PROG_CC])
Packit Service a2489d
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit Service a2489d
  AC_CACHE_CHECK([whether printf supports the 'n' directive],
Packit Service a2489d
    [gl_cv_func_printf_directive_n],
Packit Service a2489d
    [
Packit Service a2489d
      AC_RUN_IFELSE(
Packit Service a2489d
        [AC_LANG_SOURCE([[
Packit Service a2489d
#include <stdio.h>
Packit Service a2489d
#include <stdlib.h>
Packit Service a2489d
#include <string.h>
Packit Service a2489d
#ifdef _MSC_VER
Packit Service a2489d
/* See page about "Parameter Validation" on msdn.microsoft.com.  */
Packit Service a2489d
static void cdecl
Packit Service a2489d
invalid_parameter_handler (const wchar_t *expression,
Packit Service a2489d
                           const wchar_t *function,
Packit Service a2489d
                           const wchar_t *file, unsigned int line,
Packit Service a2489d
                           uintptr_t dummy)
Packit Service a2489d
{
Packit Service a2489d
  exit (1);
Packit Service a2489d
}
Packit Service a2489d
#endif
Packit Service a2489d
static char fmtstring[10];
Packit Service a2489d
static char buf[100];
Packit Service a2489d
int main ()
Packit Service a2489d
{
Packit Service a2489d
  int count = -1;
Packit Service a2489d
#ifdef _MSC_VER
Packit Service a2489d
  _set_invalid_parameter_handler (invalid_parameter_handler);
Packit Service a2489d
#endif
Packit Service a2489d
  /* Copy the format string.  Some systems (glibc with _FORTIFY_SOURCE=2)
Packit Service a2489d
     support %n in format strings in read-only memory but not in writable
Packit Service a2489d
     memory.  */
Packit Service a2489d
  strcpy (fmtstring, "%d %n");
Packit Service a2489d
  if (sprintf (buf, fmtstring, 123, &count, 33, 44, 55) < 0
Packit Service a2489d
      || strcmp (buf, "123 ") != 0
Packit Service a2489d
      || count != 4)
Packit Service a2489d
    return 1;
Packit Service a2489d
  return 0;
Packit Service a2489d
}]])],
Packit Service a2489d
        [gl_cv_func_printf_directive_n=yes],
Packit Service a2489d
        [gl_cv_func_printf_directive_n=no],
Packit Service a2489d
        [case "$host_os" in
Packit Service a2489d
                   # Guess no on native Windows.
Packit Service a2489d
           mingw*) gl_cv_func_printf_directive_n="guessing no";;
Packit Service a2489d
           *)      gl_cv_func_printf_directive_n="guessing yes";;
Packit Service a2489d
         esac
Packit Service a2489d
        ])
Packit Service a2489d
    ])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl Test whether the *printf family of functions supports the %ls format
Packit Service a2489d
dnl directive and in particular, when a precision is specified, whether
Packit Service a2489d
dnl the functions stop converting the wide string argument when the number
Packit Service a2489d
dnl of bytes that have been produced by this conversion equals or exceeds
Packit Service a2489d
dnl the precision.
Packit Service a2489d
dnl Result is gl_cv_func_printf_directive_ls.
Packit Service a2489d
Packit Service a2489d
AC_DEFUN([gl_PRINTF_DIRECTIVE_LS],
Packit Service a2489d
[
Packit Service a2489d
  AC_REQUIRE([AC_PROG_CC])
Packit Service a2489d
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit Service a2489d
  AC_CACHE_CHECK([whether printf supports the 'ls' directive],
Packit Service a2489d
    [gl_cv_func_printf_directive_ls],
Packit Service a2489d
    [
Packit Service a2489d
      AC_RUN_IFELSE(
Packit Service a2489d
        [AC_LANG_SOURCE([[
Packit Service a2489d
/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
Packit Service a2489d
   <wchar.h>.
Packit Service a2489d
   BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
Packit Service a2489d
   included before <wchar.h>.  */
Packit Service a2489d
#include <stddef.h>
Packit Service a2489d
#include <stdio.h>
Packit Service a2489d
#include <time.h>
Packit Service a2489d
#include <wchar.h>
Packit Service a2489d
#include <string.h>
Packit Service a2489d
int main ()
Packit Service a2489d
{
Packit Service a2489d
  int result = 0;
Packit Service a2489d
  char buf[100];
Packit Service a2489d
  /* Test whether %ls works at all.
Packit Service a2489d
     This test fails on OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku, but not on
Packit Service a2489d
     Cygwin 1.5.  */
Packit Service a2489d
  {
Packit Service a2489d
    static const wchar_t wstring[] = { 'a', 'b', 'c', 0 };
Packit Service a2489d
    buf[0] = '\0';
Packit Service a2489d
    if (sprintf (buf, "%ls", wstring) < 0
Packit Service a2489d
        || strcmp (buf, "abc") != 0)
Packit Service a2489d
      result |= 1;
Packit Service a2489d
  }
Packit Service a2489d
  /* This test fails on IRIX 6.5, Solaris 2.6, Cygwin 1.5, Haiku (with an
Packit Service a2489d
     assertion failure inside libc), but not on OpenBSD 4.0.  */
Packit Service a2489d
  {
Packit Service a2489d
    static const wchar_t wstring[] = { 'a', 0 };
Packit Service a2489d
    buf[0] = '\0';
Packit Service a2489d
    if (sprintf (buf, "%ls", wstring) < 0
Packit Service a2489d
        || strcmp (buf, "a") != 0)
Packit Service a2489d
      result |= 2;
Packit Service a2489d
  }
Packit Service a2489d
  /* Test whether precisions in %ls are supported as specified in ISO C 99
Packit Service a2489d
     section 7.19.6.1:
Packit Service a2489d
       "If a precision is specified, no more than that many bytes are written
Packit Service a2489d
        (including shift sequences, if any), and the array shall contain a
Packit Service a2489d
        null wide character if, to equal the multibyte character sequence
Packit Service a2489d
        length given by the precision, the function would need to access a
Packit Service a2489d
        wide character one past the end of the array."
Packit Service a2489d
     This test fails on Solaris 10.  */
Packit Service a2489d
  {
Packit Service a2489d
    static const wchar_t wstring[] = { 'a', 'b', (wchar_t) 0xfdfdfdfd, 0 };
Packit Service a2489d
    buf[0] = '\0';
Packit Service a2489d
    if (sprintf (buf, "%.2ls", wstring) < 0
Packit Service a2489d
        || strcmp (buf, "ab") != 0)
Packit Service a2489d
      result |= 8;
Packit Service a2489d
  }
Packit Service a2489d
  return result;
Packit Service a2489d
}]])],
Packit Service a2489d
        [gl_cv_func_printf_directive_ls=yes],
Packit Service a2489d
        [gl_cv_func_printf_directive_ls=no],
Packit Service a2489d
        [
Packit Service a2489d
changequote(,)dnl
Packit Service a2489d
         case "$host_os" in
Packit Service a2489d
           openbsd*)       gl_cv_func_printf_directive_ls="guessing no";;
Packit Service a2489d
           irix*)          gl_cv_func_printf_directive_ls="guessing no";;
Packit Service a2489d
           solaris*)       gl_cv_func_printf_directive_ls="guessing no";;
Packit Service a2489d
           cygwin*)        gl_cv_func_printf_directive_ls="guessing no";;
Packit Service a2489d
           beos* | haiku*) gl_cv_func_printf_directive_ls="guessing no";;
Packit Service a2489d
                           # Guess yes on native Windows.
Packit Service a2489d
           mingw*)         gl_cv_func_printf_directive_ls="guessing yes";;
Packit Service a2489d
           *)              gl_cv_func_printf_directive_ls="guessing yes";;
Packit Service a2489d
         esac
Packit Service a2489d
changequote([,])dnl
Packit Service a2489d
        ])
Packit Service a2489d
    ])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl Test whether the *printf family of functions supports POSIX/XSI format
Packit Service a2489d
dnl strings with positions. (POSIX:2001)
Packit Service a2489d
dnl Result is gl_cv_func_printf_positions.
Packit Service a2489d
Packit Service a2489d
AC_DEFUN([gl_PRINTF_POSITIONS],
Packit Service a2489d
[
Packit Service a2489d
  AC_REQUIRE([AC_PROG_CC])
Packit Service a2489d
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit Service a2489d
  AC_CACHE_CHECK([whether printf supports POSIX/XSI format strings with positions],
Packit Service a2489d
    [gl_cv_func_printf_positions],
Packit Service a2489d
    [
Packit Service a2489d
      AC_RUN_IFELSE(
Packit Service a2489d
        [AC_LANG_SOURCE([[
Packit Service a2489d
#include <stdio.h>
Packit Service a2489d
#include <string.h>
Packit Service a2489d
/* The string "%2$d %1$d", with dollar characters protected from the shell's
Packit Service a2489d
   dollar expansion (possibly an autoconf bug).  */
Packit Service a2489d
static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' };
Packit Service a2489d
static char buf[100];
Packit Service a2489d
int main ()
Packit Service a2489d
{
Packit Service a2489d
  sprintf (buf, format, 33, 55);
Packit Service a2489d
  return (strcmp (buf, "55 33") != 0);
Packit Service a2489d
}]])],
Packit Service a2489d
        [gl_cv_func_printf_positions=yes],
Packit Service a2489d
        [gl_cv_func_printf_positions=no],
Packit Service a2489d
        [
Packit Service a2489d
changequote(,)dnl
Packit Service a2489d
         case "$host_os" in
Packit Service a2489d
           netbsd[1-3]* | netbsdelf[1-3]* | netbsdaout[1-3]* | netbsdcoff[1-3]*)
Packit Service a2489d
                         gl_cv_func_printf_positions="guessing no";;
Packit Service a2489d
           beos*)        gl_cv_func_printf_positions="guessing no";;
Packit Service a2489d
                         # Guess no on native Windows.
Packit Service a2489d
           mingw* | pw*) gl_cv_func_printf_positions="guessing no";;
Packit Service a2489d
           *)            gl_cv_func_printf_positions="guessing yes";;
Packit Service a2489d
         esac
Packit Service a2489d
changequote([,])dnl
Packit Service a2489d
        ])
Packit Service a2489d
    ])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl Test whether the *printf family of functions supports POSIX/XSI format
Packit Service a2489d
dnl strings with the ' flag for grouping of decimal digits. (POSIX:2001)
Packit Service a2489d
dnl Result is gl_cv_func_printf_flag_grouping.
Packit Service a2489d
Packit Service a2489d
AC_DEFUN([gl_PRINTF_FLAG_GROUPING],
Packit Service a2489d
[
Packit Service a2489d
  AC_REQUIRE([AC_PROG_CC])
Packit Service a2489d
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit Service a2489d
  AC_CACHE_CHECK([whether printf supports the grouping flag],
Packit Service a2489d
    [gl_cv_func_printf_flag_grouping],
Packit Service a2489d
    [
Packit Service a2489d
      AC_RUN_IFELSE(
Packit Service a2489d
        [AC_LANG_SOURCE([[
Packit Service a2489d
#include <stdio.h>
Packit Service a2489d
#include <string.h>
Packit Service a2489d
static char buf[100];
Packit Service a2489d
int main ()
Packit Service a2489d
{
Packit Service a2489d
  if (sprintf (buf, "%'d %d", 1234567, 99) < 0
Packit Service a2489d
      || buf[strlen (buf) - 1] != '9')
Packit Service a2489d
    return 1;
Packit Service a2489d
  return 0;
Packit Service a2489d
}]])],
Packit Service a2489d
        [gl_cv_func_printf_flag_grouping=yes],
Packit Service a2489d
        [gl_cv_func_printf_flag_grouping=no],
Packit Service a2489d
        [
Packit Service a2489d
changequote(,)dnl
Packit Service a2489d
         case "$host_os" in
Packit Service a2489d
           cygwin*)      gl_cv_func_printf_flag_grouping="guessing no";;
Packit Service a2489d
           netbsd*)      gl_cv_func_printf_flag_grouping="guessing no";;
Packit Service a2489d
                         # Guess no on native Windows.
Packit Service a2489d
           mingw* | pw*) gl_cv_func_printf_flag_grouping="guessing no";;
Packit Service a2489d
           *)            gl_cv_func_printf_flag_grouping="guessing yes";;
Packit Service a2489d
         esac
Packit Service a2489d
changequote([,])dnl
Packit Service a2489d
        ])
Packit Service a2489d
    ])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl Test whether the *printf family of functions supports the - flag correctly.
Packit Service a2489d
dnl (ISO C99.) See
Packit Service a2489d
dnl <https://lists.gnu.org/r/bug-coreutils/2008-02/msg00035.html>
Packit Service a2489d
dnl Result is gl_cv_func_printf_flag_leftadjust.
Packit Service a2489d
Packit Service a2489d
AC_DEFUN([gl_PRINTF_FLAG_LEFTADJUST],
Packit Service a2489d
[
Packit Service a2489d
  AC_REQUIRE([AC_PROG_CC])
Packit Service a2489d
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit Service a2489d
  AC_CACHE_CHECK([whether printf supports the left-adjust flag correctly],
Packit Service a2489d
    [gl_cv_func_printf_flag_leftadjust],
Packit Service a2489d
    [
Packit Service a2489d
      AC_RUN_IFELSE(
Packit Service a2489d
        [AC_LANG_SOURCE([[
Packit Service a2489d
#include <stdio.h>
Packit Service a2489d
#include <string.h>
Packit Service a2489d
static char buf[100];
Packit Service a2489d
int main ()
Packit Service a2489d
{
Packit Service a2489d
  /* Check that a '-' flag is not annihilated by a negative width.  */
Packit Service a2489d
  if (sprintf (buf, "a%-*sc", -3, "b") < 0
Packit Service a2489d
      || strcmp (buf, "ab  c") != 0)
Packit Service a2489d
    return 1;
Packit Service a2489d
  return 0;
Packit Service a2489d
}]])],
Packit Service a2489d
        [gl_cv_func_printf_flag_leftadjust=yes],
Packit Service a2489d
        [gl_cv_func_printf_flag_leftadjust=no],
Packit Service a2489d
        [
Packit Service a2489d
changequote(,)dnl
Packit Service a2489d
         case "$host_os" in
Packit Service a2489d
                    # Guess yes on HP-UX 11.
Packit Service a2489d
           hpux11*) gl_cv_func_printf_flag_leftadjust="guessing yes";;
Packit Service a2489d
                    # Guess no on HP-UX 10 and older.
Packit Service a2489d
           hpux*)   gl_cv_func_printf_flag_leftadjust="guessing no";;
Packit Service a2489d
                    # Guess yes on native Windows.
Packit Service a2489d
           mingw*)  gl_cv_func_printf_flag_leftadjust="guessing yes";;
Packit Service a2489d
                    # Guess yes otherwise.
Packit Service a2489d
           *)       gl_cv_func_printf_flag_leftadjust="guessing yes";;
Packit Service a2489d
         esac
Packit Service a2489d
changequote([,])dnl
Packit Service a2489d
        ])
Packit Service a2489d
    ])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl Test whether the *printf family of functions supports padding of non-finite
Packit Service a2489d
dnl values with the 0 flag correctly. (ISO C99 + TC1 + TC2.) See
Packit Service a2489d
dnl <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html>
Packit Service a2489d
dnl Result is gl_cv_func_printf_flag_zero.
Packit Service a2489d
Packit Service a2489d
AC_DEFUN([gl_PRINTF_FLAG_ZERO],
Packit Service a2489d
[
Packit Service a2489d
  AC_REQUIRE([AC_PROG_CC])
Packit Service a2489d
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit Service a2489d
  AC_CACHE_CHECK([whether printf supports the zero flag correctly],
Packit Service a2489d
    [gl_cv_func_printf_flag_zero],
Packit Service a2489d
    [
Packit Service a2489d
      AC_RUN_IFELSE(
Packit Service a2489d
        [AC_LANG_SOURCE([[
Packit Service a2489d
#include <stdio.h>
Packit Service a2489d
#include <string.h>
Packit Service a2489d
static char buf[100];
Packit Service a2489d
static double zero = 0.0;
Packit Service a2489d
int main ()
Packit Service a2489d
{
Packit Service a2489d
  if (sprintf (buf, "%010f", 1.0 / zero, 33, 44, 55) < 0
Packit Service a2489d
      || (strcmp (buf, "       inf") != 0
Packit Service a2489d
          && strcmp (buf, "  infinity") != 0))
Packit Service a2489d
    return 1;
Packit Service a2489d
  return 0;
Packit Service a2489d
}]])],
Packit Service a2489d
        [gl_cv_func_printf_flag_zero=yes],
Packit Service a2489d
        [gl_cv_func_printf_flag_zero=no],
Packit Service a2489d
        [
Packit Service a2489d
changequote(,)dnl
Packit Service a2489d
         case "$host_os" in
Packit Service a2489d
                          # Guess yes on glibc systems.
Packit Service a2489d
           *-gnu* | gnu*) gl_cv_func_printf_flag_zero="guessing yes";;
Packit Service a2489d
                          # Guess yes on BeOS.
Packit Service a2489d
           beos*)         gl_cv_func_printf_flag_zero="guessing yes";;
Packit Service a2489d
                          # Guess no on native Windows.
Packit Service a2489d
           mingw*)        gl_cv_func_printf_flag_zero="guessing no";;
Packit Service a2489d
                          # If we don't know, assume the worst.
Packit Service a2489d
           *)             gl_cv_func_printf_flag_zero="guessing no";;
Packit Service a2489d
         esac
Packit Service a2489d
changequote([,])dnl
Packit Service a2489d
        ])
Packit Service a2489d
    ])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl Test whether the *printf family of functions supports large precisions.
Packit Service a2489d
dnl On mingw, precisions larger than 512 are treated like 512, in integer,
Packit Service a2489d
dnl floating-point or pointer output. On Solaris 10/x86, precisions larger
Packit Service a2489d
dnl than 510 in floating-point output crash the program. On Solaris 10/SPARC,
Packit Service a2489d
dnl precisions larger than 510 in floating-point output yield wrong results.
Packit Service a2489d
dnl On AIX 7.1, precisions larger than 998 in floating-point output yield
Packit Service a2489d
dnl wrong results. On BeOS, precisions larger than 1044 crash the program.
Packit Service a2489d
dnl Result is gl_cv_func_printf_precision.
Packit Service a2489d
Packit Service a2489d
AC_DEFUN([gl_PRINTF_PRECISION],
Packit Service a2489d
[
Packit Service a2489d
  AC_REQUIRE([AC_PROG_CC])
Packit Service a2489d
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit Service a2489d
  AC_CACHE_CHECK([whether printf supports large precisions],
Packit Service a2489d
    [gl_cv_func_printf_precision],
Packit Service a2489d
    [
Packit Service a2489d
      AC_RUN_IFELSE(
Packit Service a2489d
        [AC_LANG_SOURCE([[
Packit Service a2489d
#include <stdio.h>
Packit Service a2489d
#include <string.h>
Packit Service a2489d
static char buf[5000];
Packit Service a2489d
int main ()
Packit Service a2489d
{
Packit Service a2489d
  int result = 0;
Packit Service a2489d
#ifdef __BEOS__
Packit Service a2489d
  /* On BeOS, this would crash and show a dialog box.  Avoid the crash.  */
Packit Service a2489d
  return 1;
Packit Service a2489d
#endif
Packit Service a2489d
  if (sprintf (buf, "%.4000d %d", 1, 33, 44) < 4000 + 3)
Packit Service a2489d
    result |= 1;
Packit Service a2489d
  if (sprintf (buf, "%.4000f %d", 1.0, 33, 44) < 4000 + 5)
Packit Service a2489d
    result |= 2;
Packit Service a2489d
  if (sprintf (buf, "%.511f %d", 1.0, 33, 44) < 511 + 5
Packit Service a2489d
      || buf[0] != '1')
Packit Service a2489d
    result |= 4;
Packit Service a2489d
  if (sprintf (buf, "%.999f %d", 1.0, 33, 44) < 999 + 5
Packit Service a2489d
      || buf[0] != '1')
Packit Service a2489d
    result |= 4;
Packit Service a2489d
  return result;
Packit Service a2489d
}]])],
Packit Service a2489d
        [gl_cv_func_printf_precision=yes],
Packit Service a2489d
        [gl_cv_func_printf_precision=no],
Packit Service a2489d
        [
Packit Service a2489d
changequote(,)dnl
Packit Service a2489d
         case "$host_os" in
Packit Service a2489d
           # Guess no only on Solaris, native Windows, and BeOS systems.
Packit Service a2489d
           solaris*)     gl_cv_func_printf_precision="guessing no" ;;
Packit Service a2489d
           mingw* | pw*) gl_cv_func_printf_precision="guessing no" ;;
Packit Service a2489d
           beos*)        gl_cv_func_printf_precision="guessing no" ;;
Packit Service a2489d
           *)            gl_cv_func_printf_precision="guessing yes" ;;
Packit Service a2489d
         esac
Packit Service a2489d
changequote([,])dnl
Packit Service a2489d
        ])
Packit Service a2489d
    ])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl Test whether the *printf family of functions recovers gracefully in case
Packit Service a2489d
dnl of an out-of-memory condition, or whether it crashes the entire program.
Packit Service a2489d
dnl Result is gl_cv_func_printf_enomem.
Packit Service a2489d
Packit Service a2489d
AC_DEFUN([gl_PRINTF_ENOMEM],
Packit Service a2489d
[
Packit Service a2489d
  AC_REQUIRE([AC_PROG_CC])
Packit Service a2489d
  AC_REQUIRE([gl_MULTIARCH])
Packit Service a2489d
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit Service a2489d
  AC_CACHE_CHECK([whether printf survives out-of-memory conditions],
Packit Service a2489d
    [gl_cv_func_printf_enomem],
Packit Service a2489d
    [
Packit Service a2489d
      gl_cv_func_printf_enomem="guessing no"
Packit Service a2489d
      if test "$cross_compiling" = no; then
Packit Service a2489d
        if test $APPLE_UNIVERSAL_BUILD = 0; then
Packit Service a2489d
          AC_LANG_CONFTEST([AC_LANG_SOURCE([
Packit Service a2489d
]GL_NOCRASH[
Packit Service a2489d
changequote(,)dnl
Packit Service a2489d
#include <stdio.h>
Packit Service a2489d
#include <sys/types.h>
Packit Service a2489d
#include <sys/time.h>
Packit Service a2489d
#include <sys/resource.h>
Packit Service a2489d
#include <errno.h>
Packit Service a2489d
int main()
Packit Service a2489d
{
Packit Service a2489d
  struct rlimit limit;
Packit Service a2489d
  int ret;
Packit Service a2489d
  nocrash_init ();
Packit Service a2489d
  /* Some printf implementations allocate temporary space with malloc.  */
Packit Service a2489d
  /* On BSD systems, malloc() is limited by RLIMIT_DATA.  */
Packit Service a2489d
#ifdef RLIMIT_DATA
Packit Service a2489d
  if (getrlimit (RLIMIT_DATA, &limit) < 0)
Packit Service a2489d
    return 77;
Packit Service a2489d
  if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
Packit Service a2489d
    limit.rlim_max = 5000000;
Packit Service a2489d
  limit.rlim_cur = limit.rlim_max;
Packit Service a2489d
  if (setrlimit (RLIMIT_DATA, &limit) < 0)
Packit Service a2489d
    return 77;
Packit Service a2489d
#endif
Packit Service a2489d
  /* On Linux systems, malloc() is limited by RLIMIT_AS.  */
Packit Service a2489d
#ifdef RLIMIT_AS
Packit Service a2489d
  if (getrlimit (RLIMIT_AS, &limit) < 0)
Packit Service a2489d
    return 77;
Packit Service a2489d
  if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
Packit Service a2489d
    limit.rlim_max = 5000000;
Packit Service a2489d
  limit.rlim_cur = limit.rlim_max;
Packit Service a2489d
  if (setrlimit (RLIMIT_AS, &limit) < 0)
Packit Service a2489d
    return 77;
Packit Service a2489d
#endif
Packit Service a2489d
  /* Some printf implementations allocate temporary space on the stack.  */
Packit Service a2489d
#ifdef RLIMIT_STACK
Packit Service a2489d
  if (getrlimit (RLIMIT_STACK, &limit) < 0)
Packit Service a2489d
    return 77;
Packit Service a2489d
  if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
Packit Service a2489d
    limit.rlim_max = 5000000;
Packit Service a2489d
  limit.rlim_cur = limit.rlim_max;
Packit Service a2489d
  if (setrlimit (RLIMIT_STACK, &limit) < 0)
Packit Service a2489d
    return 77;
Packit Service a2489d
#endif
Packit Service a2489d
  ret = printf ("%.5000000f", 1.0);
Packit Service a2489d
  return !(ret == 5000002 || (ret < 0 && errno == ENOMEM));
Packit Service a2489d
}
Packit Service a2489d
changequote([,])dnl
Packit Service a2489d
          ])])
Packit Service a2489d
          if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
Packit Service a2489d
            (./conftest 2>&AS_MESSAGE_LOG_FD
Packit Service a2489d
             result=$?
Packit Service a2489d
             _AS_ECHO_LOG([\$? = $result])
Packit Service a2489d
             if test $result != 0 && test $result != 77; then result=1; fi
Packit Service a2489d
             exit $result
Packit Service a2489d
            ) >/dev/null 2>/dev/null
Packit Service a2489d
            case $? in
Packit Service a2489d
              0) gl_cv_func_printf_enomem="yes" ;;
Packit Service a2489d
              77) gl_cv_func_printf_enomem="guessing no" ;;
Packit Service a2489d
              *) gl_cv_func_printf_enomem="no" ;;
Packit Service a2489d
            esac
Packit Service a2489d
          else
Packit Service a2489d
            gl_cv_func_printf_enomem="guessing no"
Packit Service a2489d
          fi
Packit Service a2489d
          rm -fr conftest*
Packit Service a2489d
        else
Packit Service a2489d
          dnl A universal build on Apple Mac OS X platforms.
Packit Service a2489d
          dnl The result would be 'no' in 32-bit mode and 'yes' in 64-bit mode.
Packit Service a2489d
          dnl But we need a configuration result that is valid in both modes.
Packit Service a2489d
          gl_cv_func_printf_enomem="guessing no"
Packit Service a2489d
        fi
Packit Service a2489d
      fi
Packit Service a2489d
      if test "$gl_cv_func_printf_enomem" = "guessing no"; then
Packit Service a2489d
changequote(,)dnl
Packit Service a2489d
        case "$host_os" in
Packit Service a2489d
                         # Guess yes on glibc systems.
Packit Service a2489d
          *-gnu* | gnu*) gl_cv_func_printf_enomem="guessing yes";;
Packit Service a2489d
                         # Guess yes on Solaris.
Packit Service a2489d
          solaris*)      gl_cv_func_printf_enomem="guessing yes";;
Packit Service a2489d
                         # Guess yes on AIX.
Packit Service a2489d
          aix*)          gl_cv_func_printf_enomem="guessing yes";;
Packit Service a2489d
                         # Guess yes on HP-UX/hppa.
Packit Service a2489d
          hpux*)         case "$host_cpu" in
Packit Service a2489d
                           hppa*) gl_cv_func_printf_enomem="guessing yes";;
Packit Service a2489d
                           *)     gl_cv_func_printf_enomem="guessing no";;
Packit Service a2489d
                         esac
Packit Service a2489d
                         ;;
Packit Service a2489d
                         # Guess yes on IRIX.
Packit Service a2489d
          irix*)         gl_cv_func_printf_enomem="guessing yes";;
Packit Service a2489d
                         # Guess yes on OSF/1.
Packit Service a2489d
          osf*)          gl_cv_func_printf_enomem="guessing yes";;
Packit Service a2489d
                         # Guess yes on BeOS.
Packit Service a2489d
          beos*)         gl_cv_func_printf_enomem="guessing yes";;
Packit Service a2489d
                         # Guess yes on Haiku.
Packit Service a2489d
          haiku*)        gl_cv_func_printf_enomem="guessing yes";;
Packit Service a2489d
                         # If we don't know, assume the worst.
Packit Service a2489d
          *)             gl_cv_func_printf_enomem="guessing no";;
Packit Service a2489d
        esac
Packit Service a2489d
changequote([,])dnl
Packit Service a2489d
      fi
Packit Service a2489d
    ])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl Test whether the snprintf function exists. (ISO C99, POSIX:2001)
Packit Service a2489d
dnl Result is ac_cv_func_snprintf.
Packit Service a2489d
Packit Service a2489d
AC_DEFUN([gl_SNPRINTF_PRESENCE],
Packit Service a2489d
[
Packit Service a2489d
  AC_CHECK_FUNCS_ONCE([snprintf])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl Test whether the string produced by the snprintf function is always NUL
Packit Service a2489d
dnl terminated. (ISO C99, POSIX:2001)
Packit Service a2489d
dnl Result is gl_cv_func_snprintf_truncation_c99.
Packit Service a2489d
Packit Service a2489d
AC_DEFUN([gl_SNPRINTF_TRUNCATION_C99],
Packit Service a2489d
[
Packit Service a2489d
  AC_REQUIRE([AC_PROG_CC])
Packit Service a2489d
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit Service a2489d
  AC_REQUIRE([gl_SNPRINTF_PRESENCE])
Packit Service a2489d
  AC_CACHE_CHECK([whether snprintf truncates the result as in C99],
Packit Service a2489d
    [gl_cv_func_snprintf_truncation_c99],
Packit Service a2489d
    [
Packit Service a2489d
      AC_RUN_IFELSE(
Packit Service a2489d
        [AC_LANG_SOURCE([[
Packit Service a2489d
#include <stdio.h>
Packit Service a2489d
#include <string.h>
Packit Service a2489d
#if HAVE_SNPRINTF
Packit Service a2489d
# define my_snprintf snprintf
Packit Service a2489d
#else
Packit Service a2489d
# include <stdarg.h>
Packit Service a2489d
static int my_snprintf (char *buf, int size, const char *format, ...)
Packit Service a2489d
{
Packit Service a2489d
  va_list args;
Packit Service a2489d
  int ret;
Packit Service a2489d
  va_start (args, format);
Packit Service a2489d
  ret = vsnprintf (buf, size, format, args);
Packit Service a2489d
  va_end (args);
Packit Service a2489d
  return ret;
Packit Service a2489d
}
Packit Service a2489d
#endif
Packit Service a2489d
static char buf[100];
Packit Service a2489d
int main ()
Packit Service a2489d
{
Packit Service a2489d
  strcpy (buf, "ABCDEF");
Packit Service a2489d
  my_snprintf (buf, 3, "%d %d", 4567, 89);
Packit Service a2489d
  if (memcmp (buf, "45\0DEF", 6) != 0)
Packit Service a2489d
    return 1;
Packit Service a2489d
  return 0;
Packit Service a2489d
}]])],
Packit Service a2489d
        [gl_cv_func_snprintf_truncation_c99=yes],
Packit Service a2489d
        [gl_cv_func_snprintf_truncation_c99=no],
Packit Service a2489d
        [
Packit Service a2489d
changequote(,)dnl
Packit Service a2489d
         case "$host_os" in
Packit Service a2489d
                                 # Guess yes on glibc systems.
Packit Service a2489d
           *-gnu* | gnu*)        gl_cv_func_snprintf_truncation_c99="guessing yes";;
Packit Service a2489d
                                 # Guess yes on FreeBSD >= 5.
Packit Service a2489d
           freebsd[1-4].*)       gl_cv_func_snprintf_truncation_c99="guessing no";;
Packit Service a2489d
           freebsd* | kfreebsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
Packit Service a2489d
                                 # Guess yes on Mac OS X >= 10.3.
Packit Service a2489d
           darwin[1-6].*)        gl_cv_func_snprintf_truncation_c99="guessing no";;
Packit Service a2489d
           darwin*)              gl_cv_func_snprintf_truncation_c99="guessing yes";;
Packit Service a2489d
                                 # Guess yes on OpenBSD >= 3.9.
Packit Service a2489d
           openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
Packit Service a2489d
                                 gl_cv_func_snprintf_truncation_c99="guessing no";;
Packit Service a2489d
           openbsd*)             gl_cv_func_snprintf_truncation_c99="guessing yes";;
Packit Service a2489d
                                 # Guess yes on Solaris >= 2.6.
Packit Service a2489d
           solaris2.[0-5] | solaris2.[0-5].*)
Packit Service a2489d
                                 gl_cv_func_snprintf_truncation_c99="guessing no";;
Packit Service a2489d
           solaris*)             gl_cv_func_snprintf_truncation_c99="guessing yes";;
Packit Service a2489d
                                 # Guess yes on AIX >= 4.
Packit Service a2489d
           aix[1-3]*)            gl_cv_func_snprintf_truncation_c99="guessing no";;
Packit Service a2489d
           aix*)                 gl_cv_func_snprintf_truncation_c99="guessing yes";;
Packit Service a2489d
                                 # Guess yes on HP-UX >= 11.
Packit Service a2489d
           hpux[7-9]* | hpux10*) gl_cv_func_snprintf_truncation_c99="guessing no";;
Packit Service a2489d
           hpux*)                gl_cv_func_snprintf_truncation_c99="guessing yes";;
Packit Service a2489d
                                 # Guess yes on IRIX >= 6.5.
Packit Service a2489d
           irix6.5)              gl_cv_func_snprintf_truncation_c99="guessing yes";;
Packit Service a2489d
                                 # Guess yes on OSF/1 >= 5.
Packit Service a2489d
           osf[3-4]*)            gl_cv_func_snprintf_truncation_c99="guessing no";;
Packit Service a2489d
           osf*)                 gl_cv_func_snprintf_truncation_c99="guessing yes";;
Packit Service a2489d
                                 # Guess yes on NetBSD >= 3.
Packit Service a2489d
           netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
Packit Service a2489d
                                 gl_cv_func_snprintf_truncation_c99="guessing no";;
Packit Service a2489d
           netbsd*)              gl_cv_func_snprintf_truncation_c99="guessing yes";;
Packit Service a2489d
                                 # Guess yes on BeOS.
Packit Service a2489d
           beos*)                gl_cv_func_snprintf_truncation_c99="guessing yes";;
Packit Service a2489d
                                 # Guess no on native Windows.
Packit Service a2489d
           mingw*)               gl_cv_func_snprintf_truncation_c99="guessing no";;
Packit Service a2489d
                                 # If we don't know, assume the worst.
Packit Service a2489d
           *)                    gl_cv_func_snprintf_truncation_c99="guessing no";;
Packit Service a2489d
         esac
Packit Service a2489d
changequote([,])dnl
Packit Service a2489d
        ])
Packit Service a2489d
    ])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl Test whether the return value of the snprintf function is the number
Packit Service a2489d
dnl of bytes (excluding the terminating NUL) that would have been produced
Packit Service a2489d
dnl if the buffer had been large enough. (ISO C99, POSIX:2001)
Packit Service a2489d
dnl For example, this test program fails on IRIX 6.5:
Packit Service a2489d
dnl     ---------------------------------------------------------------------
Packit Service a2489d
dnl     #include <stdio.h>
Packit Service a2489d
dnl     int main()
Packit Service a2489d
dnl     {
Packit Service a2489d
dnl       static char buf[8];
Packit Service a2489d
dnl       int retval = snprintf (buf, 3, "%d", 12345);
Packit Service a2489d
dnl       return retval >= 0 && retval < 3;
Packit Service a2489d
dnl     }
Packit Service a2489d
dnl     ---------------------------------------------------------------------
Packit Service a2489d
dnl Result is gl_cv_func_snprintf_retval_c99.
Packit Service a2489d
Packit Service a2489d
AC_DEFUN_ONCE([gl_SNPRINTF_RETVAL_C99],
Packit Service a2489d
[
Packit Service a2489d
  AC_REQUIRE([AC_PROG_CC])
Packit Service a2489d
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit Service a2489d
  AC_REQUIRE([gl_SNPRINTF_PRESENCE])
Packit Service a2489d
  AC_CACHE_CHECK([whether snprintf returns a byte count as in C99],
Packit Service a2489d
    [gl_cv_func_snprintf_retval_c99],
Packit Service a2489d
    [
Packit Service a2489d
      AC_RUN_IFELSE(
Packit Service a2489d
        [AC_LANG_SOURCE([[
Packit Service a2489d
#include <stdio.h>
Packit Service a2489d
#include <string.h>
Packit Service a2489d
#if HAVE_SNPRINTF
Packit Service a2489d
# define my_snprintf snprintf
Packit Service a2489d
#else
Packit Service a2489d
# include <stdarg.h>
Packit Service a2489d
static int my_snprintf (char *buf, int size, const char *format, ...)
Packit Service a2489d
{
Packit Service a2489d
  va_list args;
Packit Service a2489d
  int ret;
Packit Service a2489d
  va_start (args, format);
Packit Service a2489d
  ret = vsnprintf (buf, size, format, args);
Packit Service a2489d
  va_end (args);
Packit Service a2489d
  return ret;
Packit Service a2489d
}
Packit Service a2489d
#endif
Packit Service a2489d
static char buf[100];
Packit Service a2489d
int main ()
Packit Service a2489d
{
Packit Service a2489d
  strcpy (buf, "ABCDEF");
Packit Service a2489d
  if (my_snprintf (buf, 3, "%d %d", 4567, 89) != 7)
Packit Service a2489d
    return 1;
Packit Service a2489d
  if (my_snprintf (buf, 0, "%d %d", 4567, 89) != 7)
Packit Service a2489d
    return 2;
Packit Service a2489d
  if (my_snprintf (NULL, 0, "%d %d", 4567, 89) != 7)
Packit Service a2489d
    return 3;
Packit Service a2489d
  return 0;
Packit Service a2489d
}]])],
Packit Service a2489d
        [gl_cv_func_snprintf_retval_c99=yes],
Packit Service a2489d
        [gl_cv_func_snprintf_retval_c99=no],
Packit Service a2489d
        [case "$host_os" in
Packit Service a2489d
changequote(,)dnl
Packit Service a2489d
                                 # Guess yes on glibc systems.
Packit Service a2489d
           *-gnu* | gnu*)        gl_cv_func_snprintf_retval_c99="guessing yes";;
Packit Service a2489d
                                 # Guess yes on FreeBSD >= 5.
Packit Service a2489d
           freebsd[1-4].*)       gl_cv_func_snprintf_retval_c99="guessing no";;
Packit Service a2489d
           freebsd* | kfreebsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
Packit Service a2489d
                                 # Guess yes on Mac OS X >= 10.3.
Packit Service a2489d
           darwin[1-6].*)        gl_cv_func_snprintf_retval_c99="guessing no";;
Packit Service a2489d
           darwin*)              gl_cv_func_snprintf_retval_c99="guessing yes";;
Packit Service a2489d
                                 # Guess yes on OpenBSD >= 3.9.
Packit Service a2489d
           openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
Packit Service a2489d
                                 gl_cv_func_snprintf_retval_c99="guessing no";;
Packit Service a2489d
           openbsd*)             gl_cv_func_snprintf_retval_c99="guessing yes";;
Packit Service a2489d
                                 # Guess yes on Solaris >= 2.10.
Packit Service a2489d
           solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";;
Packit Service a2489d
           solaris*)             gl_cv_func_printf_sizes_c99="guessing no";;
Packit Service a2489d
                                 # Guess yes on AIX >= 4.
Packit Service a2489d
           aix[1-3]*)            gl_cv_func_snprintf_retval_c99="guessing no";;
Packit Service a2489d
           aix*)                 gl_cv_func_snprintf_retval_c99="guessing yes";;
Packit Service a2489d
                                 # Guess yes on NetBSD >= 3.
Packit Service a2489d
           netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
Packit Service a2489d
                                 gl_cv_func_snprintf_retval_c99="guessing no";;
Packit Service a2489d
           netbsd*)              gl_cv_func_snprintf_retval_c99="guessing yes";;
Packit Service a2489d
                                 # Guess yes on BeOS.
Packit Service a2489d
           beos*)                gl_cv_func_snprintf_retval_c99="guessing yes";;
Packit Service a2489d
changequote([,])dnl
Packit Service a2489d
                                 # Guess yes on MSVC, no on mingw.
Packit Service a2489d
           mingw*)               AC_EGREP_CPP([Known], [
Packit Service a2489d
#ifdef _MSC_VER
Packit Service a2489d
 Known
Packit Service a2489d
#endif
Packit Service a2489d
                                   ],
Packit Service a2489d
                                   [gl_cv_func_snprintf_retval_c99="guessing yes"],
Packit Service a2489d
                                   [gl_cv_func_snprintf_retval_c99="guessing no"])
Packit Service a2489d
                                 ;;
Packit Service a2489d
                                 # If we don't know, assume the worst.
Packit Service a2489d
           *)                    gl_cv_func_snprintf_retval_c99="guessing no";;
Packit Service a2489d
         esac
Packit Service a2489d
        ])
Packit Service a2489d
    ])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl Test whether the snprintf function supports the %n format directive
Packit Service a2489d
dnl also in truncated portions of the format string. (ISO C99, POSIX:2001)
Packit Service a2489d
dnl Result is gl_cv_func_snprintf_directive_n.
Packit Service a2489d
Packit Service a2489d
AC_DEFUN([gl_SNPRINTF_DIRECTIVE_N],
Packit Service a2489d
[
Packit Service a2489d
  AC_REQUIRE([AC_PROG_CC])
Packit Service a2489d
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit Service a2489d
  AC_REQUIRE([gl_SNPRINTF_PRESENCE])
Packit Service a2489d
  AC_CACHE_CHECK([whether snprintf fully supports the 'n' directive],
Packit Service a2489d
    [gl_cv_func_snprintf_directive_n],
Packit Service a2489d
    [
Packit Service a2489d
      AC_RUN_IFELSE(
Packit Service a2489d
        [AC_LANG_SOURCE([[
Packit Service a2489d
#include <stdio.h>
Packit Service a2489d
#include <string.h>
Packit Service a2489d
#if HAVE_SNPRINTF
Packit Service a2489d
# define my_snprintf snprintf
Packit Service a2489d
#else
Packit Service a2489d
# include <stdarg.h>
Packit Service a2489d
static int my_snprintf (char *buf, int size, const char *format, ...)
Packit Service a2489d
{
Packit Service a2489d
  va_list args;
Packit Service a2489d
  int ret;
Packit Service a2489d
  va_start (args, format);
Packit Service a2489d
  ret = vsnprintf (buf, size, format, args);
Packit Service a2489d
  va_end (args);
Packit Service a2489d
  return ret;
Packit Service a2489d
}
Packit Service a2489d
#endif
Packit Service a2489d
static char fmtstring[10];
Packit Service a2489d
static char buf[100];
Packit Service a2489d
int main ()
Packit Service a2489d
{
Packit Service a2489d
  int count = -1;
Packit Service a2489d
  /* Copy the format string.  Some systems (glibc with _FORTIFY_SOURCE=2)
Packit Service a2489d
     support %n in format strings in read-only memory but not in writable
Packit Service a2489d
     memory.  */
Packit Service a2489d
  strcpy (fmtstring, "%d %n");
Packit Service a2489d
  my_snprintf (buf, 4, fmtstring, 12345, &count, 33, 44, 55);
Packit Service a2489d
  if (count != 6)
Packit Service a2489d
    return 1;
Packit Service a2489d
  return 0;
Packit Service a2489d
}]])],
Packit Service a2489d
        [gl_cv_func_snprintf_directive_n=yes],
Packit Service a2489d
        [gl_cv_func_snprintf_directive_n=no],
Packit Service a2489d
        [
Packit Service a2489d
changequote(,)dnl
Packit Service a2489d
         case "$host_os" in
Packit Service a2489d
                                 # Guess yes on glibc systems.
Packit Service a2489d
           *-gnu* | gnu*)        gl_cv_func_snprintf_directive_n="guessing yes";;
Packit Service a2489d
                                 # Guess yes on FreeBSD >= 5.
Packit Service a2489d
           freebsd[1-4].*)       gl_cv_func_snprintf_directive_n="guessing no";;
Packit Service a2489d
           freebsd* | kfreebsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
Packit Service a2489d
                                 # Guess yes on Mac OS X >= 10.3.
Packit Service a2489d
           darwin[1-6].*)        gl_cv_func_snprintf_directive_n="guessing no";;
Packit Service a2489d
           darwin*)              gl_cv_func_snprintf_directive_n="guessing yes";;
Packit Service a2489d
                                 # Guess yes on Solaris >= 2.6.
Packit Service a2489d
           solaris2.[0-5] | solaris2.[0-5].*)
Packit Service a2489d
                                 gl_cv_func_snprintf_directive_n="guessing no";;
Packit Service a2489d
           solaris*)             gl_cv_func_snprintf_directive_n="guessing yes";;
Packit Service a2489d
                                 # Guess yes on AIX >= 4.
Packit Service a2489d
           aix[1-3]*)            gl_cv_func_snprintf_directive_n="guessing no";;
Packit Service a2489d
           aix*)                 gl_cv_func_snprintf_directive_n="guessing yes";;
Packit Service a2489d
                                 # Guess yes on IRIX >= 6.5.
Packit Service a2489d
           irix6.5)              gl_cv_func_snprintf_directive_n="guessing yes";;
Packit Service a2489d
                                 # Guess yes on OSF/1 >= 5.
Packit Service a2489d
           osf[3-4]*)            gl_cv_func_snprintf_directive_n="guessing no";;
Packit Service a2489d
           osf*)                 gl_cv_func_snprintf_directive_n="guessing yes";;
Packit Service a2489d
                                 # Guess yes on NetBSD >= 3.
Packit Service a2489d
           netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
Packit Service a2489d
                                 gl_cv_func_snprintf_directive_n="guessing no";;
Packit Service a2489d
           netbsd*)              gl_cv_func_snprintf_directive_n="guessing yes";;
Packit Service a2489d
                                 # Guess yes on BeOS.
Packit Service a2489d
           beos*)                gl_cv_func_snprintf_directive_n="guessing yes";;
Packit Service a2489d
                                 # Guess no on native Windows.
Packit Service a2489d
           mingw*)               gl_cv_func_snprintf_directive_n="guessing no";;
Packit Service a2489d
                                 # If we don't know, assume the worst.
Packit Service a2489d
           *)                    gl_cv_func_snprintf_directive_n="guessing no";;
Packit Service a2489d
         esac
Packit Service a2489d
changequote([,])dnl
Packit Service a2489d
        ])
Packit Service a2489d
    ])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl Test whether the snprintf function, when passed a size = 1, writes any
Packit Service a2489d
dnl output without bounds in this case, behaving like sprintf. This is the
Packit Service a2489d
dnl case on Linux libc5.
Packit Service a2489d
dnl Result is gl_cv_func_snprintf_size1.
Packit Service a2489d
Packit Service a2489d
AC_DEFUN([gl_SNPRINTF_SIZE1],
Packit Service a2489d
[
Packit Service a2489d
  AC_REQUIRE([AC_PROG_CC])
Packit Service a2489d
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit Service a2489d
  AC_REQUIRE([gl_SNPRINTF_PRESENCE])
Packit Service a2489d
  AC_CACHE_CHECK([whether snprintf respects a size of 1],
Packit Service a2489d
    [gl_cv_func_snprintf_size1],
Packit Service a2489d
    [
Packit Service a2489d
      AC_RUN_IFELSE(
Packit Service a2489d
        [AC_LANG_SOURCE([[
Packit Service a2489d
#include <stdio.h>
Packit Service a2489d
#if HAVE_SNPRINTF
Packit Service a2489d
# define my_snprintf snprintf
Packit Service a2489d
#else
Packit Service a2489d
# include <stdarg.h>
Packit Service a2489d
static int my_snprintf (char *buf, int size, const char *format, ...)
Packit Service a2489d
{
Packit Service a2489d
  va_list args;
Packit Service a2489d
  int ret;
Packit Service a2489d
  va_start (args, format);
Packit Service a2489d
  ret = vsnprintf (buf, size, format, args);
Packit Service a2489d
  va_end (args);
Packit Service a2489d
  return ret;
Packit Service a2489d
}
Packit Service a2489d
#endif
Packit Service a2489d
int main()
Packit Service a2489d
{
Packit Service a2489d
  static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
Packit Service a2489d
  my_snprintf (buf, 1, "%d", 12345);
Packit Service a2489d
  return buf[1] != 'E';
Packit Service a2489d
}]])],
Packit Service a2489d
        [gl_cv_func_snprintf_size1=yes],
Packit Service a2489d
        [gl_cv_func_snprintf_size1=no],
Packit Service a2489d
        [case "$host_os" in
Packit Service a2489d
                   # Guess yes on native Windows.
Packit Service a2489d
           mingw*) gl_cv_func_snprintf_size1="guessing yes" ;;
Packit Service a2489d
           *)      gl_cv_func_snprintf_size1="guessing yes" ;;
Packit Service a2489d
         esac
Packit Service a2489d
        ])
Packit Service a2489d
    ])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl Test whether the vsnprintf function, when passed a zero size, produces no
Packit Service a2489d
dnl output. (ISO C99, POSIX:2001)
Packit Service a2489d
dnl For example, snprintf nevertheless writes a NUL byte in this case
Packit Service a2489d
dnl on OSF/1 5.1:
Packit Service a2489d
dnl     ---------------------------------------------------------------------
Packit Service a2489d
dnl     #include <stdio.h>
Packit Service a2489d
dnl     int main()
Packit Service a2489d
dnl     {
Packit Service a2489d
dnl       static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
Packit Service a2489d
dnl       snprintf (buf, 0, "%d", 12345);
Packit Service a2489d
dnl       return buf[0] != 'D';
Packit Service a2489d
dnl     }
Packit Service a2489d
dnl     ---------------------------------------------------------------------
Packit Service a2489d
dnl And vsnprintf writes any output without bounds in this case, behaving like
Packit Service a2489d
dnl vsprintf, on HP-UX 11 and OSF/1 5.1:
Packit Service a2489d
dnl     ---------------------------------------------------------------------
Packit Service a2489d
dnl     #include <stdarg.h>
Packit Service a2489d
dnl     #include <stdio.h>
Packit Service a2489d
dnl     static int my_snprintf (char *buf, int size, const char *format, ...)
Packit Service a2489d
dnl     {
Packit Service a2489d
dnl       va_list args;
Packit Service a2489d
dnl       int ret;
Packit Service a2489d
dnl       va_start (args, format);
Packit Service a2489d
dnl       ret = vsnprintf (buf, size, format, args);
Packit Service a2489d
dnl       va_end (args);
Packit Service a2489d
dnl       return ret;
Packit Service a2489d
dnl     }
Packit Service a2489d
dnl     int main()
Packit Service a2489d
dnl     {
Packit Service a2489d
dnl       static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
Packit Service a2489d
dnl       my_snprintf (buf, 0, "%d", 12345);
Packit Service a2489d
dnl       return buf[0] != 'D';
Packit Service a2489d
dnl     }
Packit Service a2489d
dnl     ---------------------------------------------------------------------
Packit Service a2489d
dnl Result is gl_cv_func_vsnprintf_zerosize_c99.
Packit Service a2489d
Packit Service a2489d
AC_DEFUN([gl_VSNPRINTF_ZEROSIZE_C99],
Packit Service a2489d
[
Packit Service a2489d
  AC_REQUIRE([AC_PROG_CC])
Packit Service a2489d
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit Service a2489d
  AC_CACHE_CHECK([whether vsnprintf respects a zero size as in C99],
Packit Service a2489d
    [gl_cv_func_vsnprintf_zerosize_c99],
Packit Service a2489d
    [
Packit Service a2489d
      AC_RUN_IFELSE(
Packit Service a2489d
        [AC_LANG_SOURCE([[
Packit Service a2489d
#include <stdarg.h>
Packit Service a2489d
#include <stdio.h>
Packit Service a2489d
static int my_snprintf (char *buf, int size, const char *format, ...)
Packit Service a2489d
{
Packit Service a2489d
  va_list args;
Packit Service a2489d
  int ret;
Packit Service a2489d
  va_start (args, format);
Packit Service a2489d
  ret = vsnprintf (buf, size, format, args);
Packit Service a2489d
  va_end (args);
Packit Service a2489d
  return ret;
Packit Service a2489d
}
Packit Service a2489d
int main()
Packit Service a2489d
{
Packit Service a2489d
  static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
Packit Service a2489d
  my_snprintf (buf, 0, "%d", 12345);
Packit Service a2489d
  return buf[0] != 'D';
Packit Service a2489d
}]])],
Packit Service a2489d
        [gl_cv_func_vsnprintf_zerosize_c99=yes],
Packit Service a2489d
        [gl_cv_func_vsnprintf_zerosize_c99=no],
Packit Service a2489d
        [
Packit Service a2489d
changequote(,)dnl
Packit Service a2489d
         case "$host_os" in
Packit Service a2489d
                                 # Guess yes on glibc systems.
Packit Service a2489d
           *-gnu* | gnu*)        gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
Packit Service a2489d
                                 # Guess yes on FreeBSD >= 5.
Packit Service a2489d
           freebsd[1-4].*)       gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
Packit Service a2489d
           freebsd* | kfreebsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
Packit Service a2489d
                                 # Guess yes on Mac OS X >= 10.3.
Packit Service a2489d
           darwin[1-6].*)        gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
Packit Service a2489d
           darwin*)              gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
Packit Service a2489d
                                 # Guess yes on Cygwin.
Packit Service a2489d
           cygwin*)              gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
Packit Service a2489d
                                 # Guess yes on Solaris >= 2.6.
Packit Service a2489d
           solaris2.[0-5] | solaris2.[0-5].*)
Packit Service a2489d
                                 gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
Packit Service a2489d
           solaris*)             gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
Packit Service a2489d
                                 # Guess yes on AIX >= 4.
Packit Service a2489d
           aix[1-3]*)            gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
Packit Service a2489d
           aix*)                 gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
Packit Service a2489d
                                 # Guess yes on IRIX >= 6.5.
Packit Service a2489d
           irix6.5)              gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
Packit Service a2489d
                                 # Guess yes on NetBSD >= 3.
Packit Service a2489d
           netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
Packit Service a2489d
                                 gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
Packit Service a2489d
           netbsd*)              gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
Packit Service a2489d
                                 # Guess yes on BeOS.
Packit Service a2489d
           beos*)                gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
Packit Service a2489d
                                 # Guess yes on native Windows.
Packit Service a2489d
           mingw* | pw*)         gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
Packit Service a2489d
                                 # If we don't know, assume the worst.
Packit Service a2489d
           *)                    gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
Packit Service a2489d
         esac
Packit Service a2489d
changequote([,])dnl
Packit Service a2489d
        ])
Packit Service a2489d
    ])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl The results of these tests on various platforms are:
Packit Service a2489d
dnl
Packit Service a2489d
dnl 1 = gl_PRINTF_SIZES_C99
Packit Service a2489d
dnl 2 = gl_PRINTF_LONG_DOUBLE
Packit Service a2489d
dnl 3 = gl_PRINTF_INFINITE
Packit Service a2489d
dnl 4 = gl_PRINTF_INFINITE_LONG_DOUBLE
Packit Service a2489d
dnl 5 = gl_PRINTF_DIRECTIVE_A
Packit Service a2489d
dnl 6 = gl_PRINTF_DIRECTIVE_F
Packit Service a2489d
dnl 7 = gl_PRINTF_DIRECTIVE_N
Packit Service a2489d
dnl 8 = gl_PRINTF_DIRECTIVE_LS
Packit Service a2489d
dnl 9 = gl_PRINTF_POSITIONS
Packit Service a2489d
dnl 10 = gl_PRINTF_FLAG_GROUPING
Packit Service a2489d
dnl 11 = gl_PRINTF_FLAG_LEFTADJUST
Packit Service a2489d
dnl 12 = gl_PRINTF_FLAG_ZERO
Packit Service a2489d
dnl 13 = gl_PRINTF_PRECISION
Packit Service a2489d
dnl 14 = gl_PRINTF_ENOMEM
Packit Service a2489d
dnl 15 = gl_SNPRINTF_PRESENCE
Packit Service a2489d
dnl 16 = gl_SNPRINTF_TRUNCATION_C99
Packit Service a2489d
dnl 17 = gl_SNPRINTF_RETVAL_C99
Packit Service a2489d
dnl 18 = gl_SNPRINTF_DIRECTIVE_N
Packit Service a2489d
dnl 19 = gl_SNPRINTF_SIZE1
Packit Service a2489d
dnl 20 = gl_VSNPRINTF_ZEROSIZE_C99
Packit Service a2489d
dnl
Packit Service a2489d
dnl 1 = checking whether printf supports size specifiers as in C99...
Packit Service a2489d
dnl 2 = checking whether printf supports 'long double' arguments...
Packit Service a2489d
dnl 3 = checking whether printf supports infinite 'double' arguments...
Packit Service a2489d
dnl 4 = checking whether printf supports infinite 'long double' arguments...
Packit Service a2489d
dnl 5 = checking whether printf supports the 'a' and 'A' directives...
Packit Service a2489d
dnl 6 = checking whether printf supports the 'F' directive...
Packit Service a2489d
dnl 7 = checking whether printf supports the 'n' directive...
Packit Service a2489d
dnl 8 = checking whether printf supports the 'ls' directive...
Packit Service a2489d
dnl 9 = checking whether printf supports POSIX/XSI format strings with positions...
Packit Service a2489d
dnl 10 = checking whether printf supports the grouping flag...
Packit Service a2489d
dnl 11 = checking whether printf supports the left-adjust flag correctly...
Packit Service a2489d
dnl 12 = checking whether printf supports the zero flag correctly...
Packit Service a2489d
dnl 13 = checking whether printf supports large precisions...
Packit Service a2489d
dnl 14 = checking whether printf survives out-of-memory conditions...
Packit Service a2489d
dnl 15 = checking for snprintf...
Packit Service a2489d
dnl 16 = checking whether snprintf truncates the result as in C99...
Packit Service a2489d
dnl 17 = checking whether snprintf returns a byte count as in C99...
Packit Service a2489d
dnl 18 = checking whether snprintf fully supports the 'n' directive...
Packit Service a2489d
dnl 19 = checking whether snprintf respects a size of 1...
Packit Service a2489d
dnl 20 = checking whether vsnprintf respects a zero size as in C99...
Packit Service a2489d
dnl
Packit Service a2489d
dnl . = yes, # = no.
Packit Service a2489d
dnl
Packit Service a2489d
dnl                                  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
Packit Service a2489d
dnl   glibc 2.5                      .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
Packit Service a2489d
dnl   glibc 2.3.6                    .  .  .  .  #  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
Packit Service a2489d
dnl   FreeBSD 5.4, 6.1               .  .  .  .  #  .  .  .  .  .  .  #  .  #  .  .  .  .  .  .
Packit Service a2489d
dnl   Mac OS X 10.5.8                .  .  .  #  #  .  .  .  .  .  .  #  .  .  .  .  .  .  .  .
Packit Service a2489d
dnl   Mac OS X 10.3.9                .  .  .  .  #  .  .  .  .  .  .  #  .  #  .  .  .  .  .  .
Packit Service a2489d
dnl   OpenBSD 3.9, 4.0               .  .  #  #  #  #  .  #  .  #  .  #  .  #  .  .  .  .  .  .
Packit Service a2489d
dnl   Cygwin 1.7.0 (2009)            .  .  .  #  .  .  .  ?  .  .  .  .  .  ?  .  .  .  .  .  .
Packit Service a2489d
dnl   Cygwin 1.5.25 (2008)           .  .  .  #  #  .  .  #  .  .  .  .  .  #  .  .  .  .  .  .
Packit Service a2489d
dnl   Cygwin 1.5.19 (2006)           #  .  .  #  #  #  .  #  .  #  .  #  #  #  .  .  .  .  .  .
Packit Service a2489d
dnl   Solaris 11.3                   .  .  .  .  #  .  .  #  .  .  .  .  .  .  .  .  .  .  .  .
Packit Service a2489d
dnl   Solaris 11.0                   .  .  #  #  #  .  .  #  .  .  .  #  .  .  .  .  .  .  .  .
Packit Service a2489d
dnl   Solaris 10                     .  .  #  #  #  .  .  #  .  .  .  #  #  .  .  .  .  .  .  .
Packit Service a2489d
dnl   Solaris 2.6 ... 9              #  .  #  #  #  #  .  #  .  .  .  #  #  .  .  .  #  .  .  .
Packit Service a2489d
dnl   Solaris 2.5.1                  #  .  #  #  #  #  .  #  .  .  .  #  .  .  #  #  #  #  #  #
Packit Service a2489d
dnl   AIX 7.1                        .  .  #  #  #  .  .  .  .  .  .  #  #  .  .  .  .  .  .  .
Packit Service a2489d
dnl   AIX 5.2                        .  .  #  #  #  .  .  .  .  .  .  #  .  .  .  .  .  .  .  .
Packit Service a2489d
dnl   AIX 4.3.2, 5.1                 #  .  #  #  #  #  .  .  .  .  .  #  .  .  .  .  #  .  .  .
Packit Service a2489d
dnl   HP-UX 11.31                    .  .  .  .  #  .  .  .  .  .  .  #  .  .  .  .  #  #  .  .
Packit Service a2489d
dnl   HP-UX 11.{00,11,23}            #  .  .  .  #  #  .  .  .  .  .  #  .  .  .  .  #  #  .  #
Packit Service a2489d
dnl   HP-UX 10.20                    #  .  #  .  #  #  .  ?  .  .  #  #  .  .  .  .  #  #  ?  #
Packit Service a2489d
dnl   IRIX 6.5                       #  .  #  #  #  #  .  #  .  .  .  #  .  .  .  .  #  .  .  .
Packit Service a2489d
dnl   OSF/1 5.1                      #  .  #  #  #  #  .  .  .  .  .  #  .  .  .  .  #  .  .  #
Packit Service a2489d
dnl   OSF/1 4.0d                     #  .  #  #  #  #  .  .  .  .  .  #  .  .  #  #  #  #  #  #
Packit Service a2489d
dnl   NetBSD 5.0                     .  .  .  #  #  .  .  .  .  .  .  #  .  #  .  .  .  .  .  .
Packit Service a2489d
dnl   NetBSD 4.0                     .  ?  ?  ?  ?  ?  .  ?  .  ?  ?  ?  ?  ?  .  .  .  ?  ?  ?
Packit Service a2489d
dnl   NetBSD 3.0                     .  .  .  .  #  #  .  ?  #  #  ?  #  .  #  .  .  .  .  .  .
Packit Service a2489d
dnl   Haiku                          .  .  .  #  #  #  .  #  .  .  .  .  .  ?  .  .  ?  .  .  .
Packit Service a2489d
dnl   BeOS                           #  #  .  #  #  #  .  ?  #  .  ?  .  #  ?  .  .  ?  .  .  .
Packit Service a2489d
dnl   old mingw / msvcrt             #  #  #  #  #  #  .  .  #  #  .  #  #  ?  .  #  #  #  .  .
Packit Service a2489d
dnl   MSVC 9                         #  #  #  #  #  #  #  .  #  #  .  #  #  ?  #  #  #  #  .  .
Packit Service a2489d
dnl   mingw 2009-2011                .  #  .  #  .  .  .  .  #  #  .  .  .  ?  .  .  .  .  .  .
Packit Service a2489d
dnl   mingw-w64 2011                 #  #  #  #  #  #  .  .  #  #  .  #  #  ?  .  #  #  #  .  .