Blame m4/printf.m4

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