3 dnl Copyright (C) 2003, 2007-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 dnl Test whether the *printf family of functions supports the 'j', 'z', 't',
9 dnl 'L' size specifiers. (ISO C99, POSIX:2001)
10 dnl Result is gl_cv_func_printf_sizes_c99.
12 AC_DEFUN([gl_PRINTF_SIZES_C99],
14 AC_REQUIRE([AC_PROG_CC])
15 AC_REQUIRE([gl_AC_HEADER_STDINT_H])
16 AC_REQUIRE([gl_AC_HEADER_INTTYPES_H])
17 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
18 AC_CACHE_CHECK([whether printf supports size specifiers as in C99],
19 [gl_cv_func_printf_sizes_c99],
26 #include <sys/types.h>
27 #if HAVE_STDINT_H_WITH_UINTMAX
30 #if HAVE_INTTYPES_H_WITH_UINTMAX
31 # include <inttypes.h>
37 #if HAVE_STDINT_H_WITH_UINTMAX || HAVE_INTTYPES_H_WITH_UINTMAX
39 if (sprintf (buf, "%ju %d", (uintmax_t) 12345671, 33, 44, 55) < 0
40 || strcmp (buf, "12345671 33") != 0)
46 if (sprintf (buf, "%zu %d", (size_t) 12345672, 33, 44, 55) < 0
47 || strcmp (buf, "12345672 33") != 0)
50 if (sprintf (buf, "%tu %d", (ptrdiff_t) 12345673, 33, 44, 55) < 0
51 || strcmp (buf, "12345673 33") != 0)
54 if (sprintf (buf, "%Lg %d", (long double) 1.5, 33, 44, 55) < 0
55 || strcmp (buf, "1.5 33") != 0)
59 [gl_cv_func_printf_sizes_c99=yes],
60 [gl_cv_func_printf_sizes_c99=no],
64 # Guess yes on glibc systems.
65 *-gnu* | gnu*) gl_cv_func_printf_sizes_c99="guessing yes";;
66 # Guess yes on musl systems.
67 *-musl* | midipix*) gl_cv_func_printf_sizes_c99="guessing yes";;
68 # Guess yes on FreeBSD >= 5.
69 freebsd[1-4].*) gl_cv_func_printf_sizes_c99="guessing no";;
70 freebsd* | kfreebsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
71 midnightbsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
72 # Guess yes on Mac OS X >= 10.3.
73 darwin[1-6].*) gl_cv_func_printf_sizes_c99="guessing no";;
74 darwin*) gl_cv_func_printf_sizes_c99="guessing yes";;
75 # Guess yes on OpenBSD >= 3.9.
76 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
77 gl_cv_func_printf_sizes_c99="guessing no";;
78 openbsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
79 # Guess yes on Solaris >= 2.10.
80 solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";;
81 solaris*) gl_cv_func_printf_sizes_c99="guessing no";;
82 # Guess yes on NetBSD >= 3.
83 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
84 gl_cv_func_printf_sizes_c99="guessing no";;
85 netbsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
86 # Guess yes on Android.
87 linux*-android*) gl_cv_func_printf_sizes_c99="guessing yes";;
89 # Guess yes on MSVC, no on mingw.
90 windows*-msvc*) gl_cv_func_printf_sizes_c99="guessing yes" ;;
91 mingw* | windows*) AC_EGREP_CPP([Known], [
96 [gl_cv_func_printf_sizes_c99="guessing yes"],
97 [gl_cv_func_printf_sizes_c99="guessing no"])
99 # If we don't know, obey --enable-cross-guesses.
100 *) gl_cv_func_printf_sizes_c99="$gl_cross_guess_normal";;
106 dnl Test whether the *printf family of functions supports the 'w8', 'w16',
107 dnl 'w32', 'w64', 'wf8', 'wf16', 'wf32', 'wf64' size specifiers. (ISO C23)
108 dnl Result is gl_cv_func_printf_sizes_c23.
110 AC_DEFUN([gl_PRINTF_SIZES_C23],
112 AC_REQUIRE([AC_PROG_CC])
113 AC_REQUIRE([gl_AC_HEADER_STDINT_H])
114 AC_REQUIRE([gl_AC_HEADER_INTTYPES_H])
115 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
116 AC_CACHE_CHECK([whether printf supports size specifiers as in C23],
117 [gl_cv_func_printf_sizes_c23],
124 #include <sys/types.h>
125 #if HAVE_STDINT_H_WITH_UINTMAX
128 #if HAVE_INTTYPES_H_WITH_UINTMAX
129 # include <inttypes.h>
131 static char buf[100];
136 if (sprintf (buf, "%w8u %d", (uint8_t) 123, 33, 44, 55) < 0
137 || strcmp (buf, "123 33") != 0)
140 if (sprintf (buf, "%wf8u %d", (uint_fast8_t) 123, 33, 44, 55) < 0
141 || strcmp (buf, "123 33") != 0)
144 if (sprintf (buf, "%w16u %d", (uint16_t) 12345, 33, 44, 55) < 0
145 || strcmp (buf, "12345 33") != 0)
148 if (sprintf (buf, "%wf16u %d", (uint_fast16_t) 12345, 33, 44, 55) < 0
149 || strcmp (buf, "12345 33") != 0)
152 if (sprintf (buf, "%w32u %d", (uint32_t) 12345671, 33, 44, 55) < 0
153 || strcmp (buf, "12345671 33") != 0)
156 if (sprintf (buf, "%wf32u %d", (uint_fast32_t) 12345671, 33, 44, 55) < 0
157 || strcmp (buf, "12345671 33") != 0)
159 #if HAVE_STDINT_H_WITH_UINTMAX || HAVE_INTTYPES_H_WITH_UINTMAX
161 if (sprintf (buf, "%w64u %d", (uint64_t) 12345671, 33, 44, 55) < 0
162 || strcmp (buf, "12345671 33") != 0)
165 if (sprintf (buf, "%wf64u %d", (uint_fast64_t) 12345671, 33, 44, 55) < 0
166 || strcmp (buf, "12345671 33") != 0)
173 [gl_cv_func_printf_sizes_c23=yes],
174 [gl_cv_func_printf_sizes_c23=no],
177 # Guess no on glibc systems.
178 *-gnu* | gnu*) gl_cv_func_printf_sizes_c23="guessing no";;
179 # Guess no on musl systems.
180 *-musl* | midipix*) gl_cv_func_printf_sizes_c23="guessing no";;
181 # Guess no on Android.
182 linux*-android*) gl_cv_func_printf_sizes_c23="guessing no";;
183 # Guess no on native Windows.
184 mingw* | windows*) gl_cv_func_printf_sizes_c23="guessing no";;
185 # If we don't know, obey --enable-cross-guesses.
186 *) gl_cv_func_printf_sizes_c23="$gl_cross_guess_normal";;
192 dnl Test whether the *printf family of functions supports 'long double'
193 dnl arguments together with the 'L' size specifier. (ISO C99, POSIX:2001)
194 dnl Result is gl_cv_func_printf_long_double.
196 AC_DEFUN([gl_PRINTF_LONG_DOUBLE],
198 AC_REQUIRE([AC_PROG_CC])
199 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
200 AC_CACHE_CHECK([whether printf supports 'long double' arguments],
201 [gl_cv_func_printf_long_double],
207 static char buf[10000];
212 if (sprintf (buf, "%Lf %d", 1.75L, 33, 44, 55) < 0
213 || strcmp (buf, "1.750000 33") != 0)
216 if (sprintf (buf, "%Le %d", 1.75L, 33, 44, 55) < 0
217 || strcmp (buf, "1.750000e+00 33") != 0)
220 if (sprintf (buf, "%Lg %d", 1.75L, 33, 44, 55) < 0
221 || strcmp (buf, "1.75 33") != 0)
225 [gl_cv_func_printf_long_double=yes],
226 [gl_cv_func_printf_long_double=no],
229 beos*) gl_cv_func_printf_long_double="guessing no";;
230 # Guess yes on Android.
231 linux*-android*) gl_cv_func_printf_long_double="guessing yes";;
232 # Guess yes on MSVC, no on mingw.
233 windows*-msvc*) gl_cv_func_printf_long_double="guessing yes" ;;
234 mingw* | windows*) AC_EGREP_CPP([Known], [
239 [gl_cv_func_printf_long_double="guessing yes"],
240 [gl_cv_func_printf_long_double="guessing no"])
242 *) gl_cv_func_printf_long_double="guessing yes";;
248 dnl Test whether the *printf family of functions supports infinite and NaN
249 dnl 'double' arguments and negative zero arguments in the %f, %e, %g
250 dnl directives. (ISO C99, POSIX:2001)
251 dnl Result is gl_cv_func_printf_infinite.
253 AC_DEFUN([gl_PRINTF_INFINITE],
255 AC_REQUIRE([AC_PROG_CC])
256 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
257 AC_CACHE_CHECK([whether printf supports infinite 'double' arguments],
258 [gl_cv_func_printf_infinite],
265 strisnan (const char *string, size_t start_index, size_t end_index)
267 if (start_index < end_index)
269 if (string[start_index] == '-')
271 if (start_index + 3 <= end_index
272 && memcmp (string + start_index, "nan", 3) == 0)
275 if (start_index == end_index
276 || (string[start_index] == '(' && string[end_index - 1] == ')'))
285 static double plus_zero = 0.0;
286 double minus_zero = - plus_zero;
287 return memcmp (&plus_zero, &minus_zero, sizeof (double)) != 0;
289 static char buf[10000];
290 static double zero = 0.0;
294 if (sprintf (buf, "%f", 1.0 / zero) < 0
295 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
297 if (sprintf (buf, "%f", -1.0 / zero) < 0
298 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
300 if (sprintf (buf, "%f", zero / zero) < 0
301 || !strisnan (buf, 0, strlen (buf)))
303 if (sprintf (buf, "%e", 1.0 / zero) < 0
304 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
306 if (sprintf (buf, "%e", -1.0 / zero) < 0
307 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
309 if (sprintf (buf, "%e", zero / zero) < 0
310 || !strisnan (buf, 0, strlen (buf)))
312 if (sprintf (buf, "%g", 1.0 / zero) < 0
313 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
315 if (sprintf (buf, "%g", -1.0 / zero) < 0
316 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
318 if (sprintf (buf, "%g", zero / zero) < 0
319 || !strisnan (buf, 0, strlen (buf)))
321 /* This test fails on HP-UX 10.20. */
322 if (have_minus_zero ())
323 if (sprintf (buf, "%g", - zero) < 0
324 || strcmp (buf, "-0") != 0)
328 [gl_cv_func_printf_infinite=yes],
329 [gl_cv_func_printf_infinite=no],
333 # Guess yes on glibc systems.
334 *-gnu* | gnu*) gl_cv_func_printf_infinite="guessing yes";;
335 # Guess yes on musl systems.
336 *-musl* | midipix*) gl_cv_func_printf_infinite="guessing yes";;
337 # Guess yes on FreeBSD >= 6.
338 freebsd[1-5].*) gl_cv_func_printf_infinite="guessing no";;
339 freebsd* | kfreebsd*) gl_cv_func_printf_infinite="guessing yes";;
340 midnightbsd*) gl_cv_func_printf_infinite="guessing yes";;
341 # Guess yes on Mac OS X >= 10.3.
342 darwin[1-6].*) gl_cv_func_printf_infinite="guessing no";;
343 darwin*) gl_cv_func_printf_infinite="guessing yes";;
344 # Guess yes on HP-UX >= 11.
345 hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite="guessing no";;
346 hpux*) gl_cv_func_printf_infinite="guessing yes";;
347 # Guess yes on NetBSD >= 3.
348 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
349 gl_cv_func_printf_infinite="guessing no";;
350 netbsd*) gl_cv_func_printf_infinite="guessing yes";;
351 # Guess yes on OpenBSD >= 6.0.
352 openbsd[1-5].*) gl_cv_func_printf_infinite="guessing no";;
353 openbsd*) gl_cv_func_printf_infinite="guessing yes";;
355 beos*) gl_cv_func_printf_infinite="guessing yes";;
356 # Guess no on Android.
357 linux*-android*) gl_cv_func_printf_infinite="guessing no";;
359 # Guess yes on MSVC, no on mingw.
360 windows*-msvc*) gl_cv_func_printf_infinite="guessing yes" ;;
361 mingw* | windows*) AC_EGREP_CPP([Known], [
366 [gl_cv_func_printf_infinite="guessing yes"],
367 [gl_cv_func_printf_infinite="guessing no"])
369 # If we don't know, obey --enable-cross-guesses.
370 *) gl_cv_func_printf_infinite="$gl_cross_guess_normal";;
376 dnl Test whether the *printf family of functions supports infinite and NaN
377 dnl 'long double' arguments in the %f, %e, %g directives. (ISO C99, POSIX:2001)
378 dnl Result is gl_cv_func_printf_infinite_long_double.
380 AC_DEFUN([gl_PRINTF_INFINITE_LONG_DOUBLE],
382 AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
383 AC_REQUIRE([AC_PROG_CC])
384 AC_REQUIRE([gl_BIGENDIAN])
385 AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
386 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
387 dnl The user can set or unset the variable gl_printf_safe to indicate
388 dnl that he wishes a safe handling of non-IEEE-754 'long double' values.
389 if test -n "$gl_printf_safe"; then
390 AC_DEFINE([CHECK_PRINTF_SAFE], [1],
391 [Define if you wish *printf() functions that have a safe handling of
392 non-IEEE-754 'long double' values.])
394 case "$gl_cv_func_printf_long_double" in
396 AC_CACHE_CHECK([whether printf supports infinite 'long double' arguments],
397 [gl_cv_func_printf_infinite_long_double],
406 strisnan (const char *string, size_t start_index, size_t end_index)
408 if (start_index < end_index)
410 if (string[start_index] == '-')
412 if (start_index + 3 <= end_index
413 && memcmp (string + start_index, "nan", 3) == 0)
416 if (start_index == end_index
417 || (string[start_index] == '(' && string[end_index - 1] == ')'))
423 static char buf[10000];
424 static long double zeroL = 0.0L;
429 if (sprintf (buf, "%Lf", 1.0L / zeroL) < 0
430 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
432 if (sprintf (buf, "%Lf", -1.0L / zeroL) < 0
433 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
435 if (sprintf (buf, "%Lf", zeroL / zeroL) < 0
436 || !strisnan (buf, 0, strlen (buf)))
438 if (sprintf (buf, "%Le", 1.0L / zeroL) < 0
439 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
441 if (sprintf (buf, "%Le", -1.0L / zeroL) < 0
442 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
444 if (sprintf (buf, "%Le", zeroL / zeroL) < 0
445 || !strisnan (buf, 0, strlen (buf)))
447 if (sprintf (buf, "%Lg", 1.0L / zeroL) < 0
448 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
450 if (sprintf (buf, "%Lg", -1.0L / zeroL) < 0
451 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
453 if (sprintf (buf, "%Lg", zeroL / zeroL) < 0
454 || !strisnan (buf, 0, strlen (buf)))
456 #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
457 /* Representation of an 80-bit 'long double' as an initializer for a sequence
458 of 'unsigned int' words. */
459 # ifdef WORDS_BIGENDIAN
460 # define LDBL80_WORDS(exponent,manthi,mantlo) \
461 { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
462 ((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16), \
463 (unsigned int) (mantlo) << 16 \
466 # define LDBL80_WORDS(exponent,manthi,mantlo) \
467 { mantlo, manthi, exponent }
470 static union { unsigned int word[4]; long double value; } x =
471 { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
472 if (sprintf (buf, "%Lf", x.value) < 0
473 || !strisnan (buf, 0, strlen (buf)))
475 if (sprintf (buf, "%Le", x.value) < 0
476 || !strisnan (buf, 0, strlen (buf)))
478 if (sprintf (buf, "%Lg", x.value) < 0
479 || !strisnan (buf, 0, strlen (buf)))
483 /* Signalling NaN. */
484 static union { unsigned int word[4]; long double value; } x =
485 { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
486 if (sprintf (buf, "%Lf", x.value) < 0
487 || !strisnan (buf, 0, strlen (buf)))
489 if (sprintf (buf, "%Le", x.value) < 0
490 || !strisnan (buf, 0, strlen (buf)))
492 if (sprintf (buf, "%Lg", x.value) < 0
493 || !strisnan (buf, 0, strlen (buf)))
497 static union { unsigned int word[4]; long double value; } x =
498 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
499 if (sprintf (buf, "%Lf", x.value) <= 0)
501 if (sprintf (buf, "%Le", x.value) <= 0)
503 if (sprintf (buf, "%Lg", x.value) <= 0)
506 { /* Pseudo-Infinity. */
507 static union { unsigned int word[4]; long double value; } x =
508 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
509 if (sprintf (buf, "%Lf", x.value) <= 0)
511 if (sprintf (buf, "%Le", x.value) <= 0)
513 if (sprintf (buf, "%Lg", x.value) <= 0)
517 static union { unsigned int word[4]; long double value; } x =
518 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
519 if (sprintf (buf, "%Lf", x.value) <= 0)
521 if (sprintf (buf, "%Le", x.value) <= 0)
523 if (sprintf (buf, "%Lg", x.value) <= 0)
526 { /* Unnormalized number. */
527 static union { unsigned int word[4]; long double value; } x =
528 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
529 if (sprintf (buf, "%Lf", x.value) <= 0)
531 if (sprintf (buf, "%Le", x.value) <= 0)
533 if (sprintf (buf, "%Lg", x.value) <= 0)
536 { /* Pseudo-Denormal. */
537 static union { unsigned int word[4]; long double value; } x =
538 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
539 if (sprintf (buf, "%Lf", x.value) <= 0)
541 if (sprintf (buf, "%Le", x.value) <= 0)
543 if (sprintf (buf, "%Lg", x.value) <= 0)
549 [gl_cv_func_printf_infinite_long_double=yes],
550 [gl_cv_func_printf_infinite_long_double=no],
552 # Guess no on ia64, x86_64, i386.
553 ia64 | x86_64 | i*86) gl_cv_func_printf_infinite_long_double="guessing no";;
557 # Guess yes on glibc systems.
558 *-gnu* | gnu*) gl_cv_func_printf_infinite_long_double="guessing yes";;
559 # Guess yes on musl systems.
560 *-musl* | midipix*) gl_cv_func_printf_infinite_long_double="guessing yes";;
561 # Guess yes on FreeBSD >= 6.
562 freebsd[1-5].*) gl_cv_func_printf_infinite_long_double="guessing no";;
563 freebsd* | kfreebsd*) gl_cv_func_printf_infinite_long_double="guessing yes";;
564 midnightbsd*) gl_cv_func_printf_infinite_long_double="guessing yes";;
565 # Guess yes on HP-UX >= 11.
566 hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite_long_double="guessing no";;
567 hpux*) gl_cv_func_printf_infinite_long_double="guessing yes";;
568 # Guess yes on OpenBSD >= 6.0.
569 openbsd[1-5].*) gl_cv_func_printf_infinite_long_double="guessing no";;
570 openbsd*) gl_cv_func_printf_infinite_long_double="guessing yes";;
571 # Guess no on Android.
572 linux*-android*) gl_cv_func_printf_infinite_long_double="guessing no";;
574 # Guess yes on MSVC, no on mingw.
575 windows*-msvc*) gl_cv_func_printf_infinite_long_double="guessing yes" ;;
576 mingw* | windows*) AC_EGREP_CPP([Known], [
581 [gl_cv_func_printf_infinite_long_double="guessing yes"],
582 [gl_cv_func_printf_infinite_long_double="guessing no"])
584 # If we don't know, obey --enable-cross-guesses.
585 *) gl_cv_func_printf_infinite_long_double="$gl_cross_guess_normal";;
593 gl_cv_func_printf_infinite_long_double="irrelevant"
598 dnl Test whether the *printf family of functions supports the 'a' and 'A'
599 dnl conversion specifier for hexadecimal output of floating-point numbers.
600 dnl (ISO C99, POSIX:2001)
601 dnl Result is gl_cv_func_printf_directive_a.
603 AC_DEFUN([gl_PRINTF_DIRECTIVE_A],
605 AC_REQUIRE([AC_PROG_CC])
606 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
607 AC_CACHE_CHECK([whether printf supports the 'a' and 'A' directives],
608 [gl_cv_func_printf_directive_a],
614 static char buf[100];
615 static double zero = 0.0;
619 if (sprintf (buf, "%a %d", 3.1416015625, 33, 44, 55) < 0
620 || (strcmp (buf, "0x1.922p+1 33") != 0
621 && strcmp (buf, "0x3.244p+0 33") != 0
622 && strcmp (buf, "0x6.488p-1 33") != 0
623 && strcmp (buf, "0xc.91p-2 33") != 0))
625 if (sprintf (buf, "%A %d", -3.1416015625, 33, 44, 55) < 0
626 || (strcmp (buf, "-0X1.922P+1 33") != 0
627 && strcmp (buf, "-0X3.244P+0 33") != 0
628 && strcmp (buf, "-0X6.488P-1 33") != 0
629 && strcmp (buf, "-0XC.91P-2 33") != 0))
631 /* This catches a FreeBSD 13.0 bug: it doesn't round. */
632 if (sprintf (buf, "%.2a %d", 1.51, 33, 44, 55) < 0
633 || (strcmp (buf, "0x1.83p+0 33") != 0
634 && strcmp (buf, "0x3.05p-1 33") != 0
635 && strcmp (buf, "0x6.0ap-2 33") != 0
636 && strcmp (buf, "0xc.14p-3 33") != 0))
638 /* This catches a Mac OS X 10.12.4 (Darwin 16.5) bug: it doesn't round. */
639 if (sprintf (buf, "%.0a %d", 1.51, 33, 44, 55) < 0
640 || (strcmp (buf, "0x2p+0 33") != 0
641 && strcmp (buf, "0x3p-1 33") != 0
642 && strcmp (buf, "0x6p-2 33") != 0
643 && strcmp (buf, "0xcp-3 33") != 0))
645 /* This catches a FreeBSD 6.1 bug. See
646 <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */
647 if (sprintf (buf, "%010a %d", 1.0 / zero, 33, 44, 55) < 0
650 /* This catches a Mac OS X 10.3.9 (Darwin 7.9) bug. */
651 if (sprintf (buf, "%.1a", 1.999) < 0
652 || (strcmp (buf, "0x1.0p+1") != 0
653 && strcmp (buf, "0x2.0p+0") != 0
654 && strcmp (buf, "0x4.0p-1") != 0
655 && strcmp (buf, "0x8.0p-2") != 0))
657 /* This catches the same Mac OS X 10.3.9 (Darwin 7.9) bug and also a
658 glibc 2.4 bug <https://sourceware.org/bugzilla/show_bug.cgi?id=2908>. */
659 if (sprintf (buf, "%.1La", 1.999L) < 0
660 || (strcmp (buf, "0x1.0p+1") != 0
661 && strcmp (buf, "0x2.0p+0") != 0
662 && strcmp (buf, "0x4.0p-1") != 0
663 && strcmp (buf, "0x8.0p-2") != 0))
667 [gl_cv_func_printf_directive_a=yes],
668 [gl_cv_func_printf_directive_a=no],
671 # Guess yes on glibc >= 2.5 systems.
673 AC_EGREP_CPP([BZ2908], [
674 #include <features.h>
675 #ifdef __GNU_LIBRARY__
676 #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 5) || (__GLIBC__ > 2)) && !defined __UCLIBC__
681 [gl_cv_func_printf_directive_a="guessing yes"],
682 [gl_cv_func_printf_directive_a="guessing no"])
684 # Guess yes on musl systems.
685 *-musl* | midipix*) gl_cv_func_printf_directive_a="guessing yes";;
686 # Guess no on Android.
687 linux*-android*) gl_cv_func_printf_directive_a="guessing no";;
688 # Guess no on native Windows.
689 mingw* | windows*) gl_cv_func_printf_directive_a="guessing no";;
690 # If we don't know, obey --enable-cross-guesses.
691 *) gl_cv_func_printf_directive_a="$gl_cross_guess_normal";;
697 dnl Test whether the *printf family of functions supports the 'b' conversion
698 dnl specifier for binary output of integers.
700 dnl Result is gl_cv_func_printf_directive_b.
702 AC_DEFUN([gl_PRINTF_DIRECTIVE_B],
704 AC_REQUIRE([AC_PROG_CC])
705 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
706 AC_CACHE_CHECK([whether printf supports the 'b' directive],
707 [gl_cv_func_printf_directive_b],
713 static char buf[100];
717 if (sprintf (buf, "%b %d", 12345, 33, 44, 55) < 0
718 || strcmp (buf, "11000000111001 33") != 0)
722 [gl_cv_func_printf_directive_b=yes],
723 [gl_cv_func_printf_directive_b=no],
726 # Guess yes on glibc >= 2.35 systems.
728 AC_EGREP_CPP([Lucky], [
729 #include <features.h>
730 #ifdef __GNU_LIBRARY__
731 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 35) || (__GLIBC__ > 2)
736 [gl_cv_func_printf_directive_uppercase_b="guessing yes"],
737 [gl_cv_func_printf_directive_uppercase_b="guessing no"])
739 # Guess no on musl systems.
740 *-musl* | midipix*) gl_cv_func_printf_directive_b="guessing no";;
741 # Guess no on Android.
742 linux*-android*) gl_cv_func_printf_directive_b="guessing no";;
743 # Guess no on native Windows.
744 mingw* | windows*) gl_cv_func_printf_directive_b="guessing no";;
745 # If we don't know, obey --enable-cross-guesses.
746 *) gl_cv_func_printf_directive_b="$gl_cross_guess_normal";;
752 dnl Test whether the *printf family of functions supports the 'B' conversion
753 dnl specifier for binary output of integers.
754 dnl (GNU, encouraged by ISO C23 § 7.23.6.1)
755 dnl Result is gl_cv_func_printf_directive_uppercase_b.
757 AC_DEFUN([gl_PRINTF_DIRECTIVE_UPPERCASE_B],
759 AC_REQUIRE([AC_PROG_CC])
760 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
761 AC_CACHE_CHECK([whether printf supports the 'B' directive],
762 [gl_cv_func_printf_directive_uppercase_b],
768 static char buf[100];
772 if (sprintf (buf, "%#B %d", 12345, 33, 44, 55) < 0
773 || strcmp (buf, "0B11000000111001 33") != 0)
777 [gl_cv_func_printf_directive_uppercase_b=yes],
778 [gl_cv_func_printf_directive_uppercase_b=no],
781 # Guess yes on glibc >= 2.35 systems.
783 AC_EGREP_CPP([Lucky], [
784 #include <features.h>
785 #ifdef __GNU_LIBRARY__
786 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 35) || (__GLIBC__ > 2)
791 [gl_cv_func_printf_directive_uppercase_b="guessing yes"],
792 [gl_cv_func_printf_directive_uppercase_b="guessing no"])
794 # Guess no on musl systems.
795 *-musl* | midipix*) gl_cv_func_printf_directive_uppercase_b="guessing no";;
796 # Guess no on Android.
797 linux*-android*) gl_cv_func_printf_directive_uppercase_b="guessing no";;
798 # Guess no on native Windows.
799 mingw* | windows*) gl_cv_func_printf_directive_uppercase_b="guessing no";;
800 # If we don't know, obey --enable-cross-guesses.
801 *) gl_cv_func_printf_directive_uppercase_b="$gl_cross_guess_normal";;
807 dnl Test whether the *printf family of functions supports the %F format
808 dnl directive. (ISO C99, POSIX:2001)
809 dnl Result is gl_cv_func_printf_directive_f.
811 AC_DEFUN([gl_PRINTF_DIRECTIVE_F],
813 AC_REQUIRE([AC_PROG_CC])
814 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
815 AC_CACHE_CHECK([whether printf supports the 'F' directive],
816 [gl_cv_func_printf_directive_f],
822 static char buf[100];
823 static double zero = 0.0;
827 if (sprintf (buf, "%F %d", 1234567.0, 33, 44, 55) < 0
828 || strcmp (buf, "1234567.000000 33") != 0)
830 if (sprintf (buf, "%F", 1.0 / zero) < 0
831 || (strcmp (buf, "INF") != 0 && strcmp (buf, "INFINITY") != 0))
833 /* This catches a Cygwin 1.5.x bug. */
834 if (sprintf (buf, "%.F", 1234.0) < 0
835 || strcmp (buf, "1234") != 0)
839 [gl_cv_func_printf_directive_f=yes],
840 [gl_cv_func_printf_directive_f=no],
844 # Guess yes on glibc systems.
845 *-gnu* | gnu*) gl_cv_func_printf_directive_f="guessing yes";;
846 # Guess yes on musl systems.
847 *-musl* | midipix*) gl_cv_func_printf_directive_f="guessing yes";;
848 # Guess yes on FreeBSD >= 6.
849 freebsd[1-5].*) gl_cv_func_printf_directive_f="guessing no";;
850 freebsd* | kfreebsd*) gl_cv_func_printf_directive_f="guessing yes";;
851 midnightbsd*) gl_cv_func_printf_directive_f="guessing yes";;
852 # Guess yes on Mac OS X >= 10.3.
853 darwin[1-6].*) gl_cv_func_printf_directive_f="guessing no";;
854 darwin*) gl_cv_func_printf_directive_f="guessing yes";;
855 # Guess yes on OpenBSD >= 6.0.
856 openbsd[1-5].*) gl_cv_func_printf_directive_f="guessing no";;
857 openbsd*) gl_cv_func_printf_directive_f="guessing yes";;
858 # Guess yes on Solaris >= 2.10.
859 solaris2.[1-9][0-9]*) gl_cv_func_printf_directive_f="guessing yes";;
860 solaris*) gl_cv_func_printf_directive_f="guessing no";;
861 # Guess no on Android.
862 linux*-android*) gl_cv_func_printf_directive_f="guessing no";;
864 # Guess yes on MSVC, no on mingw.
865 windows*-msvc*) gl_cv_func_printf_directive_f="guessing yes" ;;
866 mingw* | windows*) AC_EGREP_CPP([Known], [
871 [gl_cv_func_printf_directive_f="guessing yes"],
872 [gl_cv_func_printf_directive_f="guessing no"])
874 # If we don't know, obey --enable-cross-guesses.
875 *) gl_cv_func_printf_directive_f="$gl_cross_guess_normal";;
881 dnl Test whether the *printf family of functions supports the %n format
882 dnl directive. (ISO C99, POSIX:2001)
883 dnl Result is gl_cv_func_printf_directive_n.
885 AC_DEFUN([gl_PRINTF_DIRECTIVE_N],
887 AC_REQUIRE([AC_PROG_CC])
888 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
889 AC_CACHE_CHECK([whether printf supports the 'n' directive],
890 [gl_cv_func_printf_directive_n],
899 #include <inttypes.h>
900 /* See page about "Parameter Validation" on msdn.microsoft.com.
901 <https://docs.microsoft.com/en-us/cpp/c-runtime-library/parameter-validation>
902 <https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/set-invalid-parameter-handler-set-thread-local-invalid-parameter-handler> */
904 invalid_parameter_handler (const wchar_t *expression,
905 const wchar_t *function,
906 const wchar_t *file, unsigned int line,
913 abort_handler (int sig)
918 static char fmtstring[10];
919 static char buf[100];
924 _set_invalid_parameter_handler (invalid_parameter_handler);
926 signal (SIGABRT, abort_handler);
927 /* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2)
928 support %n in format strings in read-only memory but not in writable
930 strcpy (fmtstring, "%d %n");
931 if (sprintf (buf, fmtstring, 123, &count, 33, 44, 55) < 0
932 || strcmp (buf, "123 ") != 0
937 [gl_cv_func_printf_directive_n=yes],
938 [gl_cv_func_printf_directive_n=no],
940 # Guess no on glibc when _FORTIFY_SOURCE >= 2.
941 *-gnu* | gnu*) AC_COMPILE_IFELSE(
943 [[#if _FORTIFY_SOURCE >= 2
947 [gl_cv_func_printf_directive_n="guessing yes"],
948 [gl_cv_func_printf_directive_n="guessing no"])
950 # Guess no on Android.
951 linux*-android*) gl_cv_func_printf_directive_n="guessing no";;
952 # Guess no on native Windows.
953 mingw* | windows*) gl_cv_func_printf_directive_n="guessing no";;
954 *) gl_cv_func_printf_directive_n="guessing yes";;
960 dnl Test whether the *printf family of functions supports the %ls format
961 dnl directive and in particular, when a precision is specified, whether
962 dnl the functions stop converting the wide string argument when the number
963 dnl of bytes that have been produced by this conversion equals or exceeds
965 dnl Result is gl_cv_func_printf_directive_ls.
967 AC_DEFUN([gl_PRINTF_DIRECTIVE_LS],
969 AC_REQUIRE([AC_PROG_CC])
970 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
971 AC_CACHE_CHECK([whether printf supports the 'ls' directive],
972 [gl_cv_func_printf_directive_ls],
983 /* Test whether %ls works at all.
984 This test fails on OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku, but not on
987 static const wchar_t wstring[] = { 'a', 'b', 'c', 0 };
989 if (sprintf (buf, "%ls", wstring) < 0
990 || strcmp (buf, "abc") != 0)
993 /* This test fails on IRIX 6.5, Solaris 2.6, Cygwin 1.5, Haiku (with an
994 assertion failure inside libc), but not on OpenBSD 4.0. */
996 static const wchar_t wstring[] = { 'a', 0 };
998 if (sprintf (buf, "%ls", wstring) < 0
999 || strcmp (buf, "a") != 0)
1002 /* Test whether precisions in %ls are supported as specified in ISO C 99
1004 "If a precision is specified, no more than that many bytes are written
1005 (including shift sequences, if any), and the array shall contain a
1006 null wide character if, to equal the multibyte character sequence
1007 length given by the precision, the function would need to access a
1008 wide character one past the end of the array."
1009 This test fails on Solaris 10. */
1011 static const wchar_t wstring[] = { 'a', 'b', (wchar_t) 0xfdfdfdfd, 0 };
1013 if (sprintf (buf, "%.2ls", wstring) < 0
1014 || strcmp (buf, "ab") != 0)
1019 [gl_cv_func_printf_directive_ls=yes],
1020 [gl_cv_func_printf_directive_ls=no],
1024 # Guess yes on OpenBSD >= 6.0.
1025 openbsd[1-5].*) gl_cv_func_printf_directive_ls="guessing no";;
1026 openbsd*) gl_cv_func_printf_directive_ls="guessing yes";;
1027 irix*) gl_cv_func_printf_directive_ls="guessing no";;
1028 solaris*) gl_cv_func_printf_directive_ls="guessing no";;
1029 cygwin*) gl_cv_func_printf_directive_ls="guessing no";;
1030 beos* | haiku*) gl_cv_func_printf_directive_ls="guessing no";;
1031 # Guess no on Android.
1032 linux*-android*) gl_cv_func_printf_directive_ls="guessing no";;
1033 # Guess yes on native Windows.
1034 mingw* | windows*) gl_cv_func_printf_directive_ls="guessing yes";;
1035 *) gl_cv_func_printf_directive_ls="guessing yes";;
1042 dnl Test whether the *printf family of functions supports the %lc format
1043 dnl directive and in particular, when the argument is a null wide character,
1044 dnl whether the functions produce a NUL byte, as specified in ISO C 23
1045 dnl after the issue GB-141 was fixed.
1046 dnl Result is gl_cv_func_printf_directive_lc.
1048 AC_DEFUN([gl_PRINTF_DIRECTIVE_LC],
1050 AC_REQUIRE([AC_PROG_CC])
1051 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1052 AC_CACHE_CHECK([whether printf supports the 'lc' directive correctly],
1053 [gl_cv_func_printf_directive_lc],
1064 /* This test fails on musl libc 1.2.4. */
1067 if (sprintf (buf, "%lc%lc%lc", (wint_t) 'a', (wint_t) 0, (wint_t) 'z') < 0
1068 || memcmp (buf, "a\0z", 4) != 0)
1073 [gl_cv_func_printf_directive_lc=yes],
1074 [gl_cv_func_printf_directive_lc=no],
1078 # Guess no on musl libc.
1079 *-musl* | midipix*) gl_cv_func_printf_directive_lc="guessing no";;
1080 # Guess yes otherwise.
1081 *) gl_cv_func_printf_directive_lc="guessing yes";;
1088 dnl Test whether the *printf family of functions supports POSIX/XSI format
1089 dnl strings with positions. (POSIX:2001)
1090 dnl Result is gl_cv_func_printf_positions.
1092 AC_DEFUN_ONCE([gl_PRINTF_POSITIONS],
1094 AC_REQUIRE([AC_PROG_CC])
1095 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1096 AC_CACHE_CHECK([whether printf supports POSIX/XSI format strings with positions],
1097 [gl_cv_func_printf_positions],
1103 /* The string "%2$d %1$d", with dollar characters protected from the shell's
1104 dollar expansion (possibly an autoconf bug). */
1105 static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' };
1106 static char buf[100];
1109 sprintf (buf, format, 33, 55);
1110 return (strcmp (buf, "55 33") != 0);
1112 [gl_cv_func_printf_positions=yes],
1113 [gl_cv_func_printf_positions=no],
1117 netbsd[1-3]* | netbsdelf[1-3]* | netbsdaout[1-3]* | netbsdcoff[1-3]*)
1118 gl_cv_func_printf_positions="guessing no";;
1120 gl_cv_func_printf_positions="guessing no";;
1121 # Guess yes on Android.
1123 gl_cv_func_printf_positions="guessing yes";;
1124 # Guess no on native Windows.
1125 mingw* | windows* | pw*)
1126 gl_cv_func_printf_positions="guessing no";;
1128 gl_cv_func_printf_positions="guessing yes";;
1135 dnl Test whether the *printf family of functions supports POSIX/XSI format
1136 dnl strings with the ' flag for grouping of decimal digits. (POSIX:2001)
1137 dnl Result is gl_cv_func_printf_flag_grouping.
1139 AC_DEFUN([gl_PRINTF_FLAG_GROUPING],
1141 AC_REQUIRE([AC_PROG_CC])
1142 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1143 AC_CACHE_CHECK([whether printf supports the grouping flag],
1144 [gl_cv_func_printf_flag_grouping],
1150 static char buf[100];
1153 if (sprintf (buf, "%'d %d", 1234567, 99) < 0
1154 || buf[strlen (buf) - 1] != '9')
1158 [gl_cv_func_printf_flag_grouping=yes],
1159 [gl_cv_func_printf_flag_grouping=no],
1163 cygwin*) gl_cv_func_printf_flag_grouping="guessing no";;
1164 netbsd*) gl_cv_func_printf_flag_grouping="guessing no";;
1165 # Guess no on Android.
1166 linux*-android*) gl_cv_func_printf_flag_grouping="guessing no";;
1167 # Guess no on native Windows.
1168 mingw* | windows* | pw*) gl_cv_func_printf_flag_grouping="guessing no";;
1169 *) gl_cv_func_printf_flag_grouping="guessing yes";;
1176 dnl Test whether the *printf family of functions supports the - flag correctly.
1178 dnl <https://lists.gnu.org/r/bug-coreutils/2008-02/msg00035.html>
1179 dnl Result is gl_cv_func_printf_flag_leftadjust.
1181 AC_DEFUN([gl_PRINTF_FLAG_LEFTADJUST],
1183 AC_REQUIRE([AC_PROG_CC])
1184 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1185 AC_CACHE_CHECK([whether printf supports the left-adjust flag correctly],
1186 [gl_cv_func_printf_flag_leftadjust],
1192 static char buf[100];
1195 /* Check that a '-' flag is not annihilated by a negative width. */
1196 if (sprintf (buf, "a%-*sc", -3, "b") < 0
1197 || strcmp (buf, "ab c") != 0)
1201 [gl_cv_func_printf_flag_leftadjust=yes],
1202 [gl_cv_func_printf_flag_leftadjust=no],
1206 # Guess yes on HP-UX 11.
1207 hpux11*) gl_cv_func_printf_flag_leftadjust="guessing yes";;
1208 # Guess no on HP-UX 10 and older.
1209 hpux*) gl_cv_func_printf_flag_leftadjust="guessing no";;
1210 # Guess yes on Android.
1211 linux*-android*) gl_cv_func_printf_flag_leftadjust="guessing yes";;
1212 # Guess yes on native Windows.
1213 mingw* | windows*) gl_cv_func_printf_flag_leftadjust="guessing yes";;
1214 # Guess yes otherwise.
1215 *) gl_cv_func_printf_flag_leftadjust="guessing yes";;
1222 dnl Test whether the *printf family of functions supports padding of non-finite
1223 dnl values with the 0 flag correctly. (ISO C99 + TC1 + TC2.) See
1224 dnl <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html>
1225 dnl Result is gl_cv_func_printf_flag_zero.
1227 AC_DEFUN([gl_PRINTF_FLAG_ZERO],
1229 AC_REQUIRE([AC_PROG_CC])
1230 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1231 AC_CACHE_CHECK([whether printf supports the zero flag correctly],
1232 [gl_cv_func_printf_flag_zero],
1238 static char buf[100];
1239 static double zero = 0.0;
1242 if (sprintf (buf, "%010f", 1.0 / zero, 33, 44, 55) < 0
1243 || (strcmp (buf, " inf") != 0
1244 && strcmp (buf, " infinity") != 0))
1248 [gl_cv_func_printf_flag_zero=yes],
1249 [gl_cv_func_printf_flag_zero=no],
1253 # Guess yes on glibc systems.
1254 *-gnu* | gnu*) gl_cv_func_printf_flag_zero="guessing yes";;
1255 # Guess yes on musl systems.
1256 *-musl* | midipix*) gl_cv_func_printf_flag_zero="guessing yes";;
1257 # Guess yes on BeOS.
1258 beos*) gl_cv_func_printf_flag_zero="guessing yes";;
1259 # Guess no on Android.
1260 linux*-android*) gl_cv_func_printf_flag_zero="guessing no";;
1261 # Guess no on native Windows.
1262 mingw* | windows*) gl_cv_func_printf_flag_zero="guessing no";;
1263 # If we don't know, obey --enable-cross-guesses.
1264 *) gl_cv_func_printf_flag_zero="$gl_cross_guess_normal";;
1271 dnl Test whether the *printf family of functions supports the # flag with a
1272 dnl zero precision and a zero value in the 'x' and 'X' directives correctly.
1273 dnl ISO C and POSIX specify that for the 'd', 'i', 'b', 'o', 'u', 'x', 'X'
1274 dnl directives: "The result of converting a zero value with a precision of
1275 dnl zero is no characters." But on Mac OS X 10.5, for the 'x', 'X' directives,
1276 dnl when a # flag is present, the output is "0" instead of "".
1277 dnl Result is gl_cv_func_printf_flag_alt_precision_zero.
1279 AC_DEFUN([gl_PRINTF_FLAG_ALT_PRECISION_ZERO],
1281 AC_REQUIRE([AC_PROG_CC])
1282 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1283 AC_CACHE_CHECK([whether printf supports the alternative flag with a zero precision],
1284 [gl_cv_func_printf_flag_alt_precision_zero],
1289 static char buf[10];
1293 if (sprintf (buf, "%#.0x %d", 0, 33, 44) > 0 + 3)
1297 [gl_cv_func_printf_flag_alt_precision_zero=yes],
1298 [gl_cv_func_printf_flag_alt_precision_zero=no],
1302 # Guess no only on macOS 10..12 systems.
1303 darwin[0-9] | darwin[0-9].* | \
1304 darwin1[0-9] | darwin1[0-9].* | \
1305 darwin2[0-1] | darwin2[0-1].*)
1306 gl_cv_func_printf_flag_alt_precision_zero="guessing no" ;;
1307 darwin*) gl_cv_func_printf_flag_alt_precision_zero="guessing yes" ;;
1308 *) gl_cv_func_printf_flag_alt_precision_zero="guessing yes" ;;
1315 dnl Test whether the *printf family of functions supports large precisions.
1316 dnl On mingw, precisions larger than 512 are treated like 512, in integer,
1317 dnl floating-point or pointer output. On Solaris 10/x86, precisions larger
1318 dnl than 510 in floating-point output crash the program. On Solaris 10/SPARC,
1319 dnl precisions larger than 510 in floating-point output yield wrong results.
1320 dnl On AIX 7.1, precisions larger than 998 in floating-point output yield
1321 dnl wrong results. On BeOS, precisions larger than 1044 crash the program.
1322 dnl Result is gl_cv_func_printf_precision.
1324 AC_DEFUN([gl_PRINTF_PRECISION],
1326 AC_REQUIRE([AC_PROG_CC])
1327 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1328 AC_CACHE_CHECK([whether printf supports large precisions],
1329 [gl_cv_func_printf_precision],
1335 static char buf[5000];
1340 /* On BeOS, this would crash and show a dialog box. Avoid the crash. */
1343 if (sprintf (buf, "%.4000d %d", 1, 33, 44) < 4000 + 3)
1345 if (sprintf (buf, "%.4000f %d", 1.0, 33, 44) < 4000 + 5)
1347 if (sprintf (buf, "%.511f %d", 1.0, 33, 44) < 511 + 5
1350 if (sprintf (buf, "%.999f %d", 1.0, 33, 44) < 999 + 5
1355 [gl_cv_func_printf_precision=yes],
1356 [gl_cv_func_printf_precision=no],
1360 # Guess no only on Solaris, native Windows, and BeOS systems.
1361 solaris*) gl_cv_func_printf_precision="guessing no" ;;
1362 mingw* | windows* | pw*) gl_cv_func_printf_precision="guessing no" ;;
1363 beos*) gl_cv_func_printf_precision="guessing no" ;;
1364 # Guess yes on Android.
1365 linux*-android*) gl_cv_func_printf_precision="guessing yes" ;;
1366 *) gl_cv_func_printf_precision="guessing yes" ;;
1373 dnl Test whether the *printf family of functions recovers gracefully in case
1374 dnl of an out-of-memory condition, or whether it crashes the entire program.
1375 dnl Result is gl_cv_func_printf_enomem.
1377 AC_DEFUN([gl_PRINTF_ENOMEM],
1379 AC_REQUIRE([AC_PROG_CC])
1380 AC_REQUIRE([gl_MULTIARCH])
1381 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1382 AC_CACHE_CHECK([whether printf survives out-of-memory conditions],
1383 [gl_cv_func_printf_enomem],
1385 gl_cv_func_printf_enomem="guessing no"
1386 if test "$cross_compiling" = no; then
1387 if test $APPLE_UNIVERSAL_BUILD = 0; then
1388 AC_LANG_CONFTEST([AC_LANG_SOURCE([[
1391 #include <sys/types.h>
1392 #include <sys/time.h>
1393 #include <sys/resource.h>
1397 struct rlimit limit;
1400 /* Some printf implementations allocate temporary space with malloc. */
1401 /* On BSD systems, malloc() is limited by RLIMIT_DATA. */
1403 if (getrlimit (RLIMIT_DATA, &limit) < 0)
1405 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
1406 limit.rlim_max = 5000000;
1407 limit.rlim_cur = limit.rlim_max;
1408 if (setrlimit (RLIMIT_DATA, &limit) < 0)
1411 /* On Linux systems, malloc() is limited by RLIMIT_AS. */
1413 if (getrlimit (RLIMIT_AS, &limit) < 0)
1415 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
1416 limit.rlim_max = 5000000;
1417 limit.rlim_cur = limit.rlim_max;
1418 if (setrlimit (RLIMIT_AS, &limit) < 0)
1421 /* Some printf implementations allocate temporary space on the stack. */
1423 if (getrlimit (RLIMIT_STACK, &limit) < 0)
1425 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
1426 limit.rlim_max = 5000000;
1427 limit.rlim_cur = limit.rlim_max;
1428 if (setrlimit (RLIMIT_STACK, &limit) < 0)
1431 ret = printf ("%.5000000f", 1.0);
1432 return !(ret == 5000002 || (ret < 0 && errno == ENOMEM));
1435 if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
1436 (./conftest 2>&AS_MESSAGE_LOG_FD
1438 _AS_ECHO_LOG([\$? = $result])
1439 if test $result != 0 && test $result != 77; then result=1; fi
1441 ) >/dev/null 2>/dev/null
1443 0) gl_cv_func_printf_enomem="yes" ;;
1444 77) gl_cv_func_printf_enomem="guessing no" ;;
1445 *) gl_cv_func_printf_enomem="no" ;;
1448 gl_cv_func_printf_enomem="guessing no"
1452 dnl A universal build on Apple Mac OS X platforms.
1453 dnl The result would be 'no' in 32-bit mode and 'yes' in 64-bit mode.
1454 dnl But we need a configuration result that is valid in both modes.
1455 gl_cv_func_printf_enomem="guessing no"
1458 if test "$gl_cv_func_printf_enomem" = "guessing no"; then
1461 # Guess yes on glibc systems.
1462 *-gnu* | gnu*) gl_cv_func_printf_enomem="guessing yes";;
1463 # Guess yes on Solaris.
1464 solaris*) gl_cv_func_printf_enomem="guessing yes";;
1466 aix*) gl_cv_func_printf_enomem="guessing yes";;
1467 # Guess yes on HP-UX/hppa.
1468 hpux*) case "$host_cpu" in
1469 hppa*) gl_cv_func_printf_enomem="guessing yes";;
1470 *) gl_cv_func_printf_enomem="guessing no";;
1473 # Guess yes on IRIX.
1474 irix*) gl_cv_func_printf_enomem="guessing yes";;
1475 # Guess yes on OSF/1.
1476 osf*) gl_cv_func_printf_enomem="guessing yes";;
1477 # Guess yes on BeOS.
1478 beos*) gl_cv_func_printf_enomem="guessing yes";;
1479 # Guess yes on Haiku.
1480 haiku*) gl_cv_func_printf_enomem="guessing yes";;
1481 # Guess no on Android.
1482 linux*-android*) gl_cv_func_printf_enomem="guessing no";;
1483 # If we don't know, obey --enable-cross-guesses.
1484 *) gl_cv_func_printf_enomem="$gl_cross_guess_normal";;
1491 dnl Test whether the snprintf function exists. (ISO C99, POSIX:2001)
1492 dnl Result is ac_cv_func_snprintf.
1494 AC_DEFUN([gl_SNPRINTF_PRESENCE],
1496 AC_CHECK_FUNCS_ONCE([snprintf])
1499 dnl Test whether the string produced by the snprintf function is always NUL
1500 dnl terminated. (ISO C99, POSIX:2001)
1501 dnl Result is gl_cv_func_snprintf_truncation_c99.
1503 AC_DEFUN_ONCE([gl_SNPRINTF_TRUNCATION_C99],
1505 AC_REQUIRE([AC_PROG_CC])
1506 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1507 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1508 AC_CACHE_CHECK([whether snprintf truncates the result as in C99],
1509 [gl_cv_func_snprintf_truncation_c99],
1516 # define my_snprintf snprintf
1518 # include <stdarg.h>
1519 static int my_snprintf (char *buf, int size, const char *format, ...)
1523 va_start (args, format);
1524 ret = vsnprintf (buf, size, format, args);
1529 static char buf[100];
1532 strcpy (buf, "ABCDEF");
1533 my_snprintf (buf, 3, "%d %d", 4567, 89);
1534 if (memcmp (buf, "45\0DEF", 6) != 0)
1538 [gl_cv_func_snprintf_truncation_c99=yes],
1539 [gl_cv_func_snprintf_truncation_c99=no],
1543 # Guess yes on glibc systems.
1544 *-gnu* | gnu*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1545 # Guess yes on musl systems.
1546 *-musl* | midipix*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1547 # Guess yes on FreeBSD >= 5.
1548 freebsd[1-4].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1549 freebsd* | kfreebsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1550 midnightbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1551 # Guess yes on Mac OS X >= 10.3.
1552 darwin[1-6].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1553 darwin*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1554 # Guess yes on OpenBSD >= 3.9.
1555 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
1556 gl_cv_func_snprintf_truncation_c99="guessing no";;
1557 openbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1558 # Guess yes on Solaris >= 2.6.
1559 solaris2.[0-5] | solaris2.[0-5].*)
1560 gl_cv_func_snprintf_truncation_c99="guessing no";;
1561 solaris*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1562 # Guess yes on AIX >= 4.
1563 aix[1-3]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1564 aix*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1565 # Guess yes on HP-UX >= 11.
1566 hpux[7-9]* | hpux10*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1567 hpux*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1568 # Guess yes on IRIX >= 6.5.
1569 irix6.5) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1570 # Guess yes on OSF/1 >= 5.
1571 osf[3-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1572 osf*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1573 # Guess yes on NetBSD >= 3.
1574 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1575 gl_cv_func_snprintf_truncation_c99="guessing no";;
1576 netbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1577 # Guess yes on BeOS.
1578 beos*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1579 # Guess yes on Android.
1580 linux*-android*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1581 # Guess no on native Windows.
1582 mingw* | windows*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1583 # If we don't know, obey --enable-cross-guesses.
1584 *) gl_cv_func_snprintf_truncation_c99="$gl_cross_guess_normal";;
1591 dnl Test whether the return value of the snprintf function is the number
1592 dnl of bytes (excluding the terminating NUL) that would have been produced
1593 dnl if the buffer had been large enough. (ISO C99, POSIX:2001)
1594 dnl For example, this test program fails on IRIX 6.5:
1595 dnl ---------------------------------------------------------------------
1596 dnl #include <stdio.h>
1599 dnl static char buf[8];
1600 dnl int retval = snprintf (buf, 3, "%d", 12345);
1601 dnl return retval >= 0 && retval < 3;
1603 dnl ---------------------------------------------------------------------
1604 dnl Result is gl_cv_func_snprintf_retval_c99.
1606 AC_DEFUN_ONCE([gl_SNPRINTF_RETVAL_C99],
1608 AC_REQUIRE([AC_PROG_CC])
1609 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1610 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1611 AC_CACHE_CHECK([whether snprintf returns a byte count as in C99],
1612 [gl_cv_func_snprintf_retval_c99],
1619 # define my_snprintf snprintf
1621 # include <stdarg.h>
1622 static int my_snprintf (char *buf, int size, const char *format, ...)
1626 va_start (args, format);
1627 ret = vsnprintf (buf, size, format, args);
1632 static char buf[100];
1635 strcpy (buf, "ABCDEF");
1636 if (my_snprintf (buf, 3, "%d %d", 4567, 89) != 7)
1638 if (my_snprintf (buf, 0, "%d %d", 4567, 89) != 7)
1640 if (my_snprintf (NULL, 0, "%d %d", 4567, 89) != 7)
1644 [gl_cv_func_snprintf_retval_c99=yes],
1645 [gl_cv_func_snprintf_retval_c99=no],
1648 # Guess yes on glibc systems.
1649 *-gnu* | gnu*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1650 # Guess yes on musl systems.
1651 *-musl* | midipix*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1652 # Guess yes on FreeBSD >= 5.
1653 freebsd[1-4].*) gl_cv_func_snprintf_retval_c99="guessing no";;
1654 freebsd* | kfreebsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1655 midnightbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1656 # Guess yes on Mac OS X >= 10.3.
1657 darwin[1-6].*) gl_cv_func_snprintf_retval_c99="guessing no";;
1658 darwin*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1659 # Guess yes on OpenBSD >= 3.9.
1660 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
1661 gl_cv_func_snprintf_retval_c99="guessing no";;
1662 openbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1663 # Guess yes on Solaris >= 2.10.
1664 solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";;
1665 solaris*) gl_cv_func_printf_sizes_c99="guessing no";;
1666 # Guess yes on AIX >= 4.
1667 aix[1-3]*) gl_cv_func_snprintf_retval_c99="guessing no";;
1668 aix*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1669 # Guess yes on NetBSD >= 3.
1670 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1671 gl_cv_func_snprintf_retval_c99="guessing no";;
1672 netbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1673 # Guess yes on BeOS.
1674 beos*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1675 # Guess yes on Android.
1676 linux*-android*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1678 # Guess yes on MSVC, no on mingw.
1679 windows*-msvc*) gl_cv_func_snprintf_retval_c99="guessing yes" ;;
1680 mingw* | windows*) AC_EGREP_CPP([Known], [
1685 [gl_cv_func_snprintf_retval_c99="guessing yes"],
1686 [gl_cv_func_snprintf_retval_c99="guessing no"])
1688 # If we don't know, obey --enable-cross-guesses.
1689 *) gl_cv_func_snprintf_retval_c99="$gl_cross_guess_normal";;
1695 dnl Test whether the snprintf function supports the %n format directive
1696 dnl also in truncated portions of the format string. (ISO C99, POSIX:2001)
1697 dnl Result is gl_cv_func_snprintf_directive_n.
1699 AC_DEFUN([gl_SNPRINTF_DIRECTIVE_N],
1701 AC_REQUIRE([AC_PROG_CC])
1702 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1703 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1704 AC_CACHE_CHECK([whether snprintf fully supports the 'n' directive],
1705 [gl_cv_func_snprintf_directive_n],
1713 # define my_snprintf snprintf
1715 # include <stdarg.h>
1716 static int my_snprintf (char *buf, int size, const char *format, ...)
1720 va_start (args, format);
1721 ret = vsnprintf (buf, size, format, args);
1727 abort_handler (int sig)
1732 static char fmtstring[10];
1733 static char buf[100];
1737 signal (SIGABRT, abort_handler);
1738 /* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2)
1739 support %n in format strings in read-only memory but not in writable
1741 strcpy (fmtstring, "%d %n");
1742 my_snprintf (buf, 4, fmtstring, 12345, &count, 33, 44, 55);
1747 [gl_cv_func_snprintf_directive_n=yes],
1748 [gl_cv_func_snprintf_directive_n=no],
1751 # Guess no on glibc when _FORTIFY_SOURCE >= 2.
1752 *-gnu* | gnu*) AC_COMPILE_IFELSE(
1754 [[#if _FORTIFY_SOURCE >= 2
1758 [gl_cv_func_snprintf_directive_n="guessing yes"],
1759 [gl_cv_func_snprintf_directive_n="guessing no"])
1762 # Guess yes on musl systems.
1763 *-musl* | midipix*) gl_cv_func_snprintf_directive_n="guessing yes";;
1764 # Guess yes on FreeBSD >= 5.
1765 freebsd[1-4].*) gl_cv_func_snprintf_directive_n="guessing no";;
1766 freebsd* | kfreebsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
1767 midnightbsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
1768 # Guess yes on Mac OS X >= 10.3.
1769 darwin[1-6].*) gl_cv_func_snprintf_directive_n="guessing no";;
1770 darwin*) gl_cv_func_snprintf_directive_n="guessing yes";;
1771 # Guess yes on Solaris >= 2.6.
1772 solaris2.[0-5] | solaris2.[0-5].*)
1773 gl_cv_func_snprintf_directive_n="guessing no";;
1774 solaris*) gl_cv_func_snprintf_directive_n="guessing yes";;
1775 # Guess yes on AIX >= 4.
1776 aix[1-3]*) gl_cv_func_snprintf_directive_n="guessing no";;
1777 aix*) gl_cv_func_snprintf_directive_n="guessing yes";;
1778 # Guess yes on IRIX >= 6.5.
1779 irix6.5) gl_cv_func_snprintf_directive_n="guessing yes";;
1780 # Guess yes on OSF/1 >= 5.
1781 osf[3-4]*) gl_cv_func_snprintf_directive_n="guessing no";;
1782 osf*) gl_cv_func_snprintf_directive_n="guessing yes";;
1783 # Guess yes on NetBSD >= 3.
1784 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1785 gl_cv_func_snprintf_directive_n="guessing no";;
1786 netbsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
1787 # Guess yes on BeOS.
1788 beos*) gl_cv_func_snprintf_directive_n="guessing yes";;
1789 # Guess no on Android.
1790 linux*-android*) gl_cv_func_snprintf_directive_n="guessing no";;
1791 # Guess no on native Windows.
1792 mingw* | windows*) gl_cv_func_snprintf_directive_n="guessing no";;
1793 # If we don't know, obey --enable-cross-guesses.
1794 *) gl_cv_func_snprintf_directive_n="$gl_cross_guess_normal";;
1801 dnl Test whether the snprintf function, when passed a size = 1, writes any
1802 dnl output without bounds in this case, behaving like sprintf. This is the
1803 dnl case on Linux libc5.
1804 dnl Result is gl_cv_func_snprintf_size1.
1806 AC_DEFUN([gl_SNPRINTF_SIZE1],
1808 AC_REQUIRE([AC_PROG_CC])
1809 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1810 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1811 AC_CACHE_CHECK([whether snprintf respects a size of 1],
1812 [gl_cv_func_snprintf_size1],
1818 # define my_snprintf snprintf
1820 # include <stdarg.h>
1821 static int my_snprintf (char *buf, int size, const char *format, ...)
1825 va_start (args, format);
1826 ret = vsnprintf (buf, size, format, args);
1833 static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1834 my_snprintf (buf, 1, "%d", 12345);
1835 return buf[1] != 'E';
1837 [gl_cv_func_snprintf_size1=yes],
1838 [gl_cv_func_snprintf_size1=no],
1840 # Guess yes on Android.
1841 linux*-android*) gl_cv_func_snprintf_size1="guessing yes" ;;
1842 # Guess yes on native Windows.
1843 mingw* | windows*) gl_cv_func_snprintf_size1="guessing yes" ;;
1844 *) gl_cv_func_snprintf_size1="guessing yes" ;;
1850 dnl Test whether the vsnprintf function, when passed a zero size, produces no
1851 dnl output. (ISO C99, POSIX:2001)
1852 dnl For example, snprintf nevertheless writes a NUL byte in this case
1854 dnl ---------------------------------------------------------------------
1855 dnl #include <stdio.h>
1858 dnl static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1859 dnl snprintf (buf, 0, "%d", 12345);
1860 dnl return buf[0] != 'D';
1862 dnl ---------------------------------------------------------------------
1863 dnl And vsnprintf writes any output without bounds in this case, behaving like
1864 dnl vsprintf, on HP-UX 11 and OSF/1 5.1:
1865 dnl ---------------------------------------------------------------------
1866 dnl #include <stdarg.h>
1867 dnl #include <stdio.h>
1868 dnl static int my_snprintf (char *buf, int size, const char *format, ...)
1872 dnl va_start (args, format);
1873 dnl ret = vsnprintf (buf, size, format, args);
1879 dnl static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1880 dnl my_snprintf (buf, 0, "%d", 12345);
1881 dnl return buf[0] != 'D';
1883 dnl ---------------------------------------------------------------------
1884 dnl Result is gl_cv_func_vsnprintf_zerosize_c99.
1886 AC_DEFUN([gl_VSNPRINTF_ZEROSIZE_C99],
1888 AC_REQUIRE([AC_PROG_CC])
1889 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1890 AC_CACHE_CHECK([whether vsnprintf respects a zero size as in C99],
1891 [gl_cv_func_vsnprintf_zerosize_c99],
1897 static int my_snprintf (char *buf, int size, const char *format, ...)
1901 va_start (args, format);
1902 ret = vsnprintf (buf, size, format, args);
1908 static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1909 my_snprintf (buf, 0, "%d", 12345);
1910 return buf[0] != 'D';
1912 [gl_cv_func_vsnprintf_zerosize_c99=yes],
1913 [gl_cv_func_vsnprintf_zerosize_c99=no],
1917 # Guess yes on glibc systems.
1918 *-gnu* | gnu*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1919 # Guess yes on musl systems.
1920 *-musl* | midipix*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1921 # Guess yes on FreeBSD >= 5.
1922 freebsd[1-4].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1923 freebsd* | kfreebsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1924 midnightbsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1925 # Guess yes on Mac OS X >= 10.3.
1926 darwin[1-6].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1927 darwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1928 # Guess yes on Cygwin.
1929 cygwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1930 # Guess yes on Solaris >= 2.6.
1931 solaris2.[0-5] | solaris2.[0-5].*)
1932 gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1933 solaris*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1934 # Guess yes on AIX >= 4.
1935 aix[1-3]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1936 aix*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1937 # Guess yes on IRIX >= 6.5.
1938 irix6.5) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1939 # Guess yes on NetBSD >= 3.
1940 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1941 gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1942 netbsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1943 # Guess yes on BeOS.
1944 beos*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1945 # Guess yes on Android.
1946 linux*-android*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1947 # Guess yes on native Windows.
1948 mingw* | windows* | pw*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1949 # If we don't know, obey --enable-cross-guesses.
1950 *) gl_cv_func_vsnprintf_zerosize_c99="$gl_cross_guess_normal";;
1957 dnl Test whether the swprintf function works correctly when it produces output
1958 dnl that contains null wide characters.
1959 dnl Result is gl_cv_func_swprintf_works.
1961 AC_DEFUN([gl_SWPRINTF_WORKS],
1963 AC_REQUIRE([AC_PROG_CC])
1964 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1965 AC_CHECK_FUNCS_ONCE([swprintf])
1966 AC_CACHE_CHECK([whether swprintf works],
1967 [gl_cv_func_swprintf_works],
1971 #ifndef __USE_MINGW_ANSI_STDIO
1972 # define __USE_MINGW_ANSI_STDIO 1
1979 { /* This test fails on musl libc 1.2.3, FreeBSD, NetBSD, OpenBSD, macOS, AIX. */
1980 wchar_t buf[5] = { 0xBEEF, 0xBEEF, 0xBEEF, 0xBEEF, 0xBEEF };
1981 int ret = swprintf (buf, 4, L"%cz", '\0');
1983 ret = 2, buf[0] = 0x0, buf[1] = 0x7a, buf[2] = 0x0, buf[3] = 0xbeef
1985 ret = 2, buf[0] = 0x0, buf[1] = 0x0, buf[2] = 0x0, buf[3] = 0x0
1986 Reported at <https://www.openwall.com/lists/musl/2023/03/22/9>.
1987 FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2, macOS 12.5, AIX 7.2:
1988 ret = 2, buf[0] = 0x0, buf[1] = 0xbeef, buf[2] = 0xbeef, buf[3] = 0xbeef
1990 if (ret < 0 || buf[1] != 'z')
1993 { /* This test fails on mingw. */
1995 int ret = swprintf (buf, 2, L"%lc", (wint_t)0);
1996 /* Expected: ret = 1
2004 [gl_cv_func_swprintf_works=yes],
2005 [gl_cv_func_swprintf_works=no],
2007 # Guess yes on glibc systems.
2008 *-gnu* | gnu*) gl_cv_func_swprintf_works="guessing yes";;
2009 # Guess no on musl systems.
2010 *-musl* | midipix*) gl_cv_func_swprintf_works="guessing no";;
2011 # Guess no on FreeBSD, NetBSD, OpenBSD, macOS, AIX.
2012 freebsd* | midnightbsd* | netbsd* | openbsd* | darwin* | aix*)
2013 gl_cv_func_swprintf_works="guessing no";;
2014 # Guess no on native Windows.
2015 mingw* | windows* | pw*) gl_cv_func_swprintf_works="guessing no";;
2016 # If we don't know, obey --enable-cross-guesses.
2017 *) gl_cv_func_swprintf_works="$gl_cross_guess_normal";;
2023 dnl Test whether the *wprintf family of functions supports the 'a' and 'A'
2024 dnl conversion specifier for hexadecimal output of 'long double' numbers.
2025 dnl (ISO C99, POSIX:2001)
2026 dnl Result is gl_cv_func_swprintf_directive_la.
2028 AC_DEFUN([gl_SWPRINTF_DIRECTIVE_LA],
2030 AC_REQUIRE([AC_PROG_CC])
2031 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
2032 AC_CACHE_CHECK([whether swprintf supports the 'La' and 'LA' directives],
2033 [gl_cv_func_swprintf_directive_la],
2039 static wchar_t buf[100];
2043 /* This catches a glibc 2.15, Haiku 2022, NetBSD 10.0 bug. */
2044 if (swprintf (buf, sizeof (buf) / sizeof (wchar_t),
2045 L"%La %d", 3.1416015625L, 33, 44, 55) < 0
2046 || (wcscmp (buf, L"0x1.922p+1 33") != 0
2047 && wcscmp (buf, L"0x3.244p+0 33") != 0
2048 && wcscmp (buf, L"0x6.488p-1 33") != 0
2049 && wcscmp (buf, L"0xc.91p-2 33") != 0))
2053 [gl_cv_func_swprintf_directive_la=yes],
2054 [gl_cv_func_swprintf_directive_la=no],
2056 # Guess yes on glibc >= 2.17 systems.
2058 AC_EGREP_CPP([Unlucky], [
2059 #include <features.h>
2060 #ifdef __GNU_LIBRARY__
2061 #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 16) || (__GLIBC__ > 2)) && !defined __UCLIBC__
2066 [gl_cv_func_swprintf_directive_la="guessing yes"],
2067 [gl_cv_func_swprintf_directive_la="guessing no"])
2069 # Guess yes on musl systems.
2070 *-musl* | midipix*) gl_cv_func_swprintf_directive_la="guessing yes";;
2071 # Guess yes on Android.
2072 linux*-android*) gl_cv_func_swprintf_directive_la="guessing yes";;
2073 # Guess no on NetBSD.
2074 netbsd*) gl_cv_func_swprintf_directive_la="guessing no";;
2075 # Guess no on native Windows.
2076 mingw* | windows*) gl_cv_func_swprintf_directive_la="guessing no";;
2077 # If we don't know, obey --enable-cross-guesses.
2078 *) gl_cv_func_swprintf_directive_la="$gl_cross_guess_normal";;
2084 dnl Test whether the *wprintf family of functions supports the 'lc' conversion
2085 dnl specifier for all wide characters.
2086 dnl (ISO C11, POSIX:2001)
2087 dnl Result is gl_cv_func_swprintf_directive_lc.
2089 AC_DEFUN([gl_SWPRINTF_DIRECTIVE_LC],
2091 AC_REQUIRE([AC_PROG_CC])
2092 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
2093 AC_CACHE_CHECK([whether swprintf supports the 'lc' directive],
2094 [gl_cv_func_swprintf_directive_lc],
2100 static wchar_t buf[100];
2101 static wint_t L_invalid = (wchar_t) 0x76543210;
2105 /* This catches a musl libc 1.2.4, Android bug.
2106 Reported at <https://www.openwall.com/lists/musl/2023/06/12/3>. */
2107 if (swprintf (buf, sizeof (buf) / sizeof (wchar_t),
2108 L"%lc %d", L_invalid, 33, 44, 55) < 0)
2112 [gl_cv_func_swprintf_directive_lc=yes],
2113 [gl_cv_func_swprintf_directive_lc=no],
2115 # Guess yes on glibc systems.
2116 *-gnu* | gnu*) gl_cv_func_swprintf_directive_lc="guessing yes";;
2117 # Guess no on musl systems.
2118 *-musl* | midipix*) gl_cv_func_swprintf_directive_lc="guessing no";;
2119 # Guess no on Android.
2120 linux*-android*) gl_cv_func_swprintf_directive_lc="guessing no";;
2121 # Guess yes on native Windows.
2122 mingw* | windows*) gl_cv_func_swprintf_directive_lc="guessing yes";;
2123 # If we don't know, obey --enable-cross-guesses.
2124 *) gl_cv_func_swprintf_directive_lc="$gl_cross_guess_normal";;
2130 dnl The results of these tests on various platforms are:
2132 dnl 1 = gl_PRINTF_SIZES_C99
2133 dnl 2 = gl_PRINTF_SIZES_C23
2134 dnl 3 = gl_PRINTF_LONG_DOUBLE
2135 dnl 4 = gl_PRINTF_INFINITE
2136 dnl 5 = gl_PRINTF_INFINITE_LONG_DOUBLE
2137 dnl 6 = gl_PRINTF_DIRECTIVE_A
2138 dnl 7 = gl_PRINTF_DIRECTIVE_B
2139 dnl 8 = gl_PRINTF_DIRECTIVE_UPPERCASE_B
2140 dnl 9 = gl_PRINTF_DIRECTIVE_F
2141 dnl 10 = gl_PRINTF_DIRECTIVE_N
2142 dnl 11 = gl_PRINTF_DIRECTIVE_LS
2143 dnl 12 = gl_PRINTF_DIRECTIVE_LC
2144 dnl 13 = gl_PRINTF_POSITIONS
2145 dnl 14 = gl_PRINTF_FLAG_GROUPING
2146 dnl 15 = gl_PRINTF_FLAG_LEFTADJUST
2147 dnl 16 = gl_PRINTF_FLAG_ZERO
2148 dnl 17 = gl_PRINTF_FLAG_ALT_PRECISION_ZERO
2149 dnl 18 = gl_PRINTF_PRECISION
2150 dnl 19 = gl_PRINTF_ENOMEM
2151 dnl 20 = gl_SNPRINTF_PRESENCE
2152 dnl 21 = gl_SNPRINTF_TRUNCATION_C99
2153 dnl 22 = gl_SNPRINTF_RETVAL_C99
2154 dnl 23 = gl_SNPRINTF_DIRECTIVE_N
2155 dnl 24 = gl_SNPRINTF_SIZE1
2156 dnl 25 = gl_VSNPRINTF_ZEROSIZE_C99
2157 dnl 26 = gl_SWPRINTF_WORKS
2158 dnl 27 = gl_SWPRINTF_DIRECTIVE_LA
2159 dnl 28 = gl_SWPRINTF_DIRECTIVE_LC
2161 dnl 1 = checking whether printf supports size specifiers as in C99...
2162 dnl 2 = checking whether printf supports size specifiers as in C23...
2163 dnl 3 = checking whether printf supports 'long double' arguments...
2164 dnl 4 = checking whether printf supports infinite 'double' arguments...
2165 dnl 5 = checking whether printf supports infinite 'long double' arguments...
2166 dnl 6 = checking whether printf supports the 'a' and 'A' directives...
2167 dnl 7 = checking whether printf supports the 'b' directive...
2168 dnl 8 = checking whether printf supports the 'B' directive...
2169 dnl 9 = checking whether printf supports the 'F' directive...
2170 dnl 10 = checking whether printf supports the 'n' directive...
2171 dnl 11 = checking whether printf supports the 'ls' directive...
2172 dnl 12 = checking whether printf supports the 'lc' directive correctly...
2173 dnl 13 = checking whether printf supports POSIX/XSI format strings with positions...
2174 dnl 14 = checking whether printf supports the grouping flag...
2175 dnl 15 = checking whether printf supports the left-adjust flag correctly...
2176 dnl 16 = checking whether printf supports the zero flag correctly...
2177 dnl 17 = checking whether printf supports the alternative flag with a zero precision...
2178 dnl 18 = checking whether printf supports large precisions...
2179 dnl 19 = checking whether printf survives out-of-memory conditions...
2180 dnl 20 = checking for snprintf...
2181 dnl 21 = checking whether snprintf truncates the result as in C99...
2182 dnl 22 = checking whether snprintf returns a byte count as in C99...
2183 dnl 23 = checking whether snprintf fully supports the 'n' directive...
2184 dnl 24 = checking whether snprintf respects a size of 1...
2185 dnl 25 = checking whether vsnprintf respects a zero size as in C99...
2186 dnl 26 = checking whether swprintf works...
2187 dnl 27 = checking whether swprintf supports the 'La' and 'LA' directives...
2188 dnl 28 = checking whether swprintf supports the 'lc' directive...
2190 dnl . = yes, # = no.
2192 dnl 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
2193 dnl musl libc 1.2.3 . # . . . . # # . . . # . . . . ? . . . . . . . . # . #
2194 dnl glibc 2.35 . # . . . . . . . . . . . . . . . . . . . . . . . . . .
2195 dnl glibc 2.5 . # . . . . # # . . . . . . . . . . . . . . . . . . # .
2196 dnl glibc 2.3.6 . # . . . # # # . . . . . . . . . . . . . . . . . . # .
2197 dnl FreeBSD 14.0 . . . . . # . . . . . . . . . . . . # . . . . . . # . #
2198 dnl FreeBSD 13.0 . # . . . # # # . . . . . . . . . . # . . . . . . # . #
2199 dnl FreeBSD 5.4, 6.1 . # . . . # # # . . . . . . . # ? . # . . . . . . # ? ?
2200 dnl Mac OS X 10.13.5 . # . . # # # # . # . . . . . . . . . . . . # . . # ? ?
2201 dnl Mac OS X 10.5.8 . # . . # # # # . . . . . . . # # . . . . . . . . # ? ?
2202 dnl Mac OS X 10.3.9 . # . . . # # # . . . . . . . # # . # . . . . . . # ? ?
2203 dnl OpenBSD 6.0, 6.7 . # . . . # # # . . . . . . . . . . # . . . . . . # . #
2204 dnl OpenBSD 3.9, 4.0 . # . # # # # # # . # . . # . # ? . # . . . . . . # ? ?
2205 dnl Cygwin 1.7.0 (2009) . # . . # . # # . . ? ? . . . . ? . ? . . . . . . ? ? ?
2206 dnl Cygwin 1.5.25 (2008) . # . . # # # # . . # ? . . . . ? . # . . . . . . ? ? ?
2207 dnl Cygwin 1.5.19 (2006) # # . . # # # # # . # ? . # . # ? # # . . . . . . ? ? ?
2208 dnl Solaris 11.4 . # . # # # # # . . # . . . . # . . . . . . . . . . # .
2209 dnl Solaris 11.3 . # . . . # # # . . # . . . . . . . . . . . . . . . # .
2210 dnl Solaris 11.0 . # . # # # # # . . # . . . . # . . . . . . . . . ? ? ?
2211 dnl Solaris 10 . # . # # # # # . . # . . . . # . # . . . . . . . . # .
2212 dnl Solaris 2.6 ... 9 # # . # # # # # # . # . . . . # ? # . . . # . . . ? ? ?
2213 dnl Solaris 2.5.1 # # . # # # # # # . # . . . . # ? . . # # # # # # ? ? ?
2214 dnl AIX 7.1 . # . # # # # # . . . . . . . # . # . . . . . . . # . .
2215 dnl AIX 5.2 . # . # # # # # . . . . . . . # ? . . . . . . . . # ? ?
2216 dnl AIX 4.3.2, 5.1 # # . # # # # # # . . . . . . # ? . . . . # . . . # ? ?
2217 dnl HP-UX 11.31 . # . . . # # # . . . ? . . . # ? . . . . # # . . ? ? ?
2218 dnl HP-UX 11.{00,11,23} # # . . . # # # # . . ? . . . # ? . . . . # # . # ? ? ?
2219 dnl HP-UX 10.20 # # . # . # # # # . ? ? . . # # ? . . . . # # ? # ? ? ?
2220 dnl IRIX 6.5 # # . # # # # # # . # . . . . # ? . . . . # . . . # ? ?
2221 dnl OSF/1 5.1 # # . # # # # # # . . ? . . . # ? . . . . # . . # ? ? ?
2222 dnl OSF/1 4.0d # # . # # # # # # . . ? . . . # ? . . # # # # # # ? ? ?
2223 dnl NetBSD 9.0 . # . . . # # # . . . . . . . . . . . . . . . . . # . #
2224 dnl NetBSD 5.0 . # . . # # # # . . . . . . . # ? . # . . . . . . # ? ?
2225 dnl NetBSD 4.0 . # ? ? ? ? # # ? . ? . . ? ? ? ? ? ? . . . ? ? ? # ? ?
2226 dnl NetBSD 3.0 . # . . . # # # # . ? . # # ? # ? . # . . . . . . # ? ?
2227 dnl Haiku . # . . # # # # # . # ? . . . . ? . ? . . ? . . . . # .
2228 dnl BeOS # # # . # # # # # . ? ? # . ? . ? # ? . . ? . . . ? ? ?
2229 dnl Android 4.3 . # . # # # # # # # # ? . # . # ? . # . . . # . . ? ? ?
2230 dnl old mingw / msvcrt # # # # # # # # # . . ? # # . # ? # ? . # # # . . # ? ?
2231 dnl MSVC 9 # # # # # # # # # # . ? # # . # ? # ? # # # # . . # ? ?
2232 dnl mingw 2009-2011 . # # . # . # # . . . ? # # . . ? . ? . . . . . . # ? ?
2233 dnl mingw-w64 2011 # # # # # # # # # . . ? # # . # ? # ? . # # # . . # ? ?