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],
25 #include <sys/types.h>
26 #if HAVE_STDINT_H_WITH_UINTMAX
29 #if HAVE_INTTYPES_H_WITH_UINTMAX
30 # include <inttypes.h>
36 #if HAVE_STDINT_H_WITH_UINTMAX || HAVE_INTTYPES_H_WITH_UINTMAX
38 if (sprintf (buf, "%ju %d", (uintmax_t) 12345671, 33, 44, 55) < 0
39 || strcmp (buf, "12345671 33") != 0)
45 if (sprintf (buf, "%zu %d", (size_t) 12345672, 33, 44, 55) < 0
46 || strcmp (buf, "12345672 33") != 0)
49 if (sprintf (buf, "%tu %d", (ptrdiff_t) 12345673, 33, 44, 55) < 0
50 || strcmp (buf, "12345673 33") != 0)
53 if (sprintf (buf, "%Lg %d", (long double) 1.5, 33, 44, 55) < 0
54 || strcmp (buf, "1.5 33") != 0)
58 [gl_cv_func_printf_sizes_c99=yes],
59 [gl_cv_func_printf_sizes_c99=no],
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";;
85 # Guess yes on MSVC, no on mingw.
86 mingw*) AC_EGREP_CPP([Known], [
91 [gl_cv_func_printf_sizes_c99="guessing yes"],
92 [gl_cv_func_printf_sizes_c99="guessing no"])
94 # If we don't know, assume the worst.
95 *) gl_cv_func_printf_sizes_c99="guessing no";;
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],
116 static char buf[10000];
121 if (sprintf (buf, "%Lf %d", 1.75L, 33, 44, 55) < 0
122 || strcmp (buf, "1.750000 33") != 0)
125 if (sprintf (buf, "%Le %d", 1.75L, 33, 44, 55) < 0
126 || strcmp (buf, "1.750000e+00 33") != 0)
129 if (sprintf (buf, "%Lg %d", 1.75L, 33, 44, 55) < 0
130 || strcmp (buf, "1.75 33") != 0)
134 [gl_cv_func_printf_long_double=yes],
135 [gl_cv_func_printf_long_double=no],
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], [
147 [gl_cv_func_printf_long_double="guessing yes"],
148 [gl_cv_func_printf_long_double="guessing no"])
150 *) gl_cv_func_printf_long_double="guessing yes";;
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],
173 strisnan (const char *string, size_t start_index, size_t end_index)
175 if (start_index < end_index)
177 if (string[start_index] == '-')
179 if (start_index + 3 <= end_index
180 && memcmp (string + start_index, "nan", 3) == 0)
183 if (start_index == end_index
184 || (string[start_index] == '(' && string[end_index - 1] == ')'))
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;
202 if (sprintf (buf, "%f", 1.0 / zero) < 0
203 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
205 if (sprintf (buf, "%f", -1.0 / zero) < 0
206 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
208 if (sprintf (buf, "%f", zero / zero) < 0
209 || !strisnan (buf, 0, strlen (buf)))
211 if (sprintf (buf, "%e", 1.0 / zero) < 0
212 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
214 if (sprintf (buf, "%e", -1.0 / zero) < 0
215 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
217 if (sprintf (buf, "%e", zero / zero) < 0
218 || !strisnan (buf, 0, strlen (buf)))
220 if (sprintf (buf, "%g", 1.0 / zero) < 0
221 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
223 if (sprintf (buf, "%g", -1.0 / zero) < 0
224 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
226 if (sprintf (buf, "%g", zero / zero) < 0
227 || !strisnan (buf, 0, strlen (buf)))
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)
236 [gl_cv_func_printf_infinite=yes],
237 [gl_cv_func_printf_infinite=no],
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";;
257 beos*) gl_cv_func_printf_infinite="guessing yes";;
258 # Guess no on Android.
259 linux*-android*) gl_cv_func_printf_infinite="guessing no";;
261 # Guess yes on MSVC, no on mingw.
262 mingw*) AC_EGREP_CPP([Known], [
267 [gl_cv_func_printf_infinite="guessing yes"],
268 [gl_cv_func_printf_infinite="guessing no"])
270 # If we don't know, assume the worst.
271 *) gl_cv_func_printf_infinite="guessing no";;
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.])
295 case "$gl_cv_func_printf_long_double" in
297 AC_CACHE_CHECK([whether printf supports infinite 'long double' arguments],
298 [gl_cv_func_printf_infinite_long_double],
307 strisnan (const char *string, size_t start_index, size_t end_index)
309 if (start_index < end_index)
311 if (string[start_index] == '-')
313 if (start_index + 3 <= end_index
314 && memcmp (string + start_index, "nan", 3) == 0)
317 if (start_index == end_index
318 || (string[start_index] == '(' && string[end_index - 1] == ')'))
324 static char buf[10000];
325 static long double zeroL = 0.0L;
330 if (sprintf (buf, "%Lf", 1.0L / zeroL) < 0
331 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
333 if (sprintf (buf, "%Lf", -1.0L / zeroL) < 0
334 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
336 if (sprintf (buf, "%Lf", zeroL / zeroL) < 0
337 || !strisnan (buf, 0, strlen (buf)))
339 if (sprintf (buf, "%Le", 1.0L / zeroL) < 0
340 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
342 if (sprintf (buf, "%Le", -1.0L / zeroL) < 0
343 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
345 if (sprintf (buf, "%Le", zeroL / zeroL) < 0
346 || !strisnan (buf, 0, strlen (buf)))
348 if (sprintf (buf, "%Lg", 1.0L / zeroL) < 0
349 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
351 if (sprintf (buf, "%Lg", -1.0L / zeroL) < 0
352 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
354 if (sprintf (buf, "%Lg", zeroL / zeroL) < 0
355 || !strisnan (buf, 0, strlen (buf)))
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 \
367 # define LDBL80_WORDS(exponent,manthi,mantlo) \
368 { mantlo, manthi, exponent }
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)))
376 if (sprintf (buf, "%Le", x.value) < 0
377 || !strisnan (buf, 0, strlen (buf)))
379 if (sprintf (buf, "%Lg", x.value) < 0
380 || !strisnan (buf, 0, strlen (buf)))
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)))
390 if (sprintf (buf, "%Le", x.value) < 0
391 || !strisnan (buf, 0, strlen (buf)))
393 if (sprintf (buf, "%Lg", x.value) < 0
394 || !strisnan (buf, 0, strlen (buf)))
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)
402 if (sprintf (buf, "%Le", x.value) <= 0)
404 if (sprintf (buf, "%Lg", x.value) <= 0)
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)
412 if (sprintf (buf, "%Le", x.value) <= 0)
414 if (sprintf (buf, "%Lg", x.value) <= 0)
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)
422 if (sprintf (buf, "%Le", x.value) <= 0)
424 if (sprintf (buf, "%Lg", x.value) <= 0)
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)
432 if (sprintf (buf, "%Le", x.value) <= 0)
434 if (sprintf (buf, "%Lg", x.value) <= 0)
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)
442 if (sprintf (buf, "%Le", x.value) <= 0)
444 if (sprintf (buf, "%Lg", x.value) <= 0)
450 [gl_cv_func_printf_infinite_long_double=yes],
451 [gl_cv_func_printf_infinite_long_double=no],
453 # Guess no on ia64, x86_64, i386.
454 ia64 | x86_64 | i*86) gl_cv_func_printf_infinite_long_double="guessing no";;
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";;
469 # Guess yes on MSVC, no on mingw.
470 mingw*) AC_EGREP_CPP([Known], [
475 [gl_cv_func_printf_infinite_long_double="guessing yes"],
476 [gl_cv_func_printf_infinite_long_double="guessing no"])
478 # If we don't know, assume the worst.
479 *) gl_cv_func_printf_infinite_long_double="guessing no";;
487 gl_cv_func_printf_infinite_long_double="irrelevant"
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],
508 static char buf[100];
509 static double zero = 0.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))
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))
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))
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))
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
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))
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))
561 [gl_cv_func_printf_directive_a=yes],
562 [gl_cv_func_printf_directive_a=no],
565 # Guess yes on glibc >= 2.5 systems.
567 AC_EGREP_CPP([BZ2908], [
568 #include <features.h>
569 #ifdef __GNU_LIBRARY__
570 #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 5) || (__GLIBC__ > 2)) && !defined __UCLIBC__
575 [gl_cv_func_printf_directive_a="guessing yes"],
576 [gl_cv_func_printf_directive_a="guessing no"])
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";;
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],
604 static char buf[100];
605 static double zero = 0.0;
609 if (sprintf (buf, "%F %d", 1234567.0, 33, 44, 55) < 0
610 || strcmp (buf, "1234567.000000 33") != 0)
612 if (sprintf (buf, "%F", 1.0 / zero) < 0
613 || (strcmp (buf, "INF") != 0 && strcmp (buf, "INFINITY") != 0))
615 /* This catches a Cygwin 1.5.x bug. */
616 if (sprintf (buf, "%.F", 1234.0) < 0
617 || strcmp (buf, "1234") != 0)
621 [gl_cv_func_printf_directive_f=yes],
622 [gl_cv_func_printf_directive_f=no],
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";;
640 # Guess yes on MSVC, no on mingw.
641 mingw*) AC_EGREP_CPP([Known], [
646 [gl_cv_func_printf_directive_f="guessing yes"],
647 [gl_cv_func_printf_directive_f="guessing no"])
649 # If we don't know, assume the worst.
650 *) gl_cv_func_printf_directive_f="guessing no";;
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],
673 /* See page about "Parameter Validation" on msdn.microsoft.com. */
675 invalid_parameter_handler (const wchar_t *expression,
676 const wchar_t *function,
677 const wchar_t *file, unsigned int line,
683 static char fmtstring[10];
684 static char buf[100];
689 _set_invalid_parameter_handler (invalid_parameter_handler);
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
694 strcpy (fmtstring, "%d %n");
695 if (sprintf (buf, fmtstring, 123, &count, 33, 44, 55) < 0
696 || strcmp (buf, "123 ") != 0
701 [gl_cv_func_printf_directive_n=yes],
702 [gl_cv_func_printf_directive_n=no],
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";;
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
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],
730 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
732 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
733 included before <wchar.h>. */
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
747 static const wchar_t wstring[] = { 'a', 'b', 'c', 0 };
749 if (sprintf (buf, "%ls", wstring) < 0
750 || strcmp (buf, "abc") != 0)
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. */
756 static const wchar_t wstring[] = { 'a', 0 };
758 if (sprintf (buf, "%ls", wstring) < 0
759 || strcmp (buf, "a") != 0)
762 /* Test whether precisions in %ls are supported as specified in ISO C 99
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. */
771 static const wchar_t wstring[] = { 'a', 'b', (wchar_t) 0xfdfdfdfd, 0 };
773 if (sprintf (buf, "%.2ls", wstring) < 0
774 || strcmp (buf, "ab") != 0)
779 [gl_cv_func_printf_directive_ls=yes],
780 [gl_cv_func_printf_directive_ls=no],
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";;
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],
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];
821 sprintf (buf, format, 33, 55);
822 return (strcmp (buf, "55 33") != 0);
824 [gl_cv_func_printf_positions=yes],
825 [gl_cv_func_printf_positions=no],
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";;
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],
858 static char buf[100];
861 if (sprintf (buf, "%'d %d", 1234567, 99) < 0
862 || buf[strlen (buf) - 1] != '9')
866 [gl_cv_func_printf_flag_grouping=yes],
867 [gl_cv_func_printf_flag_grouping=no],
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";;
884 dnl Test whether the *printf family of functions supports the - flag correctly.
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],
900 static char buf[100];
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)
909 [gl_cv_func_printf_flag_leftadjust=yes],
910 [gl_cv_func_printf_flag_leftadjust=no],
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";;
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],
946 static char buf[100];
947 static double zero = 0.0;
950 if (sprintf (buf, "%010f", 1.0 / zero, 33, 44, 55) < 0
951 || (strcmp (buf, " inf") != 0
952 && strcmp (buf, " infinity") != 0))
956 [gl_cv_func_printf_flag_zero=yes],
957 [gl_cv_func_printf_flag_zero=no],
961 # Guess yes on glibc systems.
962 *-gnu* | gnu*) gl_cv_func_printf_flag_zero="guessing yes";;
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";;
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],
997 static char buf[5000];
1002 /* On BeOS, this would crash and show a dialog box. Avoid the crash. */
1005 if (sprintf (buf, "%.4000d %d", 1, 33, 44) < 4000 + 3)
1007 if (sprintf (buf, "%.4000f %d", 1.0, 33, 44) < 4000 + 5)
1009 if (sprintf (buf, "%.511f %d", 1.0, 33, 44) < 511 + 5
1012 if (sprintf (buf, "%.999f %d", 1.0, 33, 44) < 999 + 5
1017 [gl_cv_func_printf_precision=yes],
1018 [gl_cv_func_printf_precision=no],
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" ;;
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],
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([
1054 #include <sys/types.h>
1055 #include <sys/time.h>
1056 #include <sys/resource.h>
1060 struct rlimit limit;
1063 /* Some printf implementations allocate temporary space with malloc. */
1064 /* On BSD systems, malloc() is limited by RLIMIT_DATA. */
1066 if (getrlimit (RLIMIT_DATA, &limit) < 0)
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)
1074 /* On Linux systems, malloc() is limited by RLIMIT_AS. */
1076 if (getrlimit (RLIMIT_AS, &limit) < 0)
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)
1084 /* Some printf implementations allocate temporary space on the stack. */
1086 if (getrlimit (RLIMIT_STACK, &limit) < 0)
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)
1094 ret = printf ("%.5000000f", 1.0);
1095 return !(ret == 5000002 || (ret < 0 && errno == ENOMEM));
1099 if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
1100 (./conftest 2>&AS_MESSAGE_LOG_FD
1102 _AS_ECHO_LOG([\$? = $result])
1103 if test $result != 0 && test $result != 77; then result=1; fi
1105 ) >/dev/null 2>/dev/null
1107 0) gl_cv_func_printf_enomem="yes" ;;
1108 77) gl_cv_func_printf_enomem="guessing no" ;;
1109 *) gl_cv_func_printf_enomem="no" ;;
1112 gl_cv_func_printf_enomem="guessing no"
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"
1122 if test "$gl_cv_func_printf_enomem" = "guessing no"; then
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";;
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";;
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";;
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],
1180 # define my_snprintf snprintf
1182 # include <stdarg.h>
1183 static int my_snprintf (char *buf, int size, const char *format, ...)
1187 va_start (args, format);
1188 ret = vsnprintf (buf, size, format, args);
1193 static char buf[100];
1196 strcpy (buf, "ABCDEF");
1197 my_snprintf (buf, 3, "%d %d", 4567, 89);
1198 if (memcmp (buf, "45\0DEF", 6) != 0)
1202 [gl_cv_func_snprintf_truncation_c99=yes],
1203 [gl_cv_func_snprintf_truncation_c99=no],
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";;
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>
1260 dnl static char buf[8];
1261 dnl int retval = snprintf (buf, 3, "%d", 12345);
1262 dnl return retval >= 0 && retval < 3;
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],
1280 # define my_snprintf snprintf
1282 # include <stdarg.h>
1283 static int my_snprintf (char *buf, int size, const char *format, ...)
1287 va_start (args, format);
1288 ret = vsnprintf (buf, size, format, args);
1293 static char buf[100];
1296 strcpy (buf, "ABCDEF");
1297 if (my_snprintf (buf, 3, "%d %d", 4567, 89) != 7)
1299 if (my_snprintf (buf, 0, "%d %d", 4567, 89) != 7)
1301 if (my_snprintf (NULL, 0, "%d %d", 4567, 89) != 7)
1305 [gl_cv_func_snprintf_retval_c99=yes],
1306 [gl_cv_func_snprintf_retval_c99=no],
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";;
1336 # Guess yes on MSVC, no on mingw.
1337 mingw*) AC_EGREP_CPP([Known], [
1342 [gl_cv_func_snprintf_retval_c99="guessing yes"],
1343 [gl_cv_func_snprintf_retval_c99="guessing no"])
1345 # If we don't know, assume the worst.
1346 *) gl_cv_func_snprintf_retval_c99="guessing no";;
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],
1369 # define my_snprintf snprintf
1371 # include <stdarg.h>
1372 static int my_snprintf (char *buf, int size, const char *format, ...)
1376 va_start (args, format);
1377 ret = vsnprintf (buf, size, format, args);
1382 static char fmtstring[10];
1383 static char buf[100];
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
1390 strcpy (fmtstring, "%d %n");
1391 my_snprintf (buf, 4, fmtstring, 12345, &count, 33, 44, 55);
1396 [gl_cv_func_snprintf_directive_n=yes],
1397 [gl_cv_func_snprintf_directive_n=no],
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";;
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],
1456 # define my_snprintf snprintf
1458 # include <stdarg.h>
1459 static int my_snprintf (char *buf, int size, const char *format, ...)
1463 va_start (args, format);
1464 ret = vsnprintf (buf, size, format, args);
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';
1475 [gl_cv_func_snprintf_size1=yes],
1476 [gl_cv_func_snprintf_size1=no],
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" ;;
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
1492 dnl ---------------------------------------------------------------------
1493 dnl #include <stdio.h>
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';
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, ...)
1510 dnl va_start (args, format);
1511 dnl ret = vsnprintf (buf, size, format, args);
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';
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],
1535 static int my_snprintf (char *buf, int size, const char *format, ...)
1539 va_start (args, format);
1540 ret = vsnprintf (buf, size, format, args);
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';
1550 [gl_cv_func_vsnprintf_zerosize_c99=yes],
1551 [gl_cv_func_vsnprintf_zerosize_c99=no],
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";;
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 # # # # # # . . # # . # # ? . # # # . .