Fix quoting of AC_LANG_SOURCE arguments.
[gnulib.git] / m4 / printf.m4
blob8a4aaf6dcd37e5ccd4311f178227c499d263e35d
1 # printf.m4 serial 68
2 dnl Copyright (C) 2003, 2007-2020 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 dnl Test whether the *printf family of functions supports the 'j', 'z', 't',
8 dnl 'L' size specifiers. (ISO C99, POSIX:2001)
9 dnl Result is gl_cv_func_printf_sizes_c99.
11 AC_DEFUN([gl_PRINTF_SIZES_C99],
13   AC_REQUIRE([AC_PROG_CC])
14   AC_REQUIRE([gl_AC_HEADER_STDINT_H])
15   AC_REQUIRE([gl_AC_HEADER_INTTYPES_H])
16   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
17   AC_CACHE_CHECK([whether printf supports size specifiers as in C99],
18     [gl_cv_func_printf_sizes_c99],
19     [
20       AC_RUN_IFELSE(
21         [AC_LANG_SOURCE([[
22 #include <stddef.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include <sys/types.h>
26 #if HAVE_STDINT_H_WITH_UINTMAX
27 # include <stdint.h>
28 #endif
29 #if HAVE_INTTYPES_H_WITH_UINTMAX
30 # include <inttypes.h>
31 #endif
32 static char buf[100];
33 int main ()
35   int result = 0;
36 #if HAVE_STDINT_H_WITH_UINTMAX || HAVE_INTTYPES_H_WITH_UINTMAX
37   buf[0] = '\0';
38   if (sprintf (buf, "%ju %d", (uintmax_t) 12345671, 33, 44, 55) < 0
39       || strcmp (buf, "12345671 33") != 0)
40     result |= 1;
41 #else
42   result |= 1;
43 #endif
44   buf[0] = '\0';
45   if (sprintf (buf, "%zu %d", (size_t) 12345672, 33, 44, 55) < 0
46       || strcmp (buf, "12345672 33") != 0)
47     result |= 2;
48   buf[0] = '\0';
49   if (sprintf (buf, "%tu %d", (ptrdiff_t) 12345673, 33, 44, 55) < 0
50       || strcmp (buf, "12345673 33") != 0)
51     result |= 4;
52   buf[0] = '\0';
53   if (sprintf (buf, "%Lg %d", (long double) 1.5, 33, 44, 55) < 0
54       || strcmp (buf, "1.5 33") != 0)
55     result |= 8;
56   return result;
57 }]])],
58         [gl_cv_func_printf_sizes_c99=yes],
59         [gl_cv_func_printf_sizes_c99=no],
60         [
61          case "$host_os" in
62 changequote(,)dnl
63                                  # Guess yes on glibc systems.
64            *-gnu* | gnu*)        gl_cv_func_printf_sizes_c99="guessing yes";;
65                                  # Guess yes on musl systems.
66            *-musl*)              gl_cv_func_printf_sizes_c99="guessing yes";;
67                                  # Guess yes on FreeBSD >= 5.
68            freebsd[1-4].*)       gl_cv_func_printf_sizes_c99="guessing no";;
69            freebsd* | kfreebsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
70                                  # Guess yes on Mac OS X >= 10.3.
71            darwin[1-6].*)        gl_cv_func_printf_sizes_c99="guessing no";;
72            darwin*)              gl_cv_func_printf_sizes_c99="guessing yes";;
73                                  # Guess yes on OpenBSD >= 3.9.
74            openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
75                                  gl_cv_func_printf_sizes_c99="guessing no";;
76            openbsd*)             gl_cv_func_printf_sizes_c99="guessing yes";;
77                                  # Guess yes on Solaris >= 2.10.
78            solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";;
79            solaris*)             gl_cv_func_printf_sizes_c99="guessing no";;
80                                  # Guess yes on NetBSD >= 3.
81            netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
82                                  gl_cv_func_printf_sizes_c99="guessing no";;
83            netbsd*)              gl_cv_func_printf_sizes_c99="guessing yes";;
84                                  # Guess yes on Android.
85            linux*-android*)      gl_cv_func_printf_sizes_c99="guessing yes";;
86 changequote([,])dnl
87                                  # Guess yes on MSVC, no on mingw.
88            mingw*)               AC_EGREP_CPP([Known], [
89 #ifdef _MSC_VER
90  Known
91 #endif
92                                    ],
93                                    [gl_cv_func_printf_sizes_c99="guessing yes"],
94                                    [gl_cv_func_printf_sizes_c99="guessing no"])
95                                  ;;
96                                  # If we don't know, obey --enable-cross-guesses.
97            *)                    gl_cv_func_printf_sizes_c99="$gl_cross_guess_normal";;
98          esac
99         ])
100     ])
103 dnl Test whether the *printf family of functions supports 'long double'
104 dnl arguments together with the 'L' size specifier. (ISO C99, POSIX:2001)
105 dnl Result is gl_cv_func_printf_long_double.
107 AC_DEFUN([gl_PRINTF_LONG_DOUBLE],
109   AC_REQUIRE([AC_PROG_CC])
110   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
111   AC_CACHE_CHECK([whether printf supports 'long double' arguments],
112     [gl_cv_func_printf_long_double],
113     [
114       AC_RUN_IFELSE(
115         [AC_LANG_SOURCE([[
116 #include <stdio.h>
117 #include <string.h>
118 static char buf[10000];
119 int main ()
121   int result = 0;
122   buf[0] = '\0';
123   if (sprintf (buf, "%Lf %d", 1.75L, 33, 44, 55) < 0
124       || strcmp (buf, "1.750000 33") != 0)
125     result |= 1;
126   buf[0] = '\0';
127   if (sprintf (buf, "%Le %d", 1.75L, 33, 44, 55) < 0
128       || strcmp (buf, "1.750000e+00 33") != 0)
129     result |= 2;
130   buf[0] = '\0';
131   if (sprintf (buf, "%Lg %d", 1.75L, 33, 44, 55) < 0
132       || strcmp (buf, "1.75 33") != 0)
133     result |= 4;
134   return result;
135 }]])],
136         [gl_cv_func_printf_long_double=yes],
137         [gl_cv_func_printf_long_double=no],
138         [case "$host_os" in
139                             # Guess no on BeOS.
140            beos*)           gl_cv_func_printf_long_double="guessing no";;
141                             # Guess yes on Android.
142            linux*-android*) gl_cv_func_printf_long_double="guessing yes";;
143                             # Guess yes on MSVC, no on mingw.
144            mingw*)          AC_EGREP_CPP([Known], [
145 #ifdef _MSC_VER
146  Known
147 #endif
148                               ],
149                               [gl_cv_func_printf_long_double="guessing yes"],
150                               [gl_cv_func_printf_long_double="guessing no"])
151                             ;;
152            *)               gl_cv_func_printf_long_double="guessing yes";;
153          esac
154         ])
155     ])
158 dnl Test whether the *printf family of functions supports infinite and NaN
159 dnl 'double' arguments and negative zero arguments in the %f, %e, %g
160 dnl directives. (ISO C99, POSIX:2001)
161 dnl Result is gl_cv_func_printf_infinite.
163 AC_DEFUN([gl_PRINTF_INFINITE],
165   AC_REQUIRE([AC_PROG_CC])
166   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
167   AC_CACHE_CHECK([whether printf supports infinite 'double' arguments],
168     [gl_cv_func_printf_infinite],
169     [
170       AC_RUN_IFELSE(
171         [AC_LANG_SOURCE([[
172 #include <stdio.h>
173 #include <string.h>
174 static int
175 strisnan (const char *string, size_t start_index, size_t end_index)
177   if (start_index < end_index)
178     {
179       if (string[start_index] == '-')
180         start_index++;
181       if (start_index + 3 <= end_index
182           && memcmp (string + start_index, "nan", 3) == 0)
183         {
184           start_index += 3;
185           if (start_index == end_index
186               || (string[start_index] == '(' && string[end_index - 1] == ')'))
187             return 1;
188         }
189     }
190   return 0;
192 static int
193 have_minus_zero ()
195   static double plus_zero = 0.0;
196   double minus_zero = - plus_zero;
197   return memcmp (&plus_zero, &minus_zero, sizeof (double)) != 0;
199 static char buf[10000];
200 static double zero = 0.0;
201 int main ()
203   int result = 0;
204   if (sprintf (buf, "%f", 1.0 / zero) < 0
205       || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
206     result |= 1;
207   if (sprintf (buf, "%f", -1.0 / zero) < 0
208       || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
209     result |= 1;
210   if (sprintf (buf, "%f", zero / zero) < 0
211       || !strisnan (buf, 0, strlen (buf)))
212     result |= 2;
213   if (sprintf (buf, "%e", 1.0 / zero) < 0
214       || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
215     result |= 4;
216   if (sprintf (buf, "%e", -1.0 / zero) < 0
217       || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
218     result |= 4;
219   if (sprintf (buf, "%e", zero / zero) < 0
220       || !strisnan (buf, 0, strlen (buf)))
221     result |= 8;
222   if (sprintf (buf, "%g", 1.0 / zero) < 0
223       || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
224     result |= 16;
225   if (sprintf (buf, "%g", -1.0 / zero) < 0
226       || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
227     result |= 16;
228   if (sprintf (buf, "%g", zero / zero) < 0
229       || !strisnan (buf, 0, strlen (buf)))
230     result |= 32;
231   /* This test fails on HP-UX 10.20.  */
232   if (have_minus_zero ())
233     if (sprintf (buf, "%g", - zero) < 0
234         || strcmp (buf, "-0") != 0)
235     result |= 64;
236   return result;
237 }]])],
238         [gl_cv_func_printf_infinite=yes],
239         [gl_cv_func_printf_infinite=no],
240         [
241          case "$host_os" in
242 changequote(,)dnl
243                                  # Guess yes on glibc systems.
244            *-gnu* | gnu*)        gl_cv_func_printf_infinite="guessing yes";;
245                                  # Guess yes on musl systems.
246            *-musl*)              gl_cv_func_printf_infinite="guessing yes";;
247                                  # Guess yes on FreeBSD >= 6.
248            freebsd[1-5].*)       gl_cv_func_printf_infinite="guessing no";;
249            freebsd* | kfreebsd*) gl_cv_func_printf_infinite="guessing yes";;
250                                  # Guess yes on Mac OS X >= 10.3.
251            darwin[1-6].*)        gl_cv_func_printf_infinite="guessing no";;
252            darwin*)              gl_cv_func_printf_infinite="guessing yes";;
253                                  # Guess yes on HP-UX >= 11.
254            hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite="guessing no";;
255            hpux*)                gl_cv_func_printf_infinite="guessing yes";;
256                                  # Guess yes on NetBSD >= 3.
257            netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
258                                  gl_cv_func_printf_infinite="guessing no";;
259            netbsd*)              gl_cv_func_printf_infinite="guessing yes";;
260                                  # Guess yes on BeOS.
261            beos*)                gl_cv_func_printf_infinite="guessing yes";;
262                                  # Guess no on Android.
263            linux*-android*)      gl_cv_func_printf_infinite="guessing no";;
264 changequote([,])dnl
265                                  # Guess yes on MSVC, no on mingw.
266            mingw*)               AC_EGREP_CPP([Known], [
267 #ifdef _MSC_VER
268  Known
269 #endif
270                                    ],
271                                    [gl_cv_func_printf_infinite="guessing yes"],
272                                    [gl_cv_func_printf_infinite="guessing no"])
273                                  ;;
274                                  # If we don't know, obey --enable-cross-guesses.
275            *)                    gl_cv_func_printf_infinite="$gl_cross_guess_normal";;
276          esac
277         ])
278     ])
281 dnl Test whether the *printf family of functions supports infinite and NaN
282 dnl 'long double' arguments in the %f, %e, %g directives. (ISO C99, POSIX:2001)
283 dnl Result is gl_cv_func_printf_infinite_long_double.
285 AC_DEFUN([gl_PRINTF_INFINITE_LONG_DOUBLE],
287   AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
288   AC_REQUIRE([AC_PROG_CC])
289   AC_REQUIRE([gl_BIGENDIAN])
290   AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
291   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
292   dnl The user can set or unset the variable gl_printf_safe to indicate
293   dnl that he wishes a safe handling of non-IEEE-754 'long double' values.
294   if test -n "$gl_printf_safe"; then
295     AC_DEFINE([CHECK_PRINTF_SAFE], [1],
296       [Define if you wish *printf() functions that have a safe handling of
297        non-IEEE-754 'long double' values.])
298   fi
299   case "$gl_cv_func_printf_long_double" in
300     *yes)
301       AC_CACHE_CHECK([whether printf supports infinite 'long double' arguments],
302         [gl_cv_func_printf_infinite_long_double],
303         [
304           AC_RUN_IFELSE(
305             [AC_LANG_SOURCE([[
306 ]GL_NOCRASH[
307 #include <float.h>
308 #include <stdio.h>
309 #include <string.h>
310 static int
311 strisnan (const char *string, size_t start_index, size_t end_index)
313   if (start_index < end_index)
314     {
315       if (string[start_index] == '-')
316         start_index++;
317       if (start_index + 3 <= end_index
318           && memcmp (string + start_index, "nan", 3) == 0)
319         {
320           start_index += 3;
321           if (start_index == end_index
322               || (string[start_index] == '(' && string[end_index - 1] == ')'))
323             return 1;
324         }
325     }
326   return 0;
328 static char buf[10000];
329 static long double zeroL = 0.0L;
330 int main ()
332   int result = 0;
333   nocrash_init();
334   if (sprintf (buf, "%Lf", 1.0L / zeroL) < 0
335       || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
336     result |= 1;
337   if (sprintf (buf, "%Lf", -1.0L / zeroL) < 0
338       || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
339     result |= 1;
340   if (sprintf (buf, "%Lf", zeroL / zeroL) < 0
341       || !strisnan (buf, 0, strlen (buf)))
342     result |= 1;
343   if (sprintf (buf, "%Le", 1.0L / zeroL) < 0
344       || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
345     result |= 1;
346   if (sprintf (buf, "%Le", -1.0L / zeroL) < 0
347       || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
348     result |= 1;
349   if (sprintf (buf, "%Le", zeroL / zeroL) < 0
350       || !strisnan (buf, 0, strlen (buf)))
351     result |= 1;
352   if (sprintf (buf, "%Lg", 1.0L / zeroL) < 0
353       || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
354     result |= 1;
355   if (sprintf (buf, "%Lg", -1.0L / zeroL) < 0
356       || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
357     result |= 1;
358   if (sprintf (buf, "%Lg", zeroL / zeroL) < 0
359       || !strisnan (buf, 0, strlen (buf)))
360     result |= 1;
361 #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
362 /* Representation of an 80-bit 'long double' as an initializer for a sequence
363    of 'unsigned int' words.  */
364 # ifdef WORDS_BIGENDIAN
365 #  define LDBL80_WORDS(exponent,manthi,mantlo) \
366      { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
367        ((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16),   \
368        (unsigned int) (mantlo) << 16                                        \
369      }
370 # else
371 #  define LDBL80_WORDS(exponent,manthi,mantlo) \
372      { mantlo, manthi, exponent }
373 # endif
374   { /* Quiet NaN.  */
375     static union { unsigned int word[4]; long double value; } x =
376       { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
377     if (sprintf (buf, "%Lf", x.value) < 0
378         || !strisnan (buf, 0, strlen (buf)))
379       result |= 2;
380     if (sprintf (buf, "%Le", x.value) < 0
381         || !strisnan (buf, 0, strlen (buf)))
382       result |= 2;
383     if (sprintf (buf, "%Lg", x.value) < 0
384         || !strisnan (buf, 0, strlen (buf)))
385       result |= 2;
386   }
387   {
388     /* Signalling NaN.  */
389     static union { unsigned int word[4]; long double value; } x =
390       { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
391     if (sprintf (buf, "%Lf", x.value) < 0
392         || !strisnan (buf, 0, strlen (buf)))
393       result |= 2;
394     if (sprintf (buf, "%Le", x.value) < 0
395         || !strisnan (buf, 0, strlen (buf)))
396       result |= 2;
397     if (sprintf (buf, "%Lg", x.value) < 0
398         || !strisnan (buf, 0, strlen (buf)))
399       result |= 2;
400   }
401   { /* Pseudo-NaN.  */
402     static union { unsigned int word[4]; long double value; } x =
403       { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
404     if (sprintf (buf, "%Lf", x.value) <= 0)
405       result |= 4;
406     if (sprintf (buf, "%Le", x.value) <= 0)
407       result |= 4;
408     if (sprintf (buf, "%Lg", x.value) <= 0)
409       result |= 4;
410   }
411   { /* Pseudo-Infinity.  */
412     static union { unsigned int word[4]; long double value; } x =
413       { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
414     if (sprintf (buf, "%Lf", x.value) <= 0)
415       result |= 8;
416     if (sprintf (buf, "%Le", x.value) <= 0)
417       result |= 8;
418     if (sprintf (buf, "%Lg", x.value) <= 0)
419       result |= 8;
420   }
421   { /* Pseudo-Zero.  */
422     static union { unsigned int word[4]; long double value; } x =
423       { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
424     if (sprintf (buf, "%Lf", x.value) <= 0)
425       result |= 16;
426     if (sprintf (buf, "%Le", x.value) <= 0)
427       result |= 16;
428     if (sprintf (buf, "%Lg", x.value) <= 0)
429       result |= 16;
430   }
431   { /* Unnormalized number.  */
432     static union { unsigned int word[4]; long double value; } x =
433       { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
434     if (sprintf (buf, "%Lf", x.value) <= 0)
435       result |= 32;
436     if (sprintf (buf, "%Le", x.value) <= 0)
437       result |= 32;
438     if (sprintf (buf, "%Lg", x.value) <= 0)
439       result |= 32;
440   }
441   { /* Pseudo-Denormal.  */
442     static union { unsigned int word[4]; long double value; } x =
443       { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
444     if (sprintf (buf, "%Lf", x.value) <= 0)
445       result |= 64;
446     if (sprintf (buf, "%Le", x.value) <= 0)
447       result |= 64;
448     if (sprintf (buf, "%Lg", x.value) <= 0)
449       result |= 64;
450   }
451 #endif
452   return result;
453 }]])],
454             [gl_cv_func_printf_infinite_long_double=yes],
455             [gl_cv_func_printf_infinite_long_double=no],
456             [case "$host_cpu" in
457                                      # Guess no on ia64, x86_64, i386.
458                ia64 | x86_64 | i*86) gl_cv_func_printf_infinite_long_double="guessing no";;
459                *)
460                  case "$host_os" in
461 changequote(,)dnl
462                                          # Guess yes on glibc systems.
463                    *-gnu* | gnu*)        gl_cv_func_printf_infinite_long_double="guessing yes";;
464                                          # Guess yes on musl systems.
465                    *-musl*)              gl_cv_func_printf_infinite_long_double="guessing yes";;
466                                          # Guess yes on FreeBSD >= 6.
467                    freebsd[1-5].*)       gl_cv_func_printf_infinite_long_double="guessing no";;
468                    freebsd* | kfreebsd*) gl_cv_func_printf_infinite_long_double="guessing yes";;
469                                          # Guess yes on HP-UX >= 11.
470                    hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite_long_double="guessing no";;
471                    hpux*)                gl_cv_func_printf_infinite_long_double="guessing yes";;
472                                          # Guess no on Android.
473                    linux*-android*)      gl_cv_func_printf_infinite_long_double="guessing no";;
474 changequote([,])dnl
475                                          # Guess yes on MSVC, no on mingw.
476                    mingw*)               AC_EGREP_CPP([Known], [
477 #ifdef _MSC_VER
478  Known
479 #endif
480                                            ],
481                                            [gl_cv_func_printf_infinite_long_double="guessing yes"],
482                                            [gl_cv_func_printf_infinite_long_double="guessing no"])
483                                          ;;
484                                          # If we don't know, obey --enable-cross-guesses.
485                    *)                    gl_cv_func_printf_infinite_long_double="$gl_cross_guess_normal";;
486                  esac
487                  ;;
488              esac
489             ])
490         ])
491       ;;
492     *)
493       gl_cv_func_printf_infinite_long_double="irrelevant"
494       ;;
495   esac
498 dnl Test whether the *printf family of functions supports the 'a' and 'A'
499 dnl conversion specifier for hexadecimal output of floating-point numbers.
500 dnl (ISO C99, POSIX:2001)
501 dnl Result is gl_cv_func_printf_directive_a.
503 AC_DEFUN([gl_PRINTF_DIRECTIVE_A],
505   AC_REQUIRE([AC_PROG_CC])
506   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
507   AC_CACHE_CHECK([whether printf supports the 'a' and 'A' directives],
508     [gl_cv_func_printf_directive_a],
509     [
510       AC_RUN_IFELSE(
511         [AC_LANG_SOURCE([[
512 #include <stdio.h>
513 #include <string.h>
514 static char buf[100];
515 static double zero = 0.0;
516 int main ()
518   int result = 0;
519   if (sprintf (buf, "%a %d", 3.1416015625, 33, 44, 55) < 0
520       || (strcmp (buf, "0x1.922p+1 33") != 0
521           && strcmp (buf, "0x3.244p+0 33") != 0
522           && strcmp (buf, "0x6.488p-1 33") != 0
523           && strcmp (buf, "0xc.91p-2 33") != 0))
524     result |= 1;
525   if (sprintf (buf, "%A %d", -3.1416015625, 33, 44, 55) < 0
526       || (strcmp (buf, "-0X1.922P+1 33") != 0
527           && strcmp (buf, "-0X3.244P+0 33") != 0
528           && strcmp (buf, "-0X6.488P-1 33") != 0
529           && strcmp (buf, "-0XC.91P-2 33") != 0))
530     result |= 2;
531   /* This catches a FreeBSD 6.1 bug: it doesn't round.  */
532   if (sprintf (buf, "%.2a %d", 1.51, 33, 44, 55) < 0
533       || (strcmp (buf, "0x1.83p+0 33") != 0
534           && strcmp (buf, "0x3.05p-1 33") != 0
535           && strcmp (buf, "0x6.0ap-2 33") != 0
536           && strcmp (buf, "0xc.14p-3 33") != 0))
537     result |= 4;
538   /* This catches a Mac OS X 10.12.4 (Darwin 16.5) bug: it doesn't round.  */
539   if (sprintf (buf, "%.0a %d", 1.51, 33, 44, 55) < 0
540       || (strcmp (buf, "0x2p+0 33") != 0
541           && strcmp (buf, "0x3p-1 33") != 0
542           && strcmp (buf, "0x6p-2 33") != 0
543           && strcmp (buf, "0xcp-3 33") != 0))
544     result |= 4;
545   /* This catches a FreeBSD 6.1 bug.  See
546      <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */
547   if (sprintf (buf, "%010a %d", 1.0 / zero, 33, 44, 55) < 0
548       || buf[0] == '0')
549     result |= 8;
550   /* This catches a Mac OS X 10.3.9 (Darwin 7.9) bug.  */
551   if (sprintf (buf, "%.1a", 1.999) < 0
552       || (strcmp (buf, "0x1.0p+1") != 0
553           && strcmp (buf, "0x2.0p+0") != 0
554           && strcmp (buf, "0x4.0p-1") != 0
555           && strcmp (buf, "0x8.0p-2") != 0))
556     result |= 16;
557   /* This catches the same Mac OS X 10.3.9 (Darwin 7.9) bug and also a
558      glibc 2.4 bug <https://sourceware.org/bugzilla/show_bug.cgi?id=2908>.  */
559   if (sprintf (buf, "%.1La", 1.999L) < 0
560       || (strcmp (buf, "0x1.0p+1") != 0
561           && strcmp (buf, "0x2.0p+0") != 0
562           && strcmp (buf, "0x4.0p-1") != 0
563           && strcmp (buf, "0x8.0p-2") != 0))
564     result |= 32;
565   return result;
566 }]])],
567         [gl_cv_func_printf_directive_a=yes],
568         [gl_cv_func_printf_directive_a=no],
569         [
570          case "$host_os" in
571                                  # Guess yes on glibc >= 2.5 systems.
572            *-gnu* | gnu*)
573              AC_EGREP_CPP([BZ2908], [
574                #include <features.h>
575                #ifdef __GNU_LIBRARY__
576                 #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 5) || (__GLIBC__ > 2)) && !defined __UCLIBC__
577                  BZ2908
578                 #endif
579                #endif
580                ],
581                [gl_cv_func_printf_directive_a="guessing yes"],
582                [gl_cv_func_printf_directive_a="guessing no"])
583              ;;
584                                  # Guess yes on musl systems.
585            *-musl*)              gl_cv_func_printf_directive_a="guessing yes";;
586                                  # Guess no on Android.
587            linux*-android*)      gl_cv_func_printf_directive_a="guessing no";;
588                                  # Guess no on native Windows.
589            mingw*)               gl_cv_func_printf_directive_a="guessing no";;
590                                  # If we don't know, obey --enable-cross-guesses.
591            *)                    gl_cv_func_printf_directive_a="$gl_cross_guess_normal";;
592          esac
593         ])
594     ])
597 dnl Test whether the *printf family of functions supports the %F format
598 dnl directive. (ISO C99, POSIX:2001)
599 dnl Result is gl_cv_func_printf_directive_f.
601 AC_DEFUN([gl_PRINTF_DIRECTIVE_F],
603   AC_REQUIRE([AC_PROG_CC])
604   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
605   AC_CACHE_CHECK([whether printf supports the 'F' directive],
606     [gl_cv_func_printf_directive_f],
607     [
608       AC_RUN_IFELSE(
609         [AC_LANG_SOURCE([[
610 #include <stdio.h>
611 #include <string.h>
612 static char buf[100];
613 static double zero = 0.0;
614 int main ()
616   int result = 0;
617   if (sprintf (buf, "%F %d", 1234567.0, 33, 44, 55) < 0
618       || strcmp (buf, "1234567.000000 33") != 0)
619     result |= 1;
620   if (sprintf (buf, "%F", 1.0 / zero) < 0
621       || (strcmp (buf, "INF") != 0 && strcmp (buf, "INFINITY") != 0))
622     result |= 2;
623   /* This catches a Cygwin 1.5.x bug.  */
624   if (sprintf (buf, "%.F", 1234.0) < 0
625       || strcmp (buf, "1234") != 0)
626     result |= 4;
627   return result;
628 }]])],
629         [gl_cv_func_printf_directive_f=yes],
630         [gl_cv_func_printf_directive_f=no],
631         [
632          case "$host_os" in
633 changequote(,)dnl
634                                  # Guess yes on glibc systems.
635            *-gnu* | gnu*)        gl_cv_func_printf_directive_f="guessing yes";;
636                                  # Guess yes on musl systems.
637            *-musl*)              gl_cv_func_printf_directive_f="guessing yes";;
638                                  # Guess yes on FreeBSD >= 6.
639            freebsd[1-5].*)       gl_cv_func_printf_directive_f="guessing no";;
640            freebsd* | kfreebsd*) gl_cv_func_printf_directive_f="guessing yes";;
641                                  # Guess yes on Mac OS X >= 10.3.
642            darwin[1-6].*)        gl_cv_func_printf_directive_f="guessing no";;
643            darwin*)              gl_cv_func_printf_directive_f="guessing yes";;
644                                  # Guess yes on Solaris >= 2.10.
645            solaris2.[1-9][0-9]*) gl_cv_func_printf_directive_f="guessing yes";;
646            solaris*)             gl_cv_func_printf_directive_f="guessing no";;
647                                  # Guess no on Android.
648            linux*-android*)      gl_cv_func_printf_directive_f="guessing no";;
649 changequote([,])dnl
650                                  # Guess yes on MSVC, no on mingw.
651            mingw*)               AC_EGREP_CPP([Known], [
652 #ifdef _MSC_VER
653  Known
654 #endif
655                                    ],
656                                    [gl_cv_func_printf_directive_f="guessing yes"],
657                                    [gl_cv_func_printf_directive_f="guessing no"])
658                                  ;;
659                                  # If we don't know, obey --enable-cross-guesses.
660            *)                    gl_cv_func_printf_directive_f="$gl_cross_guess_normal";;
661          esac
662         ])
663     ])
666 dnl Test whether the *printf family of functions supports the %n format
667 dnl directive. (ISO C99, POSIX:2001)
668 dnl Result is gl_cv_func_printf_directive_n.
670 AC_DEFUN([gl_PRINTF_DIRECTIVE_N],
672   AC_REQUIRE([AC_PROG_CC])
673   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
674   AC_CACHE_CHECK([whether printf supports the 'n' directive],
675     [gl_cv_func_printf_directive_n],
676     [
677       AC_RUN_IFELSE(
678         [AC_LANG_SOURCE([[
679 #include <stdio.h>
680 #include <stdlib.h>
681 #include <string.h>
682 #ifdef _MSC_VER
683 #include <inttypes.h>
684 /* See page about "Parameter Validation" on msdn.microsoft.com.
685    <https://docs.microsoft.com/en-us/cpp/c-runtime-library/parameter-validation>
686    <https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/set-invalid-parameter-handler-set-thread-local-invalid-parameter-handler>  */
687 static void cdecl
688 invalid_parameter_handler (const wchar_t *expression,
689                            const wchar_t *function,
690                            const wchar_t *file, unsigned int line,
691                            uintptr_t dummy)
693   exit (1);
695 #endif
696 static char fmtstring[10];
697 static char buf[100];
698 int main ()
700   int count = -1;
701 #ifdef _MSC_VER
702   _set_invalid_parameter_handler (invalid_parameter_handler);
703 #endif
704   /* Copy the format string.  Some systems (glibc with _FORTIFY_SOURCE=2)
705      support %n in format strings in read-only memory but not in writable
706      memory.  */
707   strcpy (fmtstring, "%d %n");
708   if (sprintf (buf, fmtstring, 123, &count, 33, 44, 55) < 0
709       || strcmp (buf, "123 ") != 0
710       || count != 4)
711     return 1;
712   return 0;
713 }]])],
714         [gl_cv_func_printf_directive_n=yes],
715         [gl_cv_func_printf_directive_n=no],
716         [case "$host_os" in
717                             # Guess no on glibc when _FORTIFY_SOURCE >= 2.
718            *-gnu* | gnu*)   AC_COMPILE_IFELSE(
719                               [AC_LANG_SOURCE(
720                                  [[#if _FORTIFY_SOURCE >= 2
721                                     error fail
722                                    #endif
723                                  ]])],
724                               [gl_cv_func_printf_directive_n="guessing yes"],
725                               [gl_cv_func_printf_directive_n="guessing no"])
726                             ;;
727                             # Guess no on Android.
728            linux*-android*) gl_cv_func_printf_directive_n="guessing no";;
729                             # Guess no on native Windows.
730            mingw*)          gl_cv_func_printf_directive_n="guessing no";;
731            *)               gl_cv_func_printf_directive_n="guessing yes";;
732          esac
733         ])
734     ])
737 dnl Test whether the *printf family of functions supports the %ls format
738 dnl directive and in particular, when a precision is specified, whether
739 dnl the functions stop converting the wide string argument when the number
740 dnl of bytes that have been produced by this conversion equals or exceeds
741 dnl the precision.
742 dnl Result is gl_cv_func_printf_directive_ls.
744 AC_DEFUN([gl_PRINTF_DIRECTIVE_LS],
746   AC_REQUIRE([AC_PROG_CC])
747   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
748   AC_CACHE_CHECK([whether printf supports the 'ls' directive],
749     [gl_cv_func_printf_directive_ls],
750     [
751       AC_RUN_IFELSE(
752         [AC_LANG_SOURCE([[
753 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
754    <wchar.h>.
755    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
756    included before <wchar.h>.  */
757 #include <stddef.h>
758 #include <stdio.h>
759 #include <time.h>
760 #include <wchar.h>
761 #include <string.h>
762 int main ()
764   int result = 0;
765   char buf[100];
766   /* Test whether %ls works at all.
767      This test fails on OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku, but not on
768      Cygwin 1.5.  */
769   {
770     static const wchar_t wstring[] = { 'a', 'b', 'c', 0 };
771     buf[0] = '\0';
772     if (sprintf (buf, "%ls", wstring) < 0
773         || strcmp (buf, "abc") != 0)
774       result |= 1;
775   }
776   /* This test fails on IRIX 6.5, Solaris 2.6, Cygwin 1.5, Haiku (with an
777      assertion failure inside libc), but not on OpenBSD 4.0.  */
778   {
779     static const wchar_t wstring[] = { 'a', 0 };
780     buf[0] = '\0';
781     if (sprintf (buf, "%ls", wstring) < 0
782         || strcmp (buf, "a") != 0)
783       result |= 2;
784   }
785   /* Test whether precisions in %ls are supported as specified in ISO C 99
786      section 7.19.6.1:
787        "If a precision is specified, no more than that many bytes are written
788         (including shift sequences, if any), and the array shall contain a
789         null wide character if, to equal the multibyte character sequence
790         length given by the precision, the function would need to access a
791         wide character one past the end of the array."
792      This test fails on Solaris 10.  */
793   {
794     static const wchar_t wstring[] = { 'a', 'b', (wchar_t) 0xfdfdfdfd, 0 };
795     buf[0] = '\0';
796     if (sprintf (buf, "%.2ls", wstring) < 0
797         || strcmp (buf, "ab") != 0)
798       result |= 8;
799   }
800   return result;
801 }]])],
802         [gl_cv_func_printf_directive_ls=yes],
803         [gl_cv_func_printf_directive_ls=no],
804         [
805 changequote(,)dnl
806          case "$host_os" in
807            openbsd*)        gl_cv_func_printf_directive_ls="guessing no";;
808            irix*)           gl_cv_func_printf_directive_ls="guessing no";;
809            solaris*)        gl_cv_func_printf_directive_ls="guessing no";;
810            cygwin*)         gl_cv_func_printf_directive_ls="guessing no";;
811            beos* | haiku*)  gl_cv_func_printf_directive_ls="guessing no";;
812                             # Guess no on Android.
813            linux*-android*) gl_cv_func_printf_directive_ls="guessing no";;
814                             # Guess yes on native Windows.
815            mingw*)          gl_cv_func_printf_directive_ls="guessing yes";;
816            *)               gl_cv_func_printf_directive_ls="guessing yes";;
817          esac
818 changequote([,])dnl
819         ])
820     ])
823 dnl Test whether the *printf family of functions supports POSIX/XSI format
824 dnl strings with positions. (POSIX:2001)
825 dnl Result is gl_cv_func_printf_positions.
827 AC_DEFUN([gl_PRINTF_POSITIONS],
829   AC_REQUIRE([AC_PROG_CC])
830   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
831   AC_CACHE_CHECK([whether printf supports POSIX/XSI format strings with positions],
832     [gl_cv_func_printf_positions],
833     [
834       AC_RUN_IFELSE(
835         [AC_LANG_SOURCE([[
836 #include <stdio.h>
837 #include <string.h>
838 /* The string "%2$d %1$d", with dollar characters protected from the shell's
839    dollar expansion (possibly an autoconf bug).  */
840 static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' };
841 static char buf[100];
842 int main ()
844   sprintf (buf, format, 33, 55);
845   return (strcmp (buf, "55 33") != 0);
846 }]])],
847         [gl_cv_func_printf_positions=yes],
848         [gl_cv_func_printf_positions=no],
849         [
850 changequote(,)dnl
851          case "$host_os" in
852            netbsd[1-3]* | netbsdelf[1-3]* | netbsdaout[1-3]* | netbsdcoff[1-3]*)
853                             gl_cv_func_printf_positions="guessing no";;
854            beos*)           gl_cv_func_printf_positions="guessing no";;
855                             # Guess yes on Android.
856            linux*-android*) gl_cv_func_printf_positions="guessing yes";;
857                             # Guess no on native Windows.
858            mingw* | pw*)    gl_cv_func_printf_positions="guessing no";;
859            *)               gl_cv_func_printf_positions="guessing yes";;
860          esac
861 changequote([,])dnl
862         ])
863     ])
866 dnl Test whether the *printf family of functions supports POSIX/XSI format
867 dnl strings with the ' flag for grouping of decimal digits. (POSIX:2001)
868 dnl Result is gl_cv_func_printf_flag_grouping.
870 AC_DEFUN([gl_PRINTF_FLAG_GROUPING],
872   AC_REQUIRE([AC_PROG_CC])
873   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
874   AC_CACHE_CHECK([whether printf supports the grouping flag],
875     [gl_cv_func_printf_flag_grouping],
876     [
877       AC_RUN_IFELSE(
878         [AC_LANG_SOURCE([[
879 #include <stdio.h>
880 #include <string.h>
881 static char buf[100];
882 int main ()
884   if (sprintf (buf, "%'d %d", 1234567, 99) < 0
885       || buf[strlen (buf) - 1] != '9')
886     return 1;
887   return 0;
888 }]])],
889         [gl_cv_func_printf_flag_grouping=yes],
890         [gl_cv_func_printf_flag_grouping=no],
891         [
892 changequote(,)dnl
893          case "$host_os" in
894            cygwin*)         gl_cv_func_printf_flag_grouping="guessing no";;
895            netbsd*)         gl_cv_func_printf_flag_grouping="guessing no";;
896                             # Guess no on Android.
897            linux*-android*) gl_cv_func_printf_flag_grouping="guessing no";;
898                             # Guess no on native Windows.
899            mingw* | pw*)    gl_cv_func_printf_flag_grouping="guessing no";;
900            *)               gl_cv_func_printf_flag_grouping="guessing yes";;
901          esac
902 changequote([,])dnl
903         ])
904     ])
907 dnl Test whether the *printf family of functions supports the - flag correctly.
908 dnl (ISO C99.) See
909 dnl <https://lists.gnu.org/r/bug-coreutils/2008-02/msg00035.html>
910 dnl Result is gl_cv_func_printf_flag_leftadjust.
912 AC_DEFUN([gl_PRINTF_FLAG_LEFTADJUST],
914   AC_REQUIRE([AC_PROG_CC])
915   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
916   AC_CACHE_CHECK([whether printf supports the left-adjust flag correctly],
917     [gl_cv_func_printf_flag_leftadjust],
918     [
919       AC_RUN_IFELSE(
920         [AC_LANG_SOURCE([[
921 #include <stdio.h>
922 #include <string.h>
923 static char buf[100];
924 int main ()
926   /* Check that a '-' flag is not annihilated by a negative width.  */
927   if (sprintf (buf, "a%-*sc", -3, "b") < 0
928       || strcmp (buf, "ab  c") != 0)
929     return 1;
930   return 0;
931 }]])],
932         [gl_cv_func_printf_flag_leftadjust=yes],
933         [gl_cv_func_printf_flag_leftadjust=no],
934         [
935 changequote(,)dnl
936          case "$host_os" in
937                             # Guess yes on HP-UX 11.
938            hpux11*)         gl_cv_func_printf_flag_leftadjust="guessing yes";;
939                             # Guess no on HP-UX 10 and older.
940            hpux*)           gl_cv_func_printf_flag_leftadjust="guessing no";;
941                             # Guess yes on Android.
942            linux*-android*) gl_cv_func_printf_flag_leftadjust="guessing yes";;
943                             # Guess yes on native Windows.
944            mingw*)          gl_cv_func_printf_flag_leftadjust="guessing yes";;
945                             # Guess yes otherwise.
946            *)               gl_cv_func_printf_flag_leftadjust="guessing yes";;
947          esac
948 changequote([,])dnl
949         ])
950     ])
953 dnl Test whether the *printf family of functions supports padding of non-finite
954 dnl values with the 0 flag correctly. (ISO C99 + TC1 + TC2.) See
955 dnl <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html>
956 dnl Result is gl_cv_func_printf_flag_zero.
958 AC_DEFUN([gl_PRINTF_FLAG_ZERO],
960   AC_REQUIRE([AC_PROG_CC])
961   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
962   AC_CACHE_CHECK([whether printf supports the zero flag correctly],
963     [gl_cv_func_printf_flag_zero],
964     [
965       AC_RUN_IFELSE(
966         [AC_LANG_SOURCE([[
967 #include <stdio.h>
968 #include <string.h>
969 static char buf[100];
970 static double zero = 0.0;
971 int main ()
973   if (sprintf (buf, "%010f", 1.0 / zero, 33, 44, 55) < 0
974       || (strcmp (buf, "       inf") != 0
975           && strcmp (buf, "  infinity") != 0))
976     return 1;
977   return 0;
978 }]])],
979         [gl_cv_func_printf_flag_zero=yes],
980         [gl_cv_func_printf_flag_zero=no],
981         [
982 changequote(,)dnl
983          case "$host_os" in
984                             # Guess yes on glibc systems.
985            *-gnu* | gnu*)   gl_cv_func_printf_flag_zero="guessing yes";;
986                             # Guess yes on musl systems.
987            *-musl*)         gl_cv_func_printf_flag_zero="guessing yes";;
988                             # Guess yes on BeOS.
989            beos*)           gl_cv_func_printf_flag_zero="guessing yes";;
990                             # Guess no on Android.
991            linux*-android*) gl_cv_func_printf_flag_zero="guessing no";;
992                             # Guess no on native Windows.
993            mingw*)          gl_cv_func_printf_flag_zero="guessing no";;
994                             # If we don't know, obey --enable-cross-guesses.
995            *)               gl_cv_func_printf_flag_zero="$gl_cross_guess_normal";;
996          esac
997 changequote([,])dnl
998         ])
999     ])
1002 dnl Test whether the *printf family of functions supports large precisions.
1003 dnl On mingw, precisions larger than 512 are treated like 512, in integer,
1004 dnl floating-point or pointer output. On Solaris 10/x86, precisions larger
1005 dnl than 510 in floating-point output crash the program. On Solaris 10/SPARC,
1006 dnl precisions larger than 510 in floating-point output yield wrong results.
1007 dnl On AIX 7.1, precisions larger than 998 in floating-point output yield
1008 dnl wrong results. On BeOS, precisions larger than 1044 crash the program.
1009 dnl Result is gl_cv_func_printf_precision.
1011 AC_DEFUN([gl_PRINTF_PRECISION],
1013   AC_REQUIRE([AC_PROG_CC])
1014   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1015   AC_CACHE_CHECK([whether printf supports large precisions],
1016     [gl_cv_func_printf_precision],
1017     [
1018       AC_RUN_IFELSE(
1019         [AC_LANG_SOURCE([[
1020 #include <stdio.h>
1021 #include <string.h>
1022 static char buf[5000];
1023 int main ()
1025   int result = 0;
1026 #ifdef __BEOS__
1027   /* On BeOS, this would crash and show a dialog box.  Avoid the crash.  */
1028   return 1;
1029 #endif
1030   if (sprintf (buf, "%.4000d %d", 1, 33, 44) < 4000 + 3)
1031     result |= 1;
1032   if (sprintf (buf, "%.4000f %d", 1.0, 33, 44) < 4000 + 5)
1033     result |= 2;
1034   if (sprintf (buf, "%.511f %d", 1.0, 33, 44) < 511 + 5
1035       || buf[0] != '1')
1036     result |= 4;
1037   if (sprintf (buf, "%.999f %d", 1.0, 33, 44) < 999 + 5
1038       || buf[0] != '1')
1039     result |= 4;
1040   return result;
1041 }]])],
1042         [gl_cv_func_printf_precision=yes],
1043         [gl_cv_func_printf_precision=no],
1044         [
1045 changequote(,)dnl
1046          case "$host_os" in
1047            # Guess no only on Solaris, native Windows, and BeOS systems.
1048            solaris*)        gl_cv_func_printf_precision="guessing no" ;;
1049            mingw* | pw*)    gl_cv_func_printf_precision="guessing no" ;;
1050            beos*)           gl_cv_func_printf_precision="guessing no" ;;
1051                             # Guess yes on Android.
1052            linux*-android*) gl_cv_func_printf_precision="guessing yes" ;;
1053            *)               gl_cv_func_printf_precision="guessing yes" ;;
1054          esac
1055 changequote([,])dnl
1056         ])
1057     ])
1060 dnl Test whether the *printf family of functions recovers gracefully in case
1061 dnl of an out-of-memory condition, or whether it crashes the entire program.
1062 dnl Result is gl_cv_func_printf_enomem.
1064 AC_DEFUN([gl_PRINTF_ENOMEM],
1066   AC_REQUIRE([AC_PROG_CC])
1067   AC_REQUIRE([gl_MULTIARCH])
1068   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1069   AC_CACHE_CHECK([whether printf survives out-of-memory conditions],
1070     [gl_cv_func_printf_enomem],
1071     [
1072       gl_cv_func_printf_enomem="guessing no"
1073       if test "$cross_compiling" = no; then
1074         if test $APPLE_UNIVERSAL_BUILD = 0; then
1075           AC_LANG_CONFTEST([AC_LANG_SOURCE([[
1076 ]GL_NOCRASH[
1077 #include <stdio.h>
1078 #include <sys/types.h>
1079 #include <sys/time.h>
1080 #include <sys/resource.h>
1081 #include <errno.h>
1082 int main()
1084   struct rlimit limit;
1085   int ret;
1086   nocrash_init ();
1087   /* Some printf implementations allocate temporary space with malloc.  */
1088   /* On BSD systems, malloc() is limited by RLIMIT_DATA.  */
1089 #ifdef RLIMIT_DATA
1090   if (getrlimit (RLIMIT_DATA, &limit) < 0)
1091     return 77;
1092   if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
1093     limit.rlim_max = 5000000;
1094   limit.rlim_cur = limit.rlim_max;
1095   if (setrlimit (RLIMIT_DATA, &limit) < 0)
1096     return 77;
1097 #endif
1098   /* On Linux systems, malloc() is limited by RLIMIT_AS.  */
1099 #ifdef RLIMIT_AS
1100   if (getrlimit (RLIMIT_AS, &limit) < 0)
1101     return 77;
1102   if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
1103     limit.rlim_max = 5000000;
1104   limit.rlim_cur = limit.rlim_max;
1105   if (setrlimit (RLIMIT_AS, &limit) < 0)
1106     return 77;
1107 #endif
1108   /* Some printf implementations allocate temporary space on the stack.  */
1109 #ifdef RLIMIT_STACK
1110   if (getrlimit (RLIMIT_STACK, &limit) < 0)
1111     return 77;
1112   if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
1113     limit.rlim_max = 5000000;
1114   limit.rlim_cur = limit.rlim_max;
1115   if (setrlimit (RLIMIT_STACK, &limit) < 0)
1116     return 77;
1117 #endif
1118   ret = printf ("%.5000000f", 1.0);
1119   return !(ret == 5000002 || (ret < 0 && errno == ENOMEM));
1121           ]])])
1122           if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
1123             (./conftest 2>&AS_MESSAGE_LOG_FD
1124              result=$?
1125              _AS_ECHO_LOG([\$? = $result])
1126              if test $result != 0 && test $result != 77; then result=1; fi
1127              exit $result
1128             ) >/dev/null 2>/dev/null
1129             case $? in
1130               0) gl_cv_func_printf_enomem="yes" ;;
1131               77) gl_cv_func_printf_enomem="guessing no" ;;
1132               *) gl_cv_func_printf_enomem="no" ;;
1133             esac
1134           else
1135             gl_cv_func_printf_enomem="guessing no"
1136           fi
1137           rm -fr conftest*
1138         else
1139           dnl A universal build on Apple Mac OS X platforms.
1140           dnl The result would be 'no' in 32-bit mode and 'yes' in 64-bit mode.
1141           dnl But we need a configuration result that is valid in both modes.
1142           gl_cv_func_printf_enomem="guessing no"
1143         fi
1144       fi
1145       if test "$gl_cv_func_printf_enomem" = "guessing no"; then
1146 changequote(,)dnl
1147         case "$host_os" in
1148                            # Guess yes on glibc systems.
1149           *-gnu* | gnu*)   gl_cv_func_printf_enomem="guessing yes";;
1150                            # Guess yes on Solaris.
1151           solaris*)        gl_cv_func_printf_enomem="guessing yes";;
1152                            # Guess yes on AIX.
1153           aix*)            gl_cv_func_printf_enomem="guessing yes";;
1154                            # Guess yes on HP-UX/hppa.
1155           hpux*)           case "$host_cpu" in
1156                              hppa*) gl_cv_func_printf_enomem="guessing yes";;
1157                              *)     gl_cv_func_printf_enomem="guessing no";;
1158                            esac
1159                            ;;
1160                            # Guess yes on IRIX.
1161           irix*)           gl_cv_func_printf_enomem="guessing yes";;
1162                            # Guess yes on OSF/1.
1163           osf*)            gl_cv_func_printf_enomem="guessing yes";;
1164                            # Guess yes on BeOS.
1165           beos*)           gl_cv_func_printf_enomem="guessing yes";;
1166                            # Guess yes on Haiku.
1167           haiku*)          gl_cv_func_printf_enomem="guessing yes";;
1168                            # Guess no on Android.
1169           linux*-android*) gl_cv_func_printf_enomem="guessing no";;
1170                            # If we don't know, obey --enable-cross-guesses.
1171           *)               gl_cv_func_printf_enomem="$gl_cross_guess_normal";;
1172         esac
1173 changequote([,])dnl
1174       fi
1175     ])
1178 dnl Test whether the snprintf function exists. (ISO C99, POSIX:2001)
1179 dnl Result is ac_cv_func_snprintf.
1181 AC_DEFUN([gl_SNPRINTF_PRESENCE],
1183   AC_CHECK_FUNCS_ONCE([snprintf])
1186 dnl Test whether the string produced by the snprintf function is always NUL
1187 dnl terminated. (ISO C99, POSIX:2001)
1188 dnl Result is gl_cv_func_snprintf_truncation_c99.
1190 AC_DEFUN([gl_SNPRINTF_TRUNCATION_C99],
1192   AC_REQUIRE([AC_PROG_CC])
1193   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1194   AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1195   AC_CACHE_CHECK([whether snprintf truncates the result as in C99],
1196     [gl_cv_func_snprintf_truncation_c99],
1197     [
1198       AC_RUN_IFELSE(
1199         [AC_LANG_SOURCE([[
1200 #include <stdio.h>
1201 #include <string.h>
1202 #if HAVE_SNPRINTF
1203 # define my_snprintf snprintf
1204 #else
1205 # include <stdarg.h>
1206 static int my_snprintf (char *buf, int size, const char *format, ...)
1208   va_list args;
1209   int ret;
1210   va_start (args, format);
1211   ret = vsnprintf (buf, size, format, args);
1212   va_end (args);
1213   return ret;
1215 #endif
1216 static char buf[100];
1217 int main ()
1219   strcpy (buf, "ABCDEF");
1220   my_snprintf (buf, 3, "%d %d", 4567, 89);
1221   if (memcmp (buf, "45\0DEF", 6) != 0)
1222     return 1;
1223   return 0;
1224 }]])],
1225         [gl_cv_func_snprintf_truncation_c99=yes],
1226         [gl_cv_func_snprintf_truncation_c99=no],
1227         [
1228 changequote(,)dnl
1229          case "$host_os" in
1230                                  # Guess yes on glibc systems.
1231            *-gnu* | gnu*)        gl_cv_func_snprintf_truncation_c99="guessing yes";;
1232                                  # Guess yes on musl systems.
1233            *-musl*)              gl_cv_func_snprintf_truncation_c99="guessing yes";;
1234                                  # Guess yes on FreeBSD >= 5.
1235            freebsd[1-4].*)       gl_cv_func_snprintf_truncation_c99="guessing no";;
1236            freebsd* | kfreebsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1237                                  # Guess yes on Mac OS X >= 10.3.
1238            darwin[1-6].*)        gl_cv_func_snprintf_truncation_c99="guessing no";;
1239            darwin*)              gl_cv_func_snprintf_truncation_c99="guessing yes";;
1240                                  # Guess yes on OpenBSD >= 3.9.
1241            openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
1242                                  gl_cv_func_snprintf_truncation_c99="guessing no";;
1243            openbsd*)             gl_cv_func_snprintf_truncation_c99="guessing yes";;
1244                                  # Guess yes on Solaris >= 2.6.
1245            solaris2.[0-5] | solaris2.[0-5].*)
1246                                  gl_cv_func_snprintf_truncation_c99="guessing no";;
1247            solaris*)             gl_cv_func_snprintf_truncation_c99="guessing yes";;
1248                                  # Guess yes on AIX >= 4.
1249            aix[1-3]*)            gl_cv_func_snprintf_truncation_c99="guessing no";;
1250            aix*)                 gl_cv_func_snprintf_truncation_c99="guessing yes";;
1251                                  # Guess yes on HP-UX >= 11.
1252            hpux[7-9]* | hpux10*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1253            hpux*)                gl_cv_func_snprintf_truncation_c99="guessing yes";;
1254                                  # Guess yes on IRIX >= 6.5.
1255            irix6.5)              gl_cv_func_snprintf_truncation_c99="guessing yes";;
1256                                  # Guess yes on OSF/1 >= 5.
1257            osf[3-4]*)            gl_cv_func_snprintf_truncation_c99="guessing no";;
1258            osf*)                 gl_cv_func_snprintf_truncation_c99="guessing yes";;
1259                                  # Guess yes on NetBSD >= 3.
1260            netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1261                                  gl_cv_func_snprintf_truncation_c99="guessing no";;
1262            netbsd*)              gl_cv_func_snprintf_truncation_c99="guessing yes";;
1263                                  # Guess yes on BeOS.
1264            beos*)                gl_cv_func_snprintf_truncation_c99="guessing yes";;
1265                                  # Guess yes on Android.
1266            linux*-android*)      gl_cv_func_snprintf_truncation_c99="guessing yes";;
1267                                  # Guess no on native Windows.
1268            mingw*)               gl_cv_func_snprintf_truncation_c99="guessing no";;
1269                                  # If we don't know, obey --enable-cross-guesses.
1270            *)                    gl_cv_func_snprintf_truncation_c99="$gl_cross_guess_normal";;
1271          esac
1272 changequote([,])dnl
1273         ])
1274     ])
1277 dnl Test whether the return value of the snprintf function is the number
1278 dnl of bytes (excluding the terminating NUL) that would have been produced
1279 dnl if the buffer had been large enough. (ISO C99, POSIX:2001)
1280 dnl For example, this test program fails on IRIX 6.5:
1281 dnl     ---------------------------------------------------------------------
1282 dnl     #include <stdio.h>
1283 dnl     int main()
1284 dnl     {
1285 dnl       static char buf[8];
1286 dnl       int retval = snprintf (buf, 3, "%d", 12345);
1287 dnl       return retval >= 0 && retval < 3;
1288 dnl     }
1289 dnl     ---------------------------------------------------------------------
1290 dnl Result is gl_cv_func_snprintf_retval_c99.
1292 AC_DEFUN_ONCE([gl_SNPRINTF_RETVAL_C99],
1294   AC_REQUIRE([AC_PROG_CC])
1295   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1296   AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1297   AC_CACHE_CHECK([whether snprintf returns a byte count as in C99],
1298     [gl_cv_func_snprintf_retval_c99],
1299     [
1300       AC_RUN_IFELSE(
1301         [AC_LANG_SOURCE([[
1302 #include <stdio.h>
1303 #include <string.h>
1304 #if HAVE_SNPRINTF
1305 # define my_snprintf snprintf
1306 #else
1307 # include <stdarg.h>
1308 static int my_snprintf (char *buf, int size, const char *format, ...)
1310   va_list args;
1311   int ret;
1312   va_start (args, format);
1313   ret = vsnprintf (buf, size, format, args);
1314   va_end (args);
1315   return ret;
1317 #endif
1318 static char buf[100];
1319 int main ()
1321   strcpy (buf, "ABCDEF");
1322   if (my_snprintf (buf, 3, "%d %d", 4567, 89) != 7)
1323     return 1;
1324   if (my_snprintf (buf, 0, "%d %d", 4567, 89) != 7)
1325     return 2;
1326   if (my_snprintf (NULL, 0, "%d %d", 4567, 89) != 7)
1327     return 3;
1328   return 0;
1329 }]])],
1330         [gl_cv_func_snprintf_retval_c99=yes],
1331         [gl_cv_func_snprintf_retval_c99=no],
1332         [case "$host_os" in
1333 changequote(,)dnl
1334                                  # Guess yes on glibc systems.
1335            *-gnu* | gnu*)        gl_cv_func_snprintf_retval_c99="guessing yes";;
1336                                  # Guess yes on musl systems.
1337            *-musl*)              gl_cv_func_snprintf_retval_c99="guessing yes";;
1338                                  # Guess yes on FreeBSD >= 5.
1339            freebsd[1-4].*)       gl_cv_func_snprintf_retval_c99="guessing no";;
1340            freebsd* | kfreebsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1341                                  # Guess yes on Mac OS X >= 10.3.
1342            darwin[1-6].*)        gl_cv_func_snprintf_retval_c99="guessing no";;
1343            darwin*)              gl_cv_func_snprintf_retval_c99="guessing yes";;
1344                                  # Guess yes on OpenBSD >= 3.9.
1345            openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
1346                                  gl_cv_func_snprintf_retval_c99="guessing no";;
1347            openbsd*)             gl_cv_func_snprintf_retval_c99="guessing yes";;
1348                                  # Guess yes on Solaris >= 2.10.
1349            solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";;
1350            solaris*)             gl_cv_func_printf_sizes_c99="guessing no";;
1351                                  # Guess yes on AIX >= 4.
1352            aix[1-3]*)            gl_cv_func_snprintf_retval_c99="guessing no";;
1353            aix*)                 gl_cv_func_snprintf_retval_c99="guessing yes";;
1354                                  # Guess yes on NetBSD >= 3.
1355            netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1356                                  gl_cv_func_snprintf_retval_c99="guessing no";;
1357            netbsd*)              gl_cv_func_snprintf_retval_c99="guessing yes";;
1358                                  # Guess yes on BeOS.
1359            beos*)                gl_cv_func_snprintf_retval_c99="guessing yes";;
1360                                  # Guess yes on Android.
1361            linux*-android*)      gl_cv_func_snprintf_retval_c99="guessing yes";;
1362 changequote([,])dnl
1363                                  # Guess yes on MSVC, no on mingw.
1364            mingw*)               AC_EGREP_CPP([Known], [
1365 #ifdef _MSC_VER
1366  Known
1367 #endif
1368                                    ],
1369                                    [gl_cv_func_snprintf_retval_c99="guessing yes"],
1370                                    [gl_cv_func_snprintf_retval_c99="guessing no"])
1371                                  ;;
1372                                  # If we don't know, obey --enable-cross-guesses.
1373            *)                    gl_cv_func_snprintf_retval_c99="$gl_cross_guess_normal";;
1374          esac
1375         ])
1376     ])
1379 dnl Test whether the snprintf function supports the %n format directive
1380 dnl also in truncated portions of the format string. (ISO C99, POSIX:2001)
1381 dnl Result is gl_cv_func_snprintf_directive_n.
1383 AC_DEFUN([gl_SNPRINTF_DIRECTIVE_N],
1385   AC_REQUIRE([AC_PROG_CC])
1386   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1387   AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1388   AC_CACHE_CHECK([whether snprintf fully supports the 'n' directive],
1389     [gl_cv_func_snprintf_directive_n],
1390     [
1391       AC_RUN_IFELSE(
1392         [AC_LANG_SOURCE([[
1393 #include <stdio.h>
1394 #include <string.h>
1395 #if HAVE_SNPRINTF
1396 # define my_snprintf snprintf
1397 #else
1398 # include <stdarg.h>
1399 static int my_snprintf (char *buf, int size, const char *format, ...)
1401   va_list args;
1402   int ret;
1403   va_start (args, format);
1404   ret = vsnprintf (buf, size, format, args);
1405   va_end (args);
1406   return ret;
1408 #endif
1409 static char fmtstring[10];
1410 static char buf[100];
1411 int main ()
1413   int count = -1;
1414   /* Copy the format string.  Some systems (glibc with _FORTIFY_SOURCE=2)
1415      support %n in format strings in read-only memory but not in writable
1416      memory.  */
1417   strcpy (fmtstring, "%d %n");
1418   my_snprintf (buf, 4, fmtstring, 12345, &count, 33, 44, 55);
1419   if (count != 6)
1420     return 1;
1421   return 0;
1422 }]])],
1423         [gl_cv_func_snprintf_directive_n=yes],
1424         [gl_cv_func_snprintf_directive_n=no],
1425         [
1426          case "$host_os" in
1427                                  # Guess no on glibc when _FORTIFY_SOURCE >= 2.
1428            *-gnu* | gnu*)        AC_COMPILE_IFELSE(
1429                                    [AC_LANG_SOURCE(
1430                                       [[#if _FORTIFY_SOURCE >= 2
1431                                          error fail
1432                                         #endif
1433                                       ]])],
1434                                    [gl_cv_func_snprintf_directive_n="guessing yes"],
1435                                    [gl_cv_func_snprintf_directive_n="guessing no"])
1436                                  ;;
1437 changequote(,)dnl
1438                                  # Guess yes on musl systems.
1439            *-musl*)              gl_cv_func_snprintf_directive_n="guessing yes";;
1440                                  # Guess yes on FreeBSD >= 5.
1441            freebsd[1-4].*)       gl_cv_func_snprintf_directive_n="guessing no";;
1442            freebsd* | kfreebsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
1443                                  # Guess yes on Mac OS X >= 10.3.
1444            darwin[1-6].*)        gl_cv_func_snprintf_directive_n="guessing no";;
1445            darwin*)              gl_cv_func_snprintf_directive_n="guessing yes";;
1446                                  # Guess yes on Solaris >= 2.6.
1447            solaris2.[0-5] | solaris2.[0-5].*)
1448                                  gl_cv_func_snprintf_directive_n="guessing no";;
1449            solaris*)             gl_cv_func_snprintf_directive_n="guessing yes";;
1450                                  # Guess yes on AIX >= 4.
1451            aix[1-3]*)            gl_cv_func_snprintf_directive_n="guessing no";;
1452            aix*)                 gl_cv_func_snprintf_directive_n="guessing yes";;
1453                                  # Guess yes on IRIX >= 6.5.
1454            irix6.5)              gl_cv_func_snprintf_directive_n="guessing yes";;
1455                                  # Guess yes on OSF/1 >= 5.
1456            osf[3-4]*)            gl_cv_func_snprintf_directive_n="guessing no";;
1457            osf*)                 gl_cv_func_snprintf_directive_n="guessing yes";;
1458                                  # Guess yes on NetBSD >= 3.
1459            netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1460                                  gl_cv_func_snprintf_directive_n="guessing no";;
1461            netbsd*)              gl_cv_func_snprintf_directive_n="guessing yes";;
1462                                  # Guess yes on BeOS.
1463            beos*)                gl_cv_func_snprintf_directive_n="guessing yes";;
1464                                  # Guess no on Android.
1465            linux*-android*)      gl_cv_func_snprintf_directive_n="guessing no";;
1466                                  # Guess no on native Windows.
1467            mingw*)               gl_cv_func_snprintf_directive_n="guessing no";;
1468                                  # If we don't know, obey --enable-cross-guesses.
1469            *)                    gl_cv_func_snprintf_directive_n="$gl_cross_guess_normal";;
1470 changequote([,])dnl
1471          esac
1472         ])
1473     ])
1476 dnl Test whether the snprintf function, when passed a size = 1, writes any
1477 dnl output without bounds in this case, behaving like sprintf. This is the
1478 dnl case on Linux libc5.
1479 dnl Result is gl_cv_func_snprintf_size1.
1481 AC_DEFUN([gl_SNPRINTF_SIZE1],
1483   AC_REQUIRE([AC_PROG_CC])
1484   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1485   AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1486   AC_CACHE_CHECK([whether snprintf respects a size of 1],
1487     [gl_cv_func_snprintf_size1],
1488     [
1489       AC_RUN_IFELSE(
1490         [AC_LANG_SOURCE([[
1491 #include <stdio.h>
1492 #if HAVE_SNPRINTF
1493 # define my_snprintf snprintf
1494 #else
1495 # include <stdarg.h>
1496 static int my_snprintf (char *buf, int size, const char *format, ...)
1498   va_list args;
1499   int ret;
1500   va_start (args, format);
1501   ret = vsnprintf (buf, size, format, args);
1502   va_end (args);
1503   return ret;
1505 #endif
1506 int main()
1508   static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1509   my_snprintf (buf, 1, "%d", 12345);
1510   return buf[1] != 'E';
1511 }]])],
1512         [gl_cv_func_snprintf_size1=yes],
1513         [gl_cv_func_snprintf_size1=no],
1514         [case "$host_os" in
1515                             # Guess yes on Android.
1516            linux*-android*) gl_cv_func_snprintf_size1="guessing yes" ;;
1517                             # Guess yes on native Windows.
1518            mingw*)          gl_cv_func_snprintf_size1="guessing yes" ;;
1519            *)               gl_cv_func_snprintf_size1="guessing yes" ;;
1520          esac
1521         ])
1522     ])
1525 dnl Test whether the vsnprintf function, when passed a zero size, produces no
1526 dnl output. (ISO C99, POSIX:2001)
1527 dnl For example, snprintf nevertheless writes a NUL byte in this case
1528 dnl on OSF/1 5.1:
1529 dnl     ---------------------------------------------------------------------
1530 dnl     #include <stdio.h>
1531 dnl     int main()
1532 dnl     {
1533 dnl       static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1534 dnl       snprintf (buf, 0, "%d", 12345);
1535 dnl       return buf[0] != 'D';
1536 dnl     }
1537 dnl     ---------------------------------------------------------------------
1538 dnl And vsnprintf writes any output without bounds in this case, behaving like
1539 dnl vsprintf, on HP-UX 11 and OSF/1 5.1:
1540 dnl     ---------------------------------------------------------------------
1541 dnl     #include <stdarg.h>
1542 dnl     #include <stdio.h>
1543 dnl     static int my_snprintf (char *buf, int size, const char *format, ...)
1544 dnl     {
1545 dnl       va_list args;
1546 dnl       int ret;
1547 dnl       va_start (args, format);
1548 dnl       ret = vsnprintf (buf, size, format, args);
1549 dnl       va_end (args);
1550 dnl       return ret;
1551 dnl     }
1552 dnl     int main()
1553 dnl     {
1554 dnl       static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1555 dnl       my_snprintf (buf, 0, "%d", 12345);
1556 dnl       return buf[0] != 'D';
1557 dnl     }
1558 dnl     ---------------------------------------------------------------------
1559 dnl Result is gl_cv_func_vsnprintf_zerosize_c99.
1561 AC_DEFUN([gl_VSNPRINTF_ZEROSIZE_C99],
1563   AC_REQUIRE([AC_PROG_CC])
1564   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1565   AC_CACHE_CHECK([whether vsnprintf respects a zero size as in C99],
1566     [gl_cv_func_vsnprintf_zerosize_c99],
1567     [
1568       AC_RUN_IFELSE(
1569         [AC_LANG_SOURCE([[
1570 #include <stdarg.h>
1571 #include <stdio.h>
1572 static int my_snprintf (char *buf, int size, const char *format, ...)
1574   va_list args;
1575   int ret;
1576   va_start (args, format);
1577   ret = vsnprintf (buf, size, format, args);
1578   va_end (args);
1579   return ret;
1581 int main()
1583   static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1584   my_snprintf (buf, 0, "%d", 12345);
1585   return buf[0] != 'D';
1586 }]])],
1587         [gl_cv_func_vsnprintf_zerosize_c99=yes],
1588         [gl_cv_func_vsnprintf_zerosize_c99=no],
1589         [
1590 changequote(,)dnl
1591          case "$host_os" in
1592                                  # Guess yes on glibc systems.
1593            *-gnu* | gnu*)        gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1594                                  # Guess yes on musl systems.
1595            *-musl*)              gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1596                                  # Guess yes on FreeBSD >= 5.
1597            freebsd[1-4].*)       gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1598            freebsd* | kfreebsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1599                                  # Guess yes on Mac OS X >= 10.3.
1600            darwin[1-6].*)        gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1601            darwin*)              gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1602                                  # Guess yes on Cygwin.
1603            cygwin*)              gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1604                                  # Guess yes on Solaris >= 2.6.
1605            solaris2.[0-5] | solaris2.[0-5].*)
1606                                  gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1607            solaris*)             gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1608                                  # Guess yes on AIX >= 4.
1609            aix[1-3]*)            gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1610            aix*)                 gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1611                                  # Guess yes on IRIX >= 6.5.
1612            irix6.5)              gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1613                                  # Guess yes on NetBSD >= 3.
1614            netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1615                                  gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1616            netbsd*)              gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1617                                  # Guess yes on BeOS.
1618            beos*)                gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1619                                  # Guess yes on Android.
1620            linux*-android*)      gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1621                                  # Guess yes on native Windows.
1622            mingw* | pw*)         gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1623                                  # If we don't know, obey --enable-cross-guesses.
1624            *)                    gl_cv_func_vsnprintf_zerosize_c99="$gl_cross_guess_normal";;
1625          esac
1626 changequote([,])dnl
1627         ])
1628     ])
1631 dnl The results of these tests on various platforms are:
1633 dnl 1 = gl_PRINTF_SIZES_C99
1634 dnl 2 = gl_PRINTF_LONG_DOUBLE
1635 dnl 3 = gl_PRINTF_INFINITE
1636 dnl 4 = gl_PRINTF_INFINITE_LONG_DOUBLE
1637 dnl 5 = gl_PRINTF_DIRECTIVE_A
1638 dnl 6 = gl_PRINTF_DIRECTIVE_F
1639 dnl 7 = gl_PRINTF_DIRECTIVE_N
1640 dnl 8 = gl_PRINTF_DIRECTIVE_LS
1641 dnl 9 = gl_PRINTF_POSITIONS
1642 dnl 10 = gl_PRINTF_FLAG_GROUPING
1643 dnl 11 = gl_PRINTF_FLAG_LEFTADJUST
1644 dnl 12 = gl_PRINTF_FLAG_ZERO
1645 dnl 13 = gl_PRINTF_PRECISION
1646 dnl 14 = gl_PRINTF_ENOMEM
1647 dnl 15 = gl_SNPRINTF_PRESENCE
1648 dnl 16 = gl_SNPRINTF_TRUNCATION_C99
1649 dnl 17 = gl_SNPRINTF_RETVAL_C99
1650 dnl 18 = gl_SNPRINTF_DIRECTIVE_N
1651 dnl 19 = gl_SNPRINTF_SIZE1
1652 dnl 20 = gl_VSNPRINTF_ZEROSIZE_C99
1654 dnl 1 = checking whether printf supports size specifiers as in C99...
1655 dnl 2 = checking whether printf supports 'long double' arguments...
1656 dnl 3 = checking whether printf supports infinite 'double' arguments...
1657 dnl 4 = checking whether printf supports infinite 'long double' arguments...
1658 dnl 5 = checking whether printf supports the 'a' and 'A' directives...
1659 dnl 6 = checking whether printf supports the 'F' directive...
1660 dnl 7 = checking whether printf supports the 'n' directive...
1661 dnl 8 = checking whether printf supports the 'ls' directive...
1662 dnl 9 = checking whether printf supports POSIX/XSI format strings with positions...
1663 dnl 10 = checking whether printf supports the grouping flag...
1664 dnl 11 = checking whether printf supports the left-adjust flag correctly...
1665 dnl 12 = checking whether printf supports the zero flag correctly...
1666 dnl 13 = checking whether printf supports large precisions...
1667 dnl 14 = checking whether printf survives out-of-memory conditions...
1668 dnl 15 = checking for snprintf...
1669 dnl 16 = checking whether snprintf truncates the result as in C99...
1670 dnl 17 = checking whether snprintf returns a byte count as in C99...
1671 dnl 18 = checking whether snprintf fully supports the 'n' directive...
1672 dnl 19 = checking whether snprintf respects a size of 1...
1673 dnl 20 = checking whether vsnprintf respects a zero size as in C99...
1675 dnl . = yes, # = no.
1677 dnl                                  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
1678 dnl   glibc 2.5                      .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
1679 dnl   glibc 2.3.6                    .  .  .  .  #  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
1680 dnl   FreeBSD 5.4, 6.1               .  .  .  .  #  .  .  .  .  .  .  #  .  #  .  .  .  .  .  .
1681 dnl   Mac OS X 10.13.5               .  .  .  #  #  .  #  .  .  .  .  .  .  .  .  .  .  #  .  .
1682 dnl   Mac OS X 10.5.8                .  .  .  #  #  .  .  .  .  .  .  #  .  .  .  .  .  .  .  .
1683 dnl   Mac OS X 10.3.9                .  .  .  .  #  .  .  .  .  .  .  #  .  #  .  .  .  .  .  .
1684 dnl   OpenBSD 3.9, 4.0               .  .  #  #  #  #  .  #  .  #  .  #  .  #  .  .  .  .  .  .
1685 dnl   Cygwin 1.7.0 (2009)            .  .  .  #  .  .  .  ?  .  .  .  .  .  ?  .  .  .  .  .  .
1686 dnl   Cygwin 1.5.25 (2008)           .  .  .  #  #  .  .  #  .  .  .  .  .  #  .  .  .  .  .  .
1687 dnl   Cygwin 1.5.19 (2006)           #  .  .  #  #  #  .  #  .  #  .  #  #  #  .  .  .  .  .  .
1688 dnl   Solaris 11.4                   .  .  #  #  #  .  .  #  .  .  .  #  .  .  .  .  .  .  .  .
1689 dnl   Solaris 11.3                   .  .  .  .  #  .  .  #  .  .  .  .  .  .  .  .  .  .  .  .
1690 dnl   Solaris 11.0                   .  .  #  #  #  .  .  #  .  .  .  #  .  .  .  .  .  .  .  .
1691 dnl   Solaris 10                     .  .  #  #  #  .  .  #  .  .  .  #  #  .  .  .  .  .  .  .
1692 dnl   Solaris 2.6 ... 9              #  .  #  #  #  #  .  #  .  .  .  #  #  .  .  .  #  .  .  .
1693 dnl   Solaris 2.5.1                  #  .  #  #  #  #  .  #  .  .  .  #  .  .  #  #  #  #  #  #
1694 dnl   AIX 7.1                        .  .  #  #  #  .  .  .  .  .  .  #  #  .  .  .  .  .  .  .
1695 dnl   AIX 5.2                        .  .  #  #  #  .  .  .  .  .  .  #  .  .  .  .  .  .  .  .
1696 dnl   AIX 4.3.2, 5.1                 #  .  #  #  #  #  .  .  .  .  .  #  .  .  .  .  #  .  .  .
1697 dnl   HP-UX 11.31                    .  .  .  .  #  .  .  .  .  .  .  #  .  .  .  .  #  #  .  .
1698 dnl   HP-UX 11.{00,11,23}            #  .  .  .  #  #  .  .  .  .  .  #  .  .  .  .  #  #  .  #
1699 dnl   HP-UX 10.20                    #  .  #  .  #  #  .  ?  .  .  #  #  .  .  .  .  #  #  ?  #
1700 dnl   IRIX 6.5                       #  .  #  #  #  #  .  #  .  .  .  #  .  .  .  .  #  .  .  .
1701 dnl   OSF/1 5.1                      #  .  #  #  #  #  .  .  .  .  .  #  .  .  .  .  #  .  .  #
1702 dnl   OSF/1 4.0d                     #  .  #  #  #  #  .  .  .  .  .  #  .  .  #  #  #  #  #  #
1703 dnl   NetBSD 9.0                     .  .  .  .  #  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
1704 dnl   NetBSD 5.0                     .  .  .  #  #  .  .  .  .  .  .  #  .  #  .  .  .  .  .  .
1705 dnl   NetBSD 4.0                     .  ?  ?  ?  ?  ?  .  ?  .  ?  ?  ?  ?  ?  .  .  .  ?  ?  ?
1706 dnl   NetBSD 3.0                     .  .  .  .  #  #  .  ?  #  #  ?  #  .  #  .  .  .  .  .  .
1707 dnl   Haiku                          .  .  .  #  #  #  .  #  .  .  .  .  .  ?  .  .  ?  .  .  .
1708 dnl   BeOS                           #  #  .  #  #  #  .  ?  #  .  ?  .  #  ?  .  .  ?  .  .  .
1709 dnl   Android 4.3                    .  .  #  #  #  #  #  #  .  #  .  #  .  #  .  .  .  #  .  .
1710 dnl   old mingw / msvcrt             #  #  #  #  #  #  .  .  #  #  .  #  #  ?  .  #  #  #  .  .
1711 dnl   MSVC 9                         #  #  #  #  #  #  #  .  #  #  .  #  #  ?  #  #  #  #  .  .
1712 dnl   mingw 2009-2011                .  #  .  #  .  .  .  .  #  #  .  .  .  ?  .  .  .  .  .  .
1713 dnl   mingw-w64 2011                 #  #  #  #  #  #  .  .  #  #  .  #  #  ?  .  #  #  #  .  .