Blame m4/printf.m4

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