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