2 dnl Copyright (C) 2003, 2007-2020 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 dnl Test whether the *printf family of functions supports the 'j', 'z', 't',
8 dnl 'L' size specifiers. (ISO C99, POSIX:2001)
9 dnl Result is gl_cv_func_printf_sizes_c99.
11 AC_DEFUN([gl_PRINTF_SIZES_C99],
13 AC_REQUIRE([AC_PROG_CC])
14 AC_REQUIRE([gl_AC_HEADER_STDINT_H])
15 AC_REQUIRE([gl_AC_HEADER_INTTYPES_H])
16 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
17 AC_CACHE_CHECK([whether printf supports size specifiers as in C99],
18 [gl_cv_func_printf_sizes_c99],
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 musl systems.
66 *-musl*) gl_cv_func_printf_sizes_c99="guessing yes";;
67 # Guess yes on FreeBSD >= 5.
68 freebsd[1-4].*) gl_cv_func_printf_sizes_c99="guessing no";;
69 freebsd* | kfreebsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
70 # Guess yes on Mac OS X >= 10.3.
71 darwin[1-6].*) gl_cv_func_printf_sizes_c99="guessing no";;
72 darwin*) gl_cv_func_printf_sizes_c99="guessing yes";;
73 # Guess yes on OpenBSD >= 3.9.
74 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
75 gl_cv_func_printf_sizes_c99="guessing no";;
76 openbsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
77 # Guess yes on Solaris >= 2.10.
78 solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";;
79 solaris*) gl_cv_func_printf_sizes_c99="guessing no";;
80 # Guess yes on NetBSD >= 3.
81 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
82 gl_cv_func_printf_sizes_c99="guessing no";;
83 netbsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
84 # Guess yes on Android.
85 linux*-android*) gl_cv_func_printf_sizes_c99="guessing yes";;
87 # Guess yes on MSVC, no on mingw.
88 mingw*) AC_EGREP_CPP([Known], [
93 [gl_cv_func_printf_sizes_c99="guessing yes"],
94 [gl_cv_func_printf_sizes_c99="guessing no"])
96 # If we don't know, obey --enable-cross-guesses.
97 *) gl_cv_func_printf_sizes_c99="$gl_cross_guess_normal";;
103 dnl Test whether the *printf family of functions supports 'long double'
104 dnl arguments together with the 'L' size specifier. (ISO C99, POSIX:2001)
105 dnl Result is gl_cv_func_printf_long_double.
107 AC_DEFUN([gl_PRINTF_LONG_DOUBLE],
109 AC_REQUIRE([AC_PROG_CC])
110 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
111 AC_CACHE_CHECK([whether printf supports 'long double' arguments],
112 [gl_cv_func_printf_long_double],
118 static char buf[10000];
123 if (sprintf (buf, "%Lf %d", 1.75L, 33, 44, 55) < 0
124 || strcmp (buf, "1.750000 33") != 0)
127 if (sprintf (buf, "%Le %d", 1.75L, 33, 44, 55) < 0
128 || strcmp (buf, "1.750000e+00 33") != 0)
131 if (sprintf (buf, "%Lg %d", 1.75L, 33, 44, 55) < 0
132 || strcmp (buf, "1.75 33") != 0)
136 [gl_cv_func_printf_long_double=yes],
137 [gl_cv_func_printf_long_double=no],
140 beos*) gl_cv_func_printf_long_double="guessing no";;
141 # Guess yes on Android.
142 linux*-android*) gl_cv_func_printf_long_double="guessing yes";;
143 # Guess yes on MSVC, no on mingw.
144 mingw*) AC_EGREP_CPP([Known], [
149 [gl_cv_func_printf_long_double="guessing yes"],
150 [gl_cv_func_printf_long_double="guessing no"])
152 *) gl_cv_func_printf_long_double="guessing yes";;
158 dnl Test whether the *printf family of functions supports infinite and NaN
159 dnl 'double' arguments and negative zero arguments in the %f, %e, %g
160 dnl directives. (ISO C99, POSIX:2001)
161 dnl Result is gl_cv_func_printf_infinite.
163 AC_DEFUN([gl_PRINTF_INFINITE],
165 AC_REQUIRE([AC_PROG_CC])
166 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
167 AC_CACHE_CHECK([whether printf supports infinite 'double' arguments],
168 [gl_cv_func_printf_infinite],
175 strisnan (const char *string, size_t start_index, size_t end_index)
177 if (start_index < end_index)
179 if (string[start_index] == '-')
181 if (start_index + 3 <= end_index
182 && memcmp (string + start_index, "nan", 3) == 0)
185 if (start_index == end_index
186 || (string[start_index] == '(' && string[end_index - 1] == ')'))
195 static double plus_zero = 0.0;
196 double minus_zero = - plus_zero;
197 return memcmp (&plus_zero, &minus_zero, sizeof (double)) != 0;
199 static char buf[10000];
200 static double zero = 0.0;
204 if (sprintf (buf, "%f", 1.0 / zero) < 0
205 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
207 if (sprintf (buf, "%f", -1.0 / zero) < 0
208 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
210 if (sprintf (buf, "%f", zero / zero) < 0
211 || !strisnan (buf, 0, strlen (buf)))
213 if (sprintf (buf, "%e", 1.0 / zero) < 0
214 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
216 if (sprintf (buf, "%e", -1.0 / zero) < 0
217 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
219 if (sprintf (buf, "%e", zero / zero) < 0
220 || !strisnan (buf, 0, strlen (buf)))
222 if (sprintf (buf, "%g", 1.0 / zero) < 0
223 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
225 if (sprintf (buf, "%g", -1.0 / zero) < 0
226 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
228 if (sprintf (buf, "%g", zero / zero) < 0
229 || !strisnan (buf, 0, strlen (buf)))
231 /* This test fails on HP-UX 10.20. */
232 if (have_minus_zero ())
233 if (sprintf (buf, "%g", - zero) < 0
234 || strcmp (buf, "-0") != 0)
238 [gl_cv_func_printf_infinite=yes],
239 [gl_cv_func_printf_infinite=no],
243 # Guess yes on glibc systems.
244 *-gnu* | gnu*) gl_cv_func_printf_infinite="guessing yes";;
245 # Guess yes on musl systems.
246 *-musl*) gl_cv_func_printf_infinite="guessing yes";;
247 # Guess yes on FreeBSD >= 6.
248 freebsd[1-5].*) gl_cv_func_printf_infinite="guessing no";;
249 freebsd* | kfreebsd*) gl_cv_func_printf_infinite="guessing yes";;
250 # Guess yes on Mac OS X >= 10.3.
251 darwin[1-6].*) gl_cv_func_printf_infinite="guessing no";;
252 darwin*) gl_cv_func_printf_infinite="guessing yes";;
253 # Guess yes on HP-UX >= 11.
254 hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite="guessing no";;
255 hpux*) gl_cv_func_printf_infinite="guessing yes";;
256 # Guess yes on NetBSD >= 3.
257 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
258 gl_cv_func_printf_infinite="guessing no";;
259 netbsd*) gl_cv_func_printf_infinite="guessing yes";;
260 # Guess yes on OpenBSD >= 6.0.
261 openbsd[1-5].*) gl_cv_func_printf_infinite="guessing no";;
262 openbsd*) gl_cv_func_printf_infinite="guessing yes";;
264 beos*) gl_cv_func_printf_infinite="guessing yes";;
265 # Guess no on Android.
266 linux*-android*) gl_cv_func_printf_infinite="guessing no";;
268 # Guess yes on MSVC, no on mingw.
269 mingw*) AC_EGREP_CPP([Known], [
274 [gl_cv_func_printf_infinite="guessing yes"],
275 [gl_cv_func_printf_infinite="guessing no"])
277 # If we don't know, obey --enable-cross-guesses.
278 *) gl_cv_func_printf_infinite="$gl_cross_guess_normal";;
284 dnl Test whether the *printf family of functions supports infinite and NaN
285 dnl 'long double' arguments in the %f, %e, %g directives. (ISO C99, POSIX:2001)
286 dnl Result is gl_cv_func_printf_infinite_long_double.
288 AC_DEFUN([gl_PRINTF_INFINITE_LONG_DOUBLE],
290 AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
291 AC_REQUIRE([AC_PROG_CC])
292 AC_REQUIRE([gl_BIGENDIAN])
293 AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
294 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
295 dnl The user can set or unset the variable gl_printf_safe to indicate
296 dnl that he wishes a safe handling of non-IEEE-754 'long double' values.
297 if test -n "$gl_printf_safe"; then
298 AC_DEFINE([CHECK_PRINTF_SAFE], [1],
299 [Define if you wish *printf() functions that have a safe handling of
300 non-IEEE-754 'long double' values.])
302 case "$gl_cv_func_printf_long_double" in
304 AC_CACHE_CHECK([whether printf supports infinite 'long double' arguments],
305 [gl_cv_func_printf_infinite_long_double],
314 strisnan (const char *string, size_t start_index, size_t end_index)
316 if (start_index < end_index)
318 if (string[start_index] == '-')
320 if (start_index + 3 <= end_index
321 && memcmp (string + start_index, "nan", 3) == 0)
324 if (start_index == end_index
325 || (string[start_index] == '(' && string[end_index - 1] == ')'))
331 static char buf[10000];
332 static long double zeroL = 0.0L;
337 if (sprintf (buf, "%Lf", 1.0L / zeroL) < 0
338 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
340 if (sprintf (buf, "%Lf", -1.0L / zeroL) < 0
341 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
343 if (sprintf (buf, "%Lf", zeroL / zeroL) < 0
344 || !strisnan (buf, 0, strlen (buf)))
346 if (sprintf (buf, "%Le", 1.0L / zeroL) < 0
347 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
349 if (sprintf (buf, "%Le", -1.0L / zeroL) < 0
350 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
352 if (sprintf (buf, "%Le", zeroL / zeroL) < 0
353 || !strisnan (buf, 0, strlen (buf)))
355 if (sprintf (buf, "%Lg", 1.0L / zeroL) < 0
356 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
358 if (sprintf (buf, "%Lg", -1.0L / zeroL) < 0
359 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
361 if (sprintf (buf, "%Lg", zeroL / zeroL) < 0
362 || !strisnan (buf, 0, strlen (buf)))
364 #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
365 /* Representation of an 80-bit 'long double' as an initializer for a sequence
366 of 'unsigned int' words. */
367 # ifdef WORDS_BIGENDIAN
368 # define LDBL80_WORDS(exponent,manthi,mantlo) \
369 { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
370 ((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16), \
371 (unsigned int) (mantlo) << 16 \
374 # define LDBL80_WORDS(exponent,manthi,mantlo) \
375 { mantlo, manthi, exponent }
378 static union { unsigned int word[4]; long double value; } x =
379 { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
380 if (sprintf (buf, "%Lf", x.value) < 0
381 || !strisnan (buf, 0, strlen (buf)))
383 if (sprintf (buf, "%Le", x.value) < 0
384 || !strisnan (buf, 0, strlen (buf)))
386 if (sprintf (buf, "%Lg", x.value) < 0
387 || !strisnan (buf, 0, strlen (buf)))
391 /* Signalling NaN. */
392 static union { unsigned int word[4]; long double value; } x =
393 { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
394 if (sprintf (buf, "%Lf", x.value) < 0
395 || !strisnan (buf, 0, strlen (buf)))
397 if (sprintf (buf, "%Le", x.value) < 0
398 || !strisnan (buf, 0, strlen (buf)))
400 if (sprintf (buf, "%Lg", x.value) < 0
401 || !strisnan (buf, 0, strlen (buf)))
405 static union { unsigned int word[4]; long double value; } x =
406 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
407 if (sprintf (buf, "%Lf", x.value) <= 0)
409 if (sprintf (buf, "%Le", x.value) <= 0)
411 if (sprintf (buf, "%Lg", x.value) <= 0)
414 { /* Pseudo-Infinity. */
415 static union { unsigned int word[4]; long double value; } x =
416 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
417 if (sprintf (buf, "%Lf", x.value) <= 0)
419 if (sprintf (buf, "%Le", x.value) <= 0)
421 if (sprintf (buf, "%Lg", x.value) <= 0)
425 static union { unsigned int word[4]; long double value; } x =
426 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
427 if (sprintf (buf, "%Lf", x.value) <= 0)
429 if (sprintf (buf, "%Le", x.value) <= 0)
431 if (sprintf (buf, "%Lg", x.value) <= 0)
434 { /* Unnormalized number. */
435 static union { unsigned int word[4]; long double value; } x =
436 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
437 if (sprintf (buf, "%Lf", x.value) <= 0)
439 if (sprintf (buf, "%Le", x.value) <= 0)
441 if (sprintf (buf, "%Lg", x.value) <= 0)
444 { /* Pseudo-Denormal. */
445 static union { unsigned int word[4]; long double value; } x =
446 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
447 if (sprintf (buf, "%Lf", x.value) <= 0)
449 if (sprintf (buf, "%Le", x.value) <= 0)
451 if (sprintf (buf, "%Lg", x.value) <= 0)
457 [gl_cv_func_printf_infinite_long_double=yes],
458 [gl_cv_func_printf_infinite_long_double=no],
460 # Guess no on ia64, x86_64, i386.
461 ia64 | x86_64 | i*86) gl_cv_func_printf_infinite_long_double="guessing no";;
465 # Guess yes on glibc systems.
466 *-gnu* | gnu*) gl_cv_func_printf_infinite_long_double="guessing yes";;
467 # Guess yes on musl systems.
468 *-musl*) gl_cv_func_printf_infinite_long_double="guessing yes";;
469 # Guess yes on FreeBSD >= 6.
470 freebsd[1-5].*) gl_cv_func_printf_infinite_long_double="guessing no";;
471 freebsd* | kfreebsd*) gl_cv_func_printf_infinite_long_double="guessing yes";;
472 # Guess yes on HP-UX >= 11.
473 hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite_long_double="guessing no";;
474 hpux*) gl_cv_func_printf_infinite_long_double="guessing yes";;
475 # Guess yes on OpenBSD >= 6.0.
476 openbsd[1-5].*) gl_cv_func_printf_infinite_long_double="guessing no";;
477 openbsd*) gl_cv_func_printf_infinite_long_double="guessing yes";;
478 # Guess no on Android.
479 linux*-android*) gl_cv_func_printf_infinite_long_double="guessing no";;
481 # Guess yes on MSVC, no on mingw.
482 mingw*) AC_EGREP_CPP([Known], [
487 [gl_cv_func_printf_infinite_long_double="guessing yes"],
488 [gl_cv_func_printf_infinite_long_double="guessing no"])
490 # If we don't know, obey --enable-cross-guesses.
491 *) gl_cv_func_printf_infinite_long_double="$gl_cross_guess_normal";;
499 gl_cv_func_printf_infinite_long_double="irrelevant"
504 dnl Test whether the *printf family of functions supports the 'a' and 'A'
505 dnl conversion specifier for hexadecimal output of floating-point numbers.
506 dnl (ISO C99, POSIX:2001)
507 dnl Result is gl_cv_func_printf_directive_a.
509 AC_DEFUN([gl_PRINTF_DIRECTIVE_A],
511 AC_REQUIRE([AC_PROG_CC])
512 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
513 AC_CACHE_CHECK([whether printf supports the 'a' and 'A' directives],
514 [gl_cv_func_printf_directive_a],
520 static char buf[100];
521 static double zero = 0.0;
525 if (sprintf (buf, "%a %d", 3.1416015625, 33, 44, 55) < 0
526 || (strcmp (buf, "0x1.922p+1 33") != 0
527 && strcmp (buf, "0x3.244p+0 33") != 0
528 && strcmp (buf, "0x6.488p-1 33") != 0
529 && strcmp (buf, "0xc.91p-2 33") != 0))
531 if (sprintf (buf, "%A %d", -3.1416015625, 33, 44, 55) < 0
532 || (strcmp (buf, "-0X1.922P+1 33") != 0
533 && strcmp (buf, "-0X3.244P+0 33") != 0
534 && strcmp (buf, "-0X6.488P-1 33") != 0
535 && strcmp (buf, "-0XC.91P-2 33") != 0))
537 /* This catches a FreeBSD 6.1 bug: it doesn't round. */
538 if (sprintf (buf, "%.2a %d", 1.51, 33, 44, 55) < 0
539 || (strcmp (buf, "0x1.83p+0 33") != 0
540 && strcmp (buf, "0x3.05p-1 33") != 0
541 && strcmp (buf, "0x6.0ap-2 33") != 0
542 && strcmp (buf, "0xc.14p-3 33") != 0))
544 /* This catches a Mac OS X 10.12.4 (Darwin 16.5) bug: it doesn't round. */
545 if (sprintf (buf, "%.0a %d", 1.51, 33, 44, 55) < 0
546 || (strcmp (buf, "0x2p+0 33") != 0
547 && strcmp (buf, "0x3p-1 33") != 0
548 && strcmp (buf, "0x6p-2 33") != 0
549 && strcmp (buf, "0xcp-3 33") != 0))
551 /* This catches a FreeBSD 6.1 bug. See
552 <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */
553 if (sprintf (buf, "%010a %d", 1.0 / zero, 33, 44, 55) < 0
556 /* This catches a Mac OS X 10.3.9 (Darwin 7.9) bug. */
557 if (sprintf (buf, "%.1a", 1.999) < 0
558 || (strcmp (buf, "0x1.0p+1") != 0
559 && strcmp (buf, "0x2.0p+0") != 0
560 && strcmp (buf, "0x4.0p-1") != 0
561 && strcmp (buf, "0x8.0p-2") != 0))
563 /* This catches the same Mac OS X 10.3.9 (Darwin 7.9) bug and also a
564 glibc 2.4 bug <https://sourceware.org/bugzilla/show_bug.cgi?id=2908>. */
565 if (sprintf (buf, "%.1La", 1.999L) < 0
566 || (strcmp (buf, "0x1.0p+1") != 0
567 && strcmp (buf, "0x2.0p+0") != 0
568 && strcmp (buf, "0x4.0p-1") != 0
569 && strcmp (buf, "0x8.0p-2") != 0))
573 [gl_cv_func_printf_directive_a=yes],
574 [gl_cv_func_printf_directive_a=no],
577 # Guess yes on glibc >= 2.5 systems.
579 AC_EGREP_CPP([BZ2908], [
580 #include <features.h>
581 #ifdef __GNU_LIBRARY__
582 #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 5) || (__GLIBC__ > 2)) && !defined __UCLIBC__
587 [gl_cv_func_printf_directive_a="guessing yes"],
588 [gl_cv_func_printf_directive_a="guessing no"])
590 # Guess yes on musl systems.
591 *-musl*) gl_cv_func_printf_directive_a="guessing yes";;
592 # Guess no on Android.
593 linux*-android*) gl_cv_func_printf_directive_a="guessing no";;
594 # Guess no on native Windows.
595 mingw*) gl_cv_func_printf_directive_a="guessing no";;
596 # If we don't know, obey --enable-cross-guesses.
597 *) gl_cv_func_printf_directive_a="$gl_cross_guess_normal";;
603 dnl Test whether the *printf family of functions supports the %F format
604 dnl directive. (ISO C99, POSIX:2001)
605 dnl Result is gl_cv_func_printf_directive_f.
607 AC_DEFUN([gl_PRINTF_DIRECTIVE_F],
609 AC_REQUIRE([AC_PROG_CC])
610 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
611 AC_CACHE_CHECK([whether printf supports the 'F' directive],
612 [gl_cv_func_printf_directive_f],
618 static char buf[100];
619 static double zero = 0.0;
623 if (sprintf (buf, "%F %d", 1234567.0, 33, 44, 55) < 0
624 || strcmp (buf, "1234567.000000 33") != 0)
626 if (sprintf (buf, "%F", 1.0 / zero) < 0
627 || (strcmp (buf, "INF") != 0 && strcmp (buf, "INFINITY") != 0))
629 /* This catches a Cygwin 1.5.x bug. */
630 if (sprintf (buf, "%.F", 1234.0) < 0
631 || strcmp (buf, "1234") != 0)
635 [gl_cv_func_printf_directive_f=yes],
636 [gl_cv_func_printf_directive_f=no],
640 # Guess yes on glibc systems.
641 *-gnu* | gnu*) gl_cv_func_printf_directive_f="guessing yes";;
642 # Guess yes on musl systems.
643 *-musl*) gl_cv_func_printf_directive_f="guessing yes";;
644 # Guess yes on FreeBSD >= 6.
645 freebsd[1-5].*) gl_cv_func_printf_directive_f="guessing no";;
646 freebsd* | kfreebsd*) gl_cv_func_printf_directive_f="guessing yes";;
647 # Guess yes on Mac OS X >= 10.3.
648 darwin[1-6].*) gl_cv_func_printf_directive_f="guessing no";;
649 darwin*) gl_cv_func_printf_directive_f="guessing yes";;
650 # Guess yes on OpenBSD >= 6.0.
651 openbsd[1-5].*) gl_cv_func_printf_directive_f="guessing no";;
652 openbsd*) gl_cv_func_printf_directive_f="guessing yes";;
653 # Guess yes on Solaris >= 2.10.
654 solaris2.[1-9][0-9]*) gl_cv_func_printf_directive_f="guessing yes";;
655 solaris*) gl_cv_func_printf_directive_f="guessing no";;
656 # Guess no on Android.
657 linux*-android*) gl_cv_func_printf_directive_f="guessing no";;
659 # Guess yes on MSVC, no on mingw.
660 mingw*) AC_EGREP_CPP([Known], [
665 [gl_cv_func_printf_directive_f="guessing yes"],
666 [gl_cv_func_printf_directive_f="guessing no"])
668 # If we don't know, obey --enable-cross-guesses.
669 *) gl_cv_func_printf_directive_f="$gl_cross_guess_normal";;
675 dnl Test whether the *printf family of functions supports the %n format
676 dnl directive. (ISO C99, POSIX:2001)
677 dnl Result is gl_cv_func_printf_directive_n.
679 AC_DEFUN([gl_PRINTF_DIRECTIVE_N],
681 AC_REQUIRE([AC_PROG_CC])
682 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
683 AC_CACHE_CHECK([whether printf supports the 'n' directive],
684 [gl_cv_func_printf_directive_n],
692 #include <inttypes.h>
693 /* See page about "Parameter Validation" on msdn.microsoft.com.
694 <https://docs.microsoft.com/en-us/cpp/c-runtime-library/parameter-validation>
695 <https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/set-invalid-parameter-handler-set-thread-local-invalid-parameter-handler> */
697 invalid_parameter_handler (const wchar_t *expression,
698 const wchar_t *function,
699 const wchar_t *file, unsigned int line,
705 static char fmtstring[10];
706 static char buf[100];
711 _set_invalid_parameter_handler (invalid_parameter_handler);
713 /* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2)
714 support %n in format strings in read-only memory but not in writable
716 strcpy (fmtstring, "%d %n");
717 if (sprintf (buf, fmtstring, 123, &count, 33, 44, 55) < 0
718 || strcmp (buf, "123 ") != 0
723 [gl_cv_func_printf_directive_n=yes],
724 [gl_cv_func_printf_directive_n=no],
726 # Guess no on glibc when _FORTIFY_SOURCE >= 2.
727 *-gnu* | gnu*) AC_COMPILE_IFELSE(
729 [[#if _FORTIFY_SOURCE >= 2
733 [gl_cv_func_printf_directive_n="guessing yes"],
734 [gl_cv_func_printf_directive_n="guessing no"])
736 # Guess no on Android.
737 linux*-android*) gl_cv_func_printf_directive_n="guessing no";;
738 # Guess no on native Windows.
739 mingw*) gl_cv_func_printf_directive_n="guessing no";;
740 *) gl_cv_func_printf_directive_n="guessing yes";;
746 dnl Test whether the *printf family of functions supports the %ls format
747 dnl directive and in particular, when a precision is specified, whether
748 dnl the functions stop converting the wide string argument when the number
749 dnl of bytes that have been produced by this conversion equals or exceeds
751 dnl Result is gl_cv_func_printf_directive_ls.
753 AC_DEFUN([gl_PRINTF_DIRECTIVE_LS],
755 AC_REQUIRE([AC_PROG_CC])
756 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
757 AC_CACHE_CHECK([whether printf supports the 'ls' directive],
758 [gl_cv_func_printf_directive_ls],
762 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
764 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
765 included before <wchar.h>. */
775 /* Test whether %ls works at all.
776 This test fails on OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku, but not on
779 static const wchar_t wstring[] = { 'a', 'b', 'c', 0 };
781 if (sprintf (buf, "%ls", wstring) < 0
782 || strcmp (buf, "abc") != 0)
785 /* This test fails on IRIX 6.5, Solaris 2.6, Cygwin 1.5, Haiku (with an
786 assertion failure inside libc), but not on OpenBSD 4.0. */
788 static const wchar_t wstring[] = { 'a', 0 };
790 if (sprintf (buf, "%ls", wstring) < 0
791 || strcmp (buf, "a") != 0)
794 /* Test whether precisions in %ls are supported as specified in ISO C 99
796 "If a precision is specified, no more than that many bytes are written
797 (including shift sequences, if any), and the array shall contain a
798 null wide character if, to equal the multibyte character sequence
799 length given by the precision, the function would need to access a
800 wide character one past the end of the array."
801 This test fails on Solaris 10. */
803 static const wchar_t wstring[] = { 'a', 'b', (wchar_t) 0xfdfdfdfd, 0 };
805 if (sprintf (buf, "%.2ls", wstring) < 0
806 || strcmp (buf, "ab") != 0)
811 [gl_cv_func_printf_directive_ls=yes],
812 [gl_cv_func_printf_directive_ls=no],
816 # Guess yes on OpenBSD >= 6.0.
817 openbsd[1-5].*) gl_cv_func_printf_directive_ls="guessing no";;
818 openbsd*) gl_cv_func_printf_directive_ls="guessing yes";;
819 irix*) gl_cv_func_printf_directive_ls="guessing no";;
820 solaris*) gl_cv_func_printf_directive_ls="guessing no";;
821 cygwin*) gl_cv_func_printf_directive_ls="guessing no";;
822 beos* | haiku*) gl_cv_func_printf_directive_ls="guessing no";;
823 # Guess no on Android.
824 linux*-android*) gl_cv_func_printf_directive_ls="guessing no";;
825 # Guess yes on native Windows.
826 mingw*) gl_cv_func_printf_directive_ls="guessing yes";;
827 *) gl_cv_func_printf_directive_ls="guessing yes";;
834 dnl Test whether the *printf family of functions supports POSIX/XSI format
835 dnl strings with positions. (POSIX:2001)
836 dnl Result is gl_cv_func_printf_positions.
838 AC_DEFUN([gl_PRINTF_POSITIONS],
840 AC_REQUIRE([AC_PROG_CC])
841 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
842 AC_CACHE_CHECK([whether printf supports POSIX/XSI format strings with positions],
843 [gl_cv_func_printf_positions],
849 /* The string "%2$d %1$d", with dollar characters protected from the shell's
850 dollar expansion (possibly an autoconf bug). */
851 static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' };
852 static char buf[100];
855 sprintf (buf, format, 33, 55);
856 return (strcmp (buf, "55 33") != 0);
858 [gl_cv_func_printf_positions=yes],
859 [gl_cv_func_printf_positions=no],
863 netbsd[1-3]* | netbsdelf[1-3]* | netbsdaout[1-3]* | netbsdcoff[1-3]*)
864 gl_cv_func_printf_positions="guessing no";;
865 beos*) gl_cv_func_printf_positions="guessing no";;
866 # Guess yes on Android.
867 linux*-android*) gl_cv_func_printf_positions="guessing yes";;
868 # Guess no on native Windows.
869 mingw* | pw*) gl_cv_func_printf_positions="guessing no";;
870 *) gl_cv_func_printf_positions="guessing yes";;
877 dnl Test whether the *printf family of functions supports POSIX/XSI format
878 dnl strings with the ' flag for grouping of decimal digits. (POSIX:2001)
879 dnl Result is gl_cv_func_printf_flag_grouping.
881 AC_DEFUN([gl_PRINTF_FLAG_GROUPING],
883 AC_REQUIRE([AC_PROG_CC])
884 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
885 AC_CACHE_CHECK([whether printf supports the grouping flag],
886 [gl_cv_func_printf_flag_grouping],
892 static char buf[100];
895 if (sprintf (buf, "%'d %d", 1234567, 99) < 0
896 || buf[strlen (buf) - 1] != '9')
900 [gl_cv_func_printf_flag_grouping=yes],
901 [gl_cv_func_printf_flag_grouping=no],
905 cygwin*) gl_cv_func_printf_flag_grouping="guessing no";;
906 netbsd*) gl_cv_func_printf_flag_grouping="guessing no";;
907 # Guess no on Android.
908 linux*-android*) gl_cv_func_printf_flag_grouping="guessing no";;
909 # Guess no on native Windows.
910 mingw* | pw*) gl_cv_func_printf_flag_grouping="guessing no";;
911 *) gl_cv_func_printf_flag_grouping="guessing yes";;
918 dnl Test whether the *printf family of functions supports the - flag correctly.
920 dnl <https://lists.gnu.org/r/bug-coreutils/2008-02/msg00035.html>
921 dnl Result is gl_cv_func_printf_flag_leftadjust.
923 AC_DEFUN([gl_PRINTF_FLAG_LEFTADJUST],
925 AC_REQUIRE([AC_PROG_CC])
926 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
927 AC_CACHE_CHECK([whether printf supports the left-adjust flag correctly],
928 [gl_cv_func_printf_flag_leftadjust],
934 static char buf[100];
937 /* Check that a '-' flag is not annihilated by a negative width. */
938 if (sprintf (buf, "a%-*sc", -3, "b") < 0
939 || strcmp (buf, "ab c") != 0)
943 [gl_cv_func_printf_flag_leftadjust=yes],
944 [gl_cv_func_printf_flag_leftadjust=no],
948 # Guess yes on HP-UX 11.
949 hpux11*) gl_cv_func_printf_flag_leftadjust="guessing yes";;
950 # Guess no on HP-UX 10 and older.
951 hpux*) gl_cv_func_printf_flag_leftadjust="guessing no";;
952 # Guess yes on Android.
953 linux*-android*) gl_cv_func_printf_flag_leftadjust="guessing yes";;
954 # Guess yes on native Windows.
955 mingw*) gl_cv_func_printf_flag_leftadjust="guessing yes";;
956 # Guess yes otherwise.
957 *) gl_cv_func_printf_flag_leftadjust="guessing yes";;
964 dnl Test whether the *printf family of functions supports padding of non-finite
965 dnl values with the 0 flag correctly. (ISO C99 + TC1 + TC2.) See
966 dnl <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html>
967 dnl Result is gl_cv_func_printf_flag_zero.
969 AC_DEFUN([gl_PRINTF_FLAG_ZERO],
971 AC_REQUIRE([AC_PROG_CC])
972 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
973 AC_CACHE_CHECK([whether printf supports the zero flag correctly],
974 [gl_cv_func_printf_flag_zero],
980 static char buf[100];
981 static double zero = 0.0;
984 if (sprintf (buf, "%010f", 1.0 / zero, 33, 44, 55) < 0
985 || (strcmp (buf, " inf") != 0
986 && strcmp (buf, " infinity") != 0))
990 [gl_cv_func_printf_flag_zero=yes],
991 [gl_cv_func_printf_flag_zero=no],
995 # Guess yes on glibc systems.
996 *-gnu* | gnu*) gl_cv_func_printf_flag_zero="guessing yes";;
997 # Guess yes on musl systems.
998 *-musl*) gl_cv_func_printf_flag_zero="guessing yes";;
1000 beos*) gl_cv_func_printf_flag_zero="guessing yes";;
1001 # Guess no on Android.
1002 linux*-android*) gl_cv_func_printf_flag_zero="guessing no";;
1003 # Guess no on native Windows.
1004 mingw*) gl_cv_func_printf_flag_zero="guessing no";;
1005 # If we don't know, obey --enable-cross-guesses.
1006 *) gl_cv_func_printf_flag_zero="$gl_cross_guess_normal";;
1013 dnl Test whether the *printf family of functions supports large precisions.
1014 dnl On mingw, precisions larger than 512 are treated like 512, in integer,
1015 dnl floating-point or pointer output. On Solaris 10/x86, precisions larger
1016 dnl than 510 in floating-point output crash the program. On Solaris 10/SPARC,
1017 dnl precisions larger than 510 in floating-point output yield wrong results.
1018 dnl On AIX 7.1, precisions larger than 998 in floating-point output yield
1019 dnl wrong results. On BeOS, precisions larger than 1044 crash the program.
1020 dnl Result is gl_cv_func_printf_precision.
1022 AC_DEFUN([gl_PRINTF_PRECISION],
1024 AC_REQUIRE([AC_PROG_CC])
1025 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1026 AC_CACHE_CHECK([whether printf supports large precisions],
1027 [gl_cv_func_printf_precision],
1033 static char buf[5000];
1038 /* On BeOS, this would crash and show a dialog box. Avoid the crash. */
1041 if (sprintf (buf, "%.4000d %d", 1, 33, 44) < 4000 + 3)
1043 if (sprintf (buf, "%.4000f %d", 1.0, 33, 44) < 4000 + 5)
1045 if (sprintf (buf, "%.511f %d", 1.0, 33, 44) < 511 + 5
1048 if (sprintf (buf, "%.999f %d", 1.0, 33, 44) < 999 + 5
1053 [gl_cv_func_printf_precision=yes],
1054 [gl_cv_func_printf_precision=no],
1058 # Guess no only on Solaris, native Windows, and BeOS systems.
1059 solaris*) gl_cv_func_printf_precision="guessing no" ;;
1060 mingw* | pw*) gl_cv_func_printf_precision="guessing no" ;;
1061 beos*) gl_cv_func_printf_precision="guessing no" ;;
1062 # Guess yes on Android.
1063 linux*-android*) gl_cv_func_printf_precision="guessing yes" ;;
1064 *) gl_cv_func_printf_precision="guessing yes" ;;
1071 dnl Test whether the *printf family of functions recovers gracefully in case
1072 dnl of an out-of-memory condition, or whether it crashes the entire program.
1073 dnl Result is gl_cv_func_printf_enomem.
1075 AC_DEFUN([gl_PRINTF_ENOMEM],
1077 AC_REQUIRE([AC_PROG_CC])
1078 AC_REQUIRE([gl_MULTIARCH])
1079 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1080 AC_CACHE_CHECK([whether printf survives out-of-memory conditions],
1081 [gl_cv_func_printf_enomem],
1083 gl_cv_func_printf_enomem="guessing no"
1084 if test "$cross_compiling" = no; then
1085 if test $APPLE_UNIVERSAL_BUILD = 0; then
1086 AC_LANG_CONFTEST([AC_LANG_SOURCE([[
1089 #include <sys/types.h>
1090 #include <sys/time.h>
1091 #include <sys/resource.h>
1095 struct rlimit limit;
1098 /* Some printf implementations allocate temporary space with malloc. */
1099 /* On BSD systems, malloc() is limited by RLIMIT_DATA. */
1101 if (getrlimit (RLIMIT_DATA, &limit) < 0)
1103 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
1104 limit.rlim_max = 5000000;
1105 limit.rlim_cur = limit.rlim_max;
1106 if (setrlimit (RLIMIT_DATA, &limit) < 0)
1109 /* On Linux systems, malloc() is limited by RLIMIT_AS. */
1111 if (getrlimit (RLIMIT_AS, &limit) < 0)
1113 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
1114 limit.rlim_max = 5000000;
1115 limit.rlim_cur = limit.rlim_max;
1116 if (setrlimit (RLIMIT_AS, &limit) < 0)
1119 /* Some printf implementations allocate temporary space on the stack. */
1121 if (getrlimit (RLIMIT_STACK, &limit) < 0)
1123 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
1124 limit.rlim_max = 5000000;
1125 limit.rlim_cur = limit.rlim_max;
1126 if (setrlimit (RLIMIT_STACK, &limit) < 0)
1129 ret = printf ("%.5000000f", 1.0);
1130 return !(ret == 5000002 || (ret < 0 && errno == ENOMEM));
1133 if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
1134 (./conftest 2>&AS_MESSAGE_LOG_FD
1136 _AS_ECHO_LOG([\$? = $result])
1137 if test $result != 0 && test $result != 77; then result=1; fi
1139 ) >/dev/null 2>/dev/null
1141 0) gl_cv_func_printf_enomem="yes" ;;
1142 77) gl_cv_func_printf_enomem="guessing no" ;;
1143 *) gl_cv_func_printf_enomem="no" ;;
1146 gl_cv_func_printf_enomem="guessing no"
1150 dnl A universal build on Apple Mac OS X platforms.
1151 dnl The result would be 'no' in 32-bit mode and 'yes' in 64-bit mode.
1152 dnl But we need a configuration result that is valid in both modes.
1153 gl_cv_func_printf_enomem="guessing no"
1156 if test "$gl_cv_func_printf_enomem" = "guessing no"; then
1159 # Guess yes on glibc systems.
1160 *-gnu* | gnu*) gl_cv_func_printf_enomem="guessing yes";;
1161 # Guess yes on Solaris.
1162 solaris*) gl_cv_func_printf_enomem="guessing yes";;
1164 aix*) gl_cv_func_printf_enomem="guessing yes";;
1165 # Guess yes on HP-UX/hppa.
1166 hpux*) case "$host_cpu" in
1167 hppa*) gl_cv_func_printf_enomem="guessing yes";;
1168 *) gl_cv_func_printf_enomem="guessing no";;
1171 # Guess yes on IRIX.
1172 irix*) gl_cv_func_printf_enomem="guessing yes";;
1173 # Guess yes on OSF/1.
1174 osf*) gl_cv_func_printf_enomem="guessing yes";;
1175 # Guess yes on BeOS.
1176 beos*) gl_cv_func_printf_enomem="guessing yes";;
1177 # Guess yes on Haiku.
1178 haiku*) gl_cv_func_printf_enomem="guessing yes";;
1179 # Guess no on Android.
1180 linux*-android*) gl_cv_func_printf_enomem="guessing no";;
1181 # If we don't know, obey --enable-cross-guesses.
1182 *) gl_cv_func_printf_enomem="$gl_cross_guess_normal";;
1189 dnl Test whether the snprintf function exists. (ISO C99, POSIX:2001)
1190 dnl Result is ac_cv_func_snprintf.
1192 AC_DEFUN([gl_SNPRINTF_PRESENCE],
1194 AC_CHECK_FUNCS_ONCE([snprintf])
1197 dnl Test whether the string produced by the snprintf function is always NUL
1198 dnl terminated. (ISO C99, POSIX:2001)
1199 dnl Result is gl_cv_func_snprintf_truncation_c99.
1201 AC_DEFUN_ONCE([gl_SNPRINTF_TRUNCATION_C99],
1203 AC_REQUIRE([AC_PROG_CC])
1204 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1205 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1206 AC_CACHE_CHECK([whether snprintf truncates the result as in C99],
1207 [gl_cv_func_snprintf_truncation_c99],
1214 # define my_snprintf snprintf
1216 # include <stdarg.h>
1217 static int my_snprintf (char *buf, int size, const char *format, ...)
1221 va_start (args, format);
1222 ret = vsnprintf (buf, size, format, args);
1227 static char buf[100];
1230 strcpy (buf, "ABCDEF");
1231 my_snprintf (buf, 3, "%d %d", 4567, 89);
1232 if (memcmp (buf, "45\0DEF", 6) != 0)
1236 [gl_cv_func_snprintf_truncation_c99=yes],
1237 [gl_cv_func_snprintf_truncation_c99=no],
1241 # Guess yes on glibc systems.
1242 *-gnu* | gnu*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1243 # Guess yes on musl systems.
1244 *-musl*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1245 # Guess yes on FreeBSD >= 5.
1246 freebsd[1-4].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1247 freebsd* | kfreebsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1248 # Guess yes on Mac OS X >= 10.3.
1249 darwin[1-6].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1250 darwin*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1251 # Guess yes on OpenBSD >= 3.9.
1252 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
1253 gl_cv_func_snprintf_truncation_c99="guessing no";;
1254 openbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1255 # Guess yes on Solaris >= 2.6.
1256 solaris2.[0-5] | solaris2.[0-5].*)
1257 gl_cv_func_snprintf_truncation_c99="guessing no";;
1258 solaris*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1259 # Guess yes on AIX >= 4.
1260 aix[1-3]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1261 aix*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1262 # Guess yes on HP-UX >= 11.
1263 hpux[7-9]* | hpux10*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1264 hpux*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1265 # Guess yes on IRIX >= 6.5.
1266 irix6.5) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1267 # Guess yes on OSF/1 >= 5.
1268 osf[3-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1269 osf*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1270 # Guess yes on NetBSD >= 3.
1271 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1272 gl_cv_func_snprintf_truncation_c99="guessing no";;
1273 netbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1274 # Guess yes on BeOS.
1275 beos*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1276 # Guess yes on Android.
1277 linux*-android*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1278 # Guess no on native Windows.
1279 mingw*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1280 # If we don't know, obey --enable-cross-guesses.
1281 *) gl_cv_func_snprintf_truncation_c99="$gl_cross_guess_normal";;
1288 dnl Test whether the return value of the snprintf function is the number
1289 dnl of bytes (excluding the terminating NUL) that would have been produced
1290 dnl if the buffer had been large enough. (ISO C99, POSIX:2001)
1291 dnl For example, this test program fails on IRIX 6.5:
1292 dnl ---------------------------------------------------------------------
1293 dnl #include <stdio.h>
1296 dnl static char buf[8];
1297 dnl int retval = snprintf (buf, 3, "%d", 12345);
1298 dnl return retval >= 0 && retval < 3;
1300 dnl ---------------------------------------------------------------------
1301 dnl Result is gl_cv_func_snprintf_retval_c99.
1303 AC_DEFUN_ONCE([gl_SNPRINTF_RETVAL_C99],
1305 AC_REQUIRE([AC_PROG_CC])
1306 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1307 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1308 AC_CACHE_CHECK([whether snprintf returns a byte count as in C99],
1309 [gl_cv_func_snprintf_retval_c99],
1316 # define my_snprintf snprintf
1318 # include <stdarg.h>
1319 static int my_snprintf (char *buf, int size, const char *format, ...)
1323 va_start (args, format);
1324 ret = vsnprintf (buf, size, format, args);
1329 static char buf[100];
1332 strcpy (buf, "ABCDEF");
1333 if (my_snprintf (buf, 3, "%d %d", 4567, 89) != 7)
1335 if (my_snprintf (buf, 0, "%d %d", 4567, 89) != 7)
1337 if (my_snprintf (NULL, 0, "%d %d", 4567, 89) != 7)
1341 [gl_cv_func_snprintf_retval_c99=yes],
1342 [gl_cv_func_snprintf_retval_c99=no],
1345 # Guess yes on glibc systems.
1346 *-gnu* | gnu*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1347 # Guess yes on musl systems.
1348 *-musl*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1349 # Guess yes on FreeBSD >= 5.
1350 freebsd[1-4].*) gl_cv_func_snprintf_retval_c99="guessing no";;
1351 freebsd* | kfreebsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1352 # Guess yes on Mac OS X >= 10.3.
1353 darwin[1-6].*) gl_cv_func_snprintf_retval_c99="guessing no";;
1354 darwin*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1355 # Guess yes on OpenBSD >= 3.9.
1356 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
1357 gl_cv_func_snprintf_retval_c99="guessing no";;
1358 openbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1359 # Guess yes on Solaris >= 2.10.
1360 solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";;
1361 solaris*) gl_cv_func_printf_sizes_c99="guessing no";;
1362 # Guess yes on AIX >= 4.
1363 aix[1-3]*) gl_cv_func_snprintf_retval_c99="guessing no";;
1364 aix*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1365 # Guess yes on NetBSD >= 3.
1366 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1367 gl_cv_func_snprintf_retval_c99="guessing no";;
1368 netbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1369 # Guess yes on BeOS.
1370 beos*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1371 # Guess yes on Android.
1372 linux*-android*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1374 # Guess yes on MSVC, no on mingw.
1375 mingw*) AC_EGREP_CPP([Known], [
1380 [gl_cv_func_snprintf_retval_c99="guessing yes"],
1381 [gl_cv_func_snprintf_retval_c99="guessing no"])
1383 # If we don't know, obey --enable-cross-guesses.
1384 *) gl_cv_func_snprintf_retval_c99="$gl_cross_guess_normal";;
1390 dnl Test whether the snprintf function supports the %n format directive
1391 dnl also in truncated portions of the format string. (ISO C99, POSIX:2001)
1392 dnl Result is gl_cv_func_snprintf_directive_n.
1394 AC_DEFUN([gl_SNPRINTF_DIRECTIVE_N],
1396 AC_REQUIRE([AC_PROG_CC])
1397 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1398 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1399 AC_CACHE_CHECK([whether snprintf fully supports the 'n' directive],
1400 [gl_cv_func_snprintf_directive_n],
1407 # define my_snprintf snprintf
1409 # include <stdarg.h>
1410 static int my_snprintf (char *buf, int size, const char *format, ...)
1414 va_start (args, format);
1415 ret = vsnprintf (buf, size, format, args);
1420 static char fmtstring[10];
1421 static char buf[100];
1425 /* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2)
1426 support %n in format strings in read-only memory but not in writable
1428 strcpy (fmtstring, "%d %n");
1429 my_snprintf (buf, 4, fmtstring, 12345, &count, 33, 44, 55);
1434 [gl_cv_func_snprintf_directive_n=yes],
1435 [gl_cv_func_snprintf_directive_n=no],
1438 # Guess no on glibc when _FORTIFY_SOURCE >= 2.
1439 *-gnu* | gnu*) AC_COMPILE_IFELSE(
1441 [[#if _FORTIFY_SOURCE >= 2
1445 [gl_cv_func_snprintf_directive_n="guessing yes"],
1446 [gl_cv_func_snprintf_directive_n="guessing no"])
1449 # Guess yes on musl systems.
1450 *-musl*) gl_cv_func_snprintf_directive_n="guessing yes";;
1451 # Guess yes on FreeBSD >= 5.
1452 freebsd[1-4].*) gl_cv_func_snprintf_directive_n="guessing no";;
1453 freebsd* | kfreebsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
1454 # Guess yes on Mac OS X >= 10.3.
1455 darwin[1-6].*) gl_cv_func_snprintf_directive_n="guessing no";;
1456 darwin*) gl_cv_func_snprintf_directive_n="guessing yes";;
1457 # Guess yes on Solaris >= 2.6.
1458 solaris2.[0-5] | solaris2.[0-5].*)
1459 gl_cv_func_snprintf_directive_n="guessing no";;
1460 solaris*) gl_cv_func_snprintf_directive_n="guessing yes";;
1461 # Guess yes on AIX >= 4.
1462 aix[1-3]*) gl_cv_func_snprintf_directive_n="guessing no";;
1463 aix*) gl_cv_func_snprintf_directive_n="guessing yes";;
1464 # Guess yes on IRIX >= 6.5.
1465 irix6.5) gl_cv_func_snprintf_directive_n="guessing yes";;
1466 # Guess yes on OSF/1 >= 5.
1467 osf[3-4]*) gl_cv_func_snprintf_directive_n="guessing no";;
1468 osf*) gl_cv_func_snprintf_directive_n="guessing yes";;
1469 # Guess yes on NetBSD >= 3.
1470 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1471 gl_cv_func_snprintf_directive_n="guessing no";;
1472 netbsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
1473 # Guess yes on BeOS.
1474 beos*) gl_cv_func_snprintf_directive_n="guessing yes";;
1475 # Guess no on Android.
1476 linux*-android*) gl_cv_func_snprintf_directive_n="guessing no";;
1477 # Guess no on native Windows.
1478 mingw*) gl_cv_func_snprintf_directive_n="guessing no";;
1479 # If we don't know, obey --enable-cross-guesses.
1480 *) gl_cv_func_snprintf_directive_n="$gl_cross_guess_normal";;
1487 dnl Test whether the snprintf function, when passed a size = 1, writes any
1488 dnl output without bounds in this case, behaving like sprintf. This is the
1489 dnl case on Linux libc5.
1490 dnl Result is gl_cv_func_snprintf_size1.
1492 AC_DEFUN([gl_SNPRINTF_SIZE1],
1494 AC_REQUIRE([AC_PROG_CC])
1495 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1496 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1497 AC_CACHE_CHECK([whether snprintf respects a size of 1],
1498 [gl_cv_func_snprintf_size1],
1504 # define my_snprintf snprintf
1506 # include <stdarg.h>
1507 static int my_snprintf (char *buf, int size, const char *format, ...)
1511 va_start (args, format);
1512 ret = vsnprintf (buf, size, format, args);
1519 static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1520 my_snprintf (buf, 1, "%d", 12345);
1521 return buf[1] != 'E';
1523 [gl_cv_func_snprintf_size1=yes],
1524 [gl_cv_func_snprintf_size1=no],
1526 # Guess yes on Android.
1527 linux*-android*) gl_cv_func_snprintf_size1="guessing yes" ;;
1528 # Guess yes on native Windows.
1529 mingw*) gl_cv_func_snprintf_size1="guessing yes" ;;
1530 *) gl_cv_func_snprintf_size1="guessing yes" ;;
1536 dnl Test whether the vsnprintf function, when passed a zero size, produces no
1537 dnl output. (ISO C99, POSIX:2001)
1538 dnl For example, snprintf nevertheless writes a NUL byte in this case
1540 dnl ---------------------------------------------------------------------
1541 dnl #include <stdio.h>
1544 dnl static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1545 dnl snprintf (buf, 0, "%d", 12345);
1546 dnl return buf[0] != 'D';
1548 dnl ---------------------------------------------------------------------
1549 dnl And vsnprintf writes any output without bounds in this case, behaving like
1550 dnl vsprintf, on HP-UX 11 and OSF/1 5.1:
1551 dnl ---------------------------------------------------------------------
1552 dnl #include <stdarg.h>
1553 dnl #include <stdio.h>
1554 dnl static int my_snprintf (char *buf, int size, const char *format, ...)
1558 dnl va_start (args, format);
1559 dnl ret = vsnprintf (buf, size, format, args);
1565 dnl static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1566 dnl my_snprintf (buf, 0, "%d", 12345);
1567 dnl return buf[0] != 'D';
1569 dnl ---------------------------------------------------------------------
1570 dnl Result is gl_cv_func_vsnprintf_zerosize_c99.
1572 AC_DEFUN([gl_VSNPRINTF_ZEROSIZE_C99],
1574 AC_REQUIRE([AC_PROG_CC])
1575 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1576 AC_CACHE_CHECK([whether vsnprintf respects a zero size as in C99],
1577 [gl_cv_func_vsnprintf_zerosize_c99],
1583 static int my_snprintf (char *buf, int size, const char *format, ...)
1587 va_start (args, format);
1588 ret = vsnprintf (buf, size, format, args);
1594 static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1595 my_snprintf (buf, 0, "%d", 12345);
1596 return buf[0] != 'D';
1598 [gl_cv_func_vsnprintf_zerosize_c99=yes],
1599 [gl_cv_func_vsnprintf_zerosize_c99=no],
1603 # Guess yes on glibc systems.
1604 *-gnu* | gnu*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1605 # Guess yes on musl systems.
1606 *-musl*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1607 # Guess yes on FreeBSD >= 5.
1608 freebsd[1-4].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1609 freebsd* | kfreebsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1610 # Guess yes on Mac OS X >= 10.3.
1611 darwin[1-6].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1612 darwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1613 # Guess yes on Cygwin.
1614 cygwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1615 # Guess yes on Solaris >= 2.6.
1616 solaris2.[0-5] | solaris2.[0-5].*)
1617 gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1618 solaris*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1619 # Guess yes on AIX >= 4.
1620 aix[1-3]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1621 aix*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1622 # Guess yes on IRIX >= 6.5.
1623 irix6.5) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1624 # Guess yes on NetBSD >= 3.
1625 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1626 gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1627 netbsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1628 # Guess yes on BeOS.
1629 beos*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1630 # Guess yes on Android.
1631 linux*-android*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1632 # Guess yes on native Windows.
1633 mingw* | pw*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1634 # If we don't know, obey --enable-cross-guesses.
1635 *) gl_cv_func_vsnprintf_zerosize_c99="$gl_cross_guess_normal";;
1642 dnl The results of these tests on various platforms are:
1644 dnl 1 = gl_PRINTF_SIZES_C99
1645 dnl 2 = gl_PRINTF_LONG_DOUBLE
1646 dnl 3 = gl_PRINTF_INFINITE
1647 dnl 4 = gl_PRINTF_INFINITE_LONG_DOUBLE
1648 dnl 5 = gl_PRINTF_DIRECTIVE_A
1649 dnl 6 = gl_PRINTF_DIRECTIVE_F
1650 dnl 7 = gl_PRINTF_DIRECTIVE_N
1651 dnl 8 = gl_PRINTF_DIRECTIVE_LS
1652 dnl 9 = gl_PRINTF_POSITIONS
1653 dnl 10 = gl_PRINTF_FLAG_GROUPING
1654 dnl 11 = gl_PRINTF_FLAG_LEFTADJUST
1655 dnl 12 = gl_PRINTF_FLAG_ZERO
1656 dnl 13 = gl_PRINTF_PRECISION
1657 dnl 14 = gl_PRINTF_ENOMEM
1658 dnl 15 = gl_SNPRINTF_PRESENCE
1659 dnl 16 = gl_SNPRINTF_TRUNCATION_C99
1660 dnl 17 = gl_SNPRINTF_RETVAL_C99
1661 dnl 18 = gl_SNPRINTF_DIRECTIVE_N
1662 dnl 19 = gl_SNPRINTF_SIZE1
1663 dnl 20 = gl_VSNPRINTF_ZEROSIZE_C99
1665 dnl 1 = checking whether printf supports size specifiers as in C99...
1666 dnl 2 = checking whether printf supports 'long double' arguments...
1667 dnl 3 = checking whether printf supports infinite 'double' arguments...
1668 dnl 4 = checking whether printf supports infinite 'long double' arguments...
1669 dnl 5 = checking whether printf supports the 'a' and 'A' directives...
1670 dnl 6 = checking whether printf supports the 'F' directive...
1671 dnl 7 = checking whether printf supports the 'n' directive...
1672 dnl 8 = checking whether printf supports the 'ls' directive...
1673 dnl 9 = checking whether printf supports POSIX/XSI format strings with positions...
1674 dnl 10 = checking whether printf supports the grouping flag...
1675 dnl 11 = checking whether printf supports the left-adjust flag correctly...
1676 dnl 12 = checking whether printf supports the zero flag correctly...
1677 dnl 13 = checking whether printf supports large precisions...
1678 dnl 14 = checking whether printf survives out-of-memory conditions...
1679 dnl 15 = checking for snprintf...
1680 dnl 16 = checking whether snprintf truncates the result as in C99...
1681 dnl 17 = checking whether snprintf returns a byte count as in C99...
1682 dnl 18 = checking whether snprintf fully supports the 'n' directive...
1683 dnl 19 = checking whether snprintf respects a size of 1...
1684 dnl 20 = checking whether vsnprintf respects a zero size as in C99...
1686 dnl . = yes, # = no.
1688 dnl 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1689 dnl glibc 2.5 . . . . . . . . . . . . . . . . . . . .
1690 dnl glibc 2.3.6 . . . . # . . . . . . . . . . . . . . .
1691 dnl FreeBSD 5.4, 6.1 . . . . # . . . . . . # . # . . . . . .
1692 dnl Mac OS X 10.13.5 . . . # # . # . . . . . . . . . . # . .
1693 dnl Mac OS X 10.5.8 . . . # # . . . . . . # . . . . . . . .
1694 dnl Mac OS X 10.3.9 . . . . # . . . . . . # . # . . . . . .
1695 dnl OpenBSD 6.0, 6.7 . . . . # . . . . . . . . # . . . . . .
1696 dnl OpenBSD 3.9, 4.0 . . # # # # . # . # . # . # . . . . . .
1697 dnl Cygwin 1.7.0 (2009) . . . # . . . ? . . . . . ? . . . . . .
1698 dnl Cygwin 1.5.25 (2008) . . . # # . . # . . . . . # . . . . . .
1699 dnl Cygwin 1.5.19 (2006) # . . # # # . # . # . # # # . . . . . .
1700 dnl Solaris 11.4 . . # # # . . # . . . # . . . . . . . .
1701 dnl Solaris 11.3 . . . . # . . # . . . . . . . . . . . .
1702 dnl Solaris 11.0 . . # # # . . # . . . # . . . . . . . .
1703 dnl Solaris 10 . . # # # . . # . . . # # . . . . . . .
1704 dnl Solaris 2.6 ... 9 # . # # # # . # . . . # # . . . # . . .
1705 dnl Solaris 2.5.1 # . # # # # . # . . . # . . # # # # # #
1706 dnl AIX 7.1 . . # # # . . . . . . # # . . . . . . .
1707 dnl AIX 5.2 . . # # # . . . . . . # . . . . . . . .
1708 dnl AIX 4.3.2, 5.1 # . # # # # . . . . . # . . . . # . . .
1709 dnl HP-UX 11.31 . . . . # . . . . . . # . . . . # # . .
1710 dnl HP-UX 11.{00,11,23} # . . . # # . . . . . # . . . . # # . #
1711 dnl HP-UX 10.20 # . # . # # . ? . . # # . . . . # # ? #
1712 dnl IRIX 6.5 # . # # # # . # . . . # . . . . # . . .
1713 dnl OSF/1 5.1 # . # # # # . . . . . # . . . . # . . #
1714 dnl OSF/1 4.0d # . # # # # . . . . . # . . # # # # # #
1715 dnl NetBSD 9.0 . . . . # . . . . . . . . . . . . . . .
1716 dnl NetBSD 5.0 . . . # # . . . . . . # . # . . . . . .
1717 dnl NetBSD 4.0 . ? ? ? ? ? . ? . ? ? ? ? ? . . . ? ? ?
1718 dnl NetBSD 3.0 . . . . # # . ? # # ? # . # . . . . . .
1719 dnl Haiku . . . # # # . # . . . . . ? . . ? . . .
1720 dnl BeOS # # . # # # . ? # . ? . # ? . . ? . . .
1721 dnl Android 4.3 . . # # # # # # . # . # . # . . . # . .
1722 dnl old mingw / msvcrt # # # # # # . . # # . # # ? . # # # . .
1723 dnl MSVC 9 # # # # # # # . # # . # # ? # # # # . .
1724 dnl mingw 2009-2011 . # . # . . . . # # . . . ? . . . . . .
1725 dnl mingw-w64 2011 # # # # # # . . # # . # # ? . # # # . .