2 dnl Copyright (C) 2003, 2007-2017 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*) gl_cv_func_printf_sizes_c99="guessing yes";;
65 # Guess yes on FreeBSD >= 5.
66 freebsd[1-4].*) gl_cv_func_printf_sizes_c99="guessing no";;
67 freebsd* | kfreebsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
68 # Guess yes on Mac OS X >= 10.3.
69 darwin[1-6].*) gl_cv_func_printf_sizes_c99="guessing no";;
70 darwin*) gl_cv_func_printf_sizes_c99="guessing yes";;
71 # Guess yes on OpenBSD >= 3.9.
72 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
73 gl_cv_func_printf_sizes_c99="guessing no";;
74 openbsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
75 # Guess yes on Solaris >= 2.10.
76 solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";;
77 solaris*) gl_cv_func_printf_sizes_c99="guessing no";;
78 # Guess yes on NetBSD >= 3.
79 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
80 gl_cv_func_printf_sizes_c99="guessing no";;
81 netbsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
83 # Guess yes on MSVC, no on mingw.
84 mingw*) AC_EGREP_CPP([Known], [
89 [gl_cv_func_printf_sizes_c99="guessing yes"],
90 [gl_cv_func_printf_sizes_c99="guessing no"])
92 # If we don't know, assume the worst.
93 *) gl_cv_func_printf_sizes_c99="guessing no";;
99 dnl Test whether the *printf family of functions supports 'long double'
100 dnl arguments together with the 'L' size specifier. (ISO C99, POSIX:2001)
101 dnl Result is gl_cv_func_printf_long_double.
103 AC_DEFUN([gl_PRINTF_LONG_DOUBLE],
105 AC_REQUIRE([AC_PROG_CC])
106 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
107 AC_CACHE_CHECK([whether printf supports 'long double' arguments],
108 [gl_cv_func_printf_long_double],
114 static char buf[10000];
119 if (sprintf (buf, "%Lf %d", 1.75L, 33, 44, 55) < 0
120 || strcmp (buf, "1.750000 33") != 0)
123 if (sprintf (buf, "%Le %d", 1.75L, 33, 44, 55) < 0
124 || strcmp (buf, "1.750000e+00 33") != 0)
127 if (sprintf (buf, "%Lg %d", 1.75L, 33, 44, 55) < 0
128 || strcmp (buf, "1.75 33") != 0)
132 [gl_cv_func_printf_long_double=yes],
133 [gl_cv_func_printf_long_double=no],
135 beos*) gl_cv_func_printf_long_double="guessing no";;
136 # Guess yes on MSVC, no on mingw.
137 mingw*) AC_EGREP_CPP([Known], [
142 [gl_cv_func_printf_long_double="guessing yes"],
143 [gl_cv_func_printf_long_double="guessing no"])
145 *) gl_cv_func_printf_long_double="guessing yes";;
151 dnl Test whether the *printf family of functions supports infinite and NaN
152 dnl 'double' arguments and negative zero arguments in the %f, %e, %g
153 dnl directives. (ISO C99, POSIX:2001)
154 dnl Result is gl_cv_func_printf_infinite.
156 AC_DEFUN([gl_PRINTF_INFINITE],
158 AC_REQUIRE([AC_PROG_CC])
159 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
160 AC_CACHE_CHECK([whether printf supports infinite 'double' arguments],
161 [gl_cv_func_printf_infinite],
168 strisnan (const char *string, size_t start_index, size_t end_index)
170 if (start_index < end_index)
172 if (string[start_index] == '-')
174 if (start_index + 3 <= end_index
175 && memcmp (string + start_index, "nan", 3) == 0)
178 if (start_index == end_index
179 || (string[start_index] == '(' && string[end_index - 1] == ')'))
188 static double plus_zero = 0.0;
189 double minus_zero = - plus_zero;
190 return memcmp (&plus_zero, &minus_zero, sizeof (double)) != 0;
192 static char buf[10000];
193 static double zero = 0.0;
197 if (sprintf (buf, "%f", 1.0 / zero) < 0
198 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
200 if (sprintf (buf, "%f", -1.0 / zero) < 0
201 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
203 if (sprintf (buf, "%f", zero / zero) < 0
204 || !strisnan (buf, 0, strlen (buf)))
206 if (sprintf (buf, "%e", 1.0 / zero) < 0
207 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
209 if (sprintf (buf, "%e", -1.0 / zero) < 0
210 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
212 if (sprintf (buf, "%e", zero / zero) < 0
213 || !strisnan (buf, 0, strlen (buf)))
215 if (sprintf (buf, "%g", 1.0 / zero) < 0
216 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
218 if (sprintf (buf, "%g", -1.0 / zero) < 0
219 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
221 if (sprintf (buf, "%g", zero / zero) < 0
222 || !strisnan (buf, 0, strlen (buf)))
224 /* This test fails on HP-UX 10.20. */
225 if (have_minus_zero ())
226 if (sprintf (buf, "%g", - zero) < 0
227 || strcmp (buf, "-0") != 0)
231 [gl_cv_func_printf_infinite=yes],
232 [gl_cv_func_printf_infinite=no],
236 # Guess yes on glibc systems.
237 *-gnu*) gl_cv_func_printf_infinite="guessing yes";;
238 # Guess yes on FreeBSD >= 6.
239 freebsd[1-5].*) gl_cv_func_printf_infinite="guessing no";;
240 freebsd* | kfreebsd*) gl_cv_func_printf_infinite="guessing yes";;
241 # Guess yes on Mac OS X >= 10.3.
242 darwin[1-6].*) gl_cv_func_printf_infinite="guessing no";;
243 darwin*) gl_cv_func_printf_infinite="guessing yes";;
244 # Guess yes on HP-UX >= 11.
245 hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite="guessing no";;
246 hpux*) gl_cv_func_printf_infinite="guessing yes";;
247 # Guess yes on NetBSD >= 3.
248 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
249 gl_cv_func_printf_infinite="guessing no";;
250 netbsd*) gl_cv_func_printf_infinite="guessing yes";;
252 beos*) gl_cv_func_printf_infinite="guessing yes";;
254 # Guess yes on MSVC, no on mingw.
255 mingw*) AC_EGREP_CPP([Known], [
260 [gl_cv_func_printf_infinite="guessing yes"],
261 [gl_cv_func_printf_infinite="guessing no"])
263 # If we don't know, assume the worst.
264 *) gl_cv_func_printf_infinite="guessing no";;
270 dnl Test whether the *printf family of functions supports infinite and NaN
271 dnl 'long double' arguments in the %f, %e, %g directives. (ISO C99, POSIX:2001)
272 dnl Result is gl_cv_func_printf_infinite_long_double.
274 AC_DEFUN([gl_PRINTF_INFINITE_LONG_DOUBLE],
276 AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
277 AC_REQUIRE([AC_PROG_CC])
278 AC_REQUIRE([gl_BIGENDIAN])
279 AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
280 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
281 dnl The user can set or unset the variable gl_printf_safe to indicate
282 dnl that he wishes a safe handling of non-IEEE-754 'long double' values.
283 if test -n "$gl_printf_safe"; then
284 AC_DEFINE([CHECK_PRINTF_SAFE], [1],
285 [Define if you wish *printf() functions that have a safe handling of
286 non-IEEE-754 'long double' values.])
288 case "$gl_cv_func_printf_long_double" in
290 AC_CACHE_CHECK([whether printf supports infinite 'long double' arguments],
291 [gl_cv_func_printf_infinite_long_double],
300 strisnan (const char *string, size_t start_index, size_t end_index)
302 if (start_index < end_index)
304 if (string[start_index] == '-')
306 if (start_index + 3 <= end_index
307 && memcmp (string + start_index, "nan", 3) == 0)
310 if (start_index == end_index
311 || (string[start_index] == '(' && string[end_index - 1] == ')'))
317 static char buf[10000];
318 static long double zeroL = 0.0L;
323 if (sprintf (buf, "%Lf", 1.0L / zeroL) < 0
324 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
326 if (sprintf (buf, "%Lf", -1.0L / zeroL) < 0
327 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
329 if (sprintf (buf, "%Lf", zeroL / zeroL) < 0
330 || !strisnan (buf, 0, strlen (buf)))
332 if (sprintf (buf, "%Le", 1.0L / zeroL) < 0
333 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
335 if (sprintf (buf, "%Le", -1.0L / zeroL) < 0
336 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
338 if (sprintf (buf, "%Le", zeroL / zeroL) < 0
339 || !strisnan (buf, 0, strlen (buf)))
341 if (sprintf (buf, "%Lg", 1.0L / zeroL) < 0
342 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
344 if (sprintf (buf, "%Lg", -1.0L / zeroL) < 0
345 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
347 if (sprintf (buf, "%Lg", zeroL / zeroL) < 0
348 || !strisnan (buf, 0, strlen (buf)))
350 #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
351 /* Representation of an 80-bit 'long double' as an initializer for a sequence
352 of 'unsigned int' words. */
353 # ifdef WORDS_BIGENDIAN
354 # define LDBL80_WORDS(exponent,manthi,mantlo) \
355 { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
356 ((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16), \
357 (unsigned int) (mantlo) << 16 \
360 # define LDBL80_WORDS(exponent,manthi,mantlo) \
361 { mantlo, manthi, exponent }
364 static union { unsigned int word[4]; long double value; } x =
365 { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
366 if (sprintf (buf, "%Lf", x.value) < 0
367 || !strisnan (buf, 0, strlen (buf)))
369 if (sprintf (buf, "%Le", x.value) < 0
370 || !strisnan (buf, 0, strlen (buf)))
372 if (sprintf (buf, "%Lg", x.value) < 0
373 || !strisnan (buf, 0, strlen (buf)))
377 /* Signalling NaN. */
378 static union { unsigned int word[4]; long double value; } x =
379 { LDBL80_WORDS (0xFFFF, 0x83333333, 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 static union { unsigned int word[4]; long double value; } x =
392 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
393 if (sprintf (buf, "%Lf", x.value) <= 0)
395 if (sprintf (buf, "%Le", x.value) <= 0)
397 if (sprintf (buf, "%Lg", x.value) <= 0)
400 { /* Pseudo-Infinity. */
401 static union { unsigned int word[4]; long double value; } x =
402 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
403 if (sprintf (buf, "%Lf", x.value) <= 0)
405 if (sprintf (buf, "%Le", x.value) <= 0)
407 if (sprintf (buf, "%Lg", x.value) <= 0)
411 static union { unsigned int word[4]; long double value; } x =
412 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
413 if (sprintf (buf, "%Lf", x.value) <= 0)
415 if (sprintf (buf, "%Le", x.value) <= 0)
417 if (sprintf (buf, "%Lg", x.value) <= 0)
420 { /* Unnormalized number. */
421 static union { unsigned int word[4]; long double value; } x =
422 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
423 if (sprintf (buf, "%Lf", x.value) <= 0)
425 if (sprintf (buf, "%Le", x.value) <= 0)
427 if (sprintf (buf, "%Lg", x.value) <= 0)
430 { /* Pseudo-Denormal. */
431 static union { unsigned int word[4]; long double value; } x =
432 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
433 if (sprintf (buf, "%Lf", x.value) <= 0)
435 if (sprintf (buf, "%Le", x.value) <= 0)
437 if (sprintf (buf, "%Lg", x.value) <= 0)
443 [gl_cv_func_printf_infinite_long_double=yes],
444 [gl_cv_func_printf_infinite_long_double=no],
446 # Guess no on ia64, x86_64, i386.
447 ia64 | x86_64 | i*86) gl_cv_func_printf_infinite_long_double="guessing no";;
451 # Guess yes on glibc systems.
452 *-gnu*) gl_cv_func_printf_infinite_long_double="guessing yes";;
453 # Guess yes on FreeBSD >= 6.
454 freebsd[1-5].*) gl_cv_func_printf_infinite_long_double="guessing no";;
455 freebsd* | kfreebsd*) gl_cv_func_printf_infinite_long_double="guessing yes";;
456 # Guess yes on HP-UX >= 11.
457 hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite_long_double="guessing no";;
458 hpux*) gl_cv_func_printf_infinite_long_double="guessing yes";;
460 # Guess yes on MSVC, no on mingw.
461 mingw*) AC_EGREP_CPP([Known], [
466 [gl_cv_func_printf_infinite_long_double="guessing yes"],
467 [gl_cv_func_printf_infinite_long_double="guessing no"])
469 # If we don't know, assume the worst.
470 *) gl_cv_func_printf_infinite_long_double="guessing no";;
478 gl_cv_func_printf_infinite_long_double="irrelevant"
483 dnl Test whether the *printf family of functions supports the 'a' and 'A'
484 dnl conversion specifier for hexadecimal output of floating-point numbers.
485 dnl (ISO C99, POSIX:2001)
486 dnl Result is gl_cv_func_printf_directive_a.
488 AC_DEFUN([gl_PRINTF_DIRECTIVE_A],
490 AC_REQUIRE([AC_PROG_CC])
491 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
492 AC_CACHE_CHECK([whether printf supports the 'a' and 'A' directives],
493 [gl_cv_func_printf_directive_a],
499 static char buf[100];
500 static double zero = 0.0;
504 if (sprintf (buf, "%a %d", 3.1416015625, 33, 44, 55) < 0
505 || (strcmp (buf, "0x1.922p+1 33") != 0
506 && strcmp (buf, "0x3.244p+0 33") != 0
507 && strcmp (buf, "0x6.488p-1 33") != 0
508 && strcmp (buf, "0xc.91p-2 33") != 0))
510 if (sprintf (buf, "%A %d", -3.1416015625, 33, 44, 55) < 0
511 || (strcmp (buf, "-0X1.922P+1 33") != 0
512 && strcmp (buf, "-0X3.244P+0 33") != 0
513 && strcmp (buf, "-0X6.488P-1 33") != 0
514 && strcmp (buf, "-0XC.91P-2 33") != 0))
516 /* This catches a FreeBSD 6.1 bug: it doesn't round. */
517 if (sprintf (buf, "%.2a %d", 1.51, 33, 44, 55) < 0
518 || (strcmp (buf, "0x1.83p+0 33") != 0
519 && strcmp (buf, "0x3.05p-1 33") != 0
520 && strcmp (buf, "0x6.0ap-2 33") != 0
521 && strcmp (buf, "0xc.14p-3 33") != 0))
523 /* This catches a Mac OS X 10.12.4 (Darwin 16.5) bug: it doesn't round. */
524 if (sprintf (buf, "%.0a %d", 1.51, 33, 44, 55) < 0
525 || (strcmp (buf, "0x2p+0 33") != 0
526 && strcmp (buf, "0x3p-1 33") != 0
527 && strcmp (buf, "0x6p-2 33") != 0
528 && strcmp (buf, "0xcp-3 33") != 0))
530 /* This catches a FreeBSD 6.1 bug. See
531 <https://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
532 if (sprintf (buf, "%010a %d", 1.0 / zero, 33, 44, 55) < 0
535 /* This catches a Mac OS X 10.3.9 (Darwin 7.9) bug. */
536 if (sprintf (buf, "%.1a", 1.999) < 0
537 || (strcmp (buf, "0x1.0p+1") != 0
538 && strcmp (buf, "0x2.0p+0") != 0
539 && strcmp (buf, "0x4.0p-1") != 0
540 && strcmp (buf, "0x8.0p-2") != 0))
542 /* This catches the same Mac OS X 10.3.9 (Darwin 7.9) bug and also a
543 glibc 2.4 bug <https://sourceware.org/bugzilla/show_bug.cgi?id=2908>. */
544 if (sprintf (buf, "%.1La", 1.999L) < 0
545 || (strcmp (buf, "0x1.0p+1") != 0
546 && strcmp (buf, "0x2.0p+0") != 0
547 && strcmp (buf, "0x4.0p-1") != 0
548 && strcmp (buf, "0x8.0p-2") != 0))
552 [gl_cv_func_printf_directive_a=yes],
553 [gl_cv_func_printf_directive_a=no],
556 # Guess yes on glibc >= 2.5 systems.
558 AC_EGREP_CPP([BZ2908], [
559 #include <features.h>
560 #ifdef __GNU_LIBRARY__
561 #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 5) || (__GLIBC__ > 2)) && !defined __UCLIBC__
566 [gl_cv_func_printf_directive_a="guessing yes"],
567 [gl_cv_func_printf_directive_a="guessing no"])
569 # Guess no on native Windows.
570 mingw*) gl_cv_func_printf_directive_a="guessing no";;
571 # If we don't know, assume the worst.
572 *) gl_cv_func_printf_directive_a="guessing no";;
578 dnl Test whether the *printf family of functions supports the %F format
579 dnl directive. (ISO C99, POSIX:2001)
580 dnl Result is gl_cv_func_printf_directive_f.
582 AC_DEFUN([gl_PRINTF_DIRECTIVE_F],
584 AC_REQUIRE([AC_PROG_CC])
585 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
586 AC_CACHE_CHECK([whether printf supports the 'F' directive],
587 [gl_cv_func_printf_directive_f],
593 static char buf[100];
594 static double zero = 0.0;
598 if (sprintf (buf, "%F %d", 1234567.0, 33, 44, 55) < 0
599 || strcmp (buf, "1234567.000000 33") != 0)
601 if (sprintf (buf, "%F", 1.0 / zero) < 0
602 || (strcmp (buf, "INF") != 0 && strcmp (buf, "INFINITY") != 0))
604 /* This catches a Cygwin 1.5.x bug. */
605 if (sprintf (buf, "%.F", 1234.0) < 0
606 || strcmp (buf, "1234") != 0)
610 [gl_cv_func_printf_directive_f=yes],
611 [gl_cv_func_printf_directive_f=no],
615 # Guess yes on glibc systems.
616 *-gnu*) gl_cv_func_printf_directive_f="guessing yes";;
617 # Guess yes on FreeBSD >= 6.
618 freebsd[1-5].*) gl_cv_func_printf_directive_f="guessing no";;
619 freebsd* | kfreebsd*) gl_cv_func_printf_directive_f="guessing yes";;
620 # Guess yes on Mac OS X >= 10.3.
621 darwin[1-6].*) gl_cv_func_printf_directive_f="guessing no";;
622 darwin*) gl_cv_func_printf_directive_f="guessing yes";;
623 # Guess yes on Solaris >= 2.10.
624 solaris2.[1-9][0-9]*) gl_cv_func_printf_directive_f="guessing yes";;
625 solaris*) gl_cv_func_printf_directive_f="guessing no";;
627 # Guess yes on MSVC, no on mingw.
628 mingw*) AC_EGREP_CPP([Known], [
633 [gl_cv_func_printf_directive_f="guessing yes"],
634 [gl_cv_func_printf_directive_f="guessing no"])
636 # If we don't know, assume the worst.
637 *) gl_cv_func_printf_directive_f="guessing no";;
643 dnl Test whether the *printf family of functions supports the %n format
644 dnl directive. (ISO C99, POSIX:2001)
645 dnl Result is gl_cv_func_printf_directive_n.
647 AC_DEFUN([gl_PRINTF_DIRECTIVE_N],
649 AC_REQUIRE([AC_PROG_CC])
650 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
651 AC_CACHE_CHECK([whether printf supports the 'n' directive],
652 [gl_cv_func_printf_directive_n],
660 /* See page about "Parameter Validation" on msdn.microsoft.com. */
662 invalid_parameter_handler (const wchar_t *expression,
663 const wchar_t *function,
664 const wchar_t *file, unsigned int line,
670 static char fmtstring[10];
671 static char buf[100];
676 _set_invalid_parameter_handler (invalid_parameter_handler);
678 /* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2)
679 support %n in format strings in read-only memory but not in writable
681 strcpy (fmtstring, "%d %n");
682 if (sprintf (buf, fmtstring, 123, &count, 33, 44, 55) < 0
683 || strcmp (buf, "123 ") != 0
688 [gl_cv_func_printf_directive_n=yes],
689 [gl_cv_func_printf_directive_n=no],
691 # Guess no on native Windows.
692 mingw*) gl_cv_func_printf_directive_n="guessing no";;
693 *) gl_cv_func_printf_directive_n="guessing yes";;
699 dnl Test whether the *printf family of functions supports the %ls format
700 dnl directive and in particular, when a precision is specified, whether
701 dnl the functions stop converting the wide string argument when the number
702 dnl of bytes that have been produced by this conversion equals or exceeds
704 dnl Result is gl_cv_func_printf_directive_ls.
706 AC_DEFUN([gl_PRINTF_DIRECTIVE_LS],
708 AC_REQUIRE([AC_PROG_CC])
709 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
710 AC_CACHE_CHECK([whether printf supports the 'ls' directive],
711 [gl_cv_func_printf_directive_ls],
715 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
717 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
718 included before <wchar.h>. */
728 /* Test whether %ls works at all.
729 This test fails on OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku, but not on
732 static const wchar_t wstring[] = { 'a', 'b', 'c', 0 };
734 if (sprintf (buf, "%ls", wstring) < 0
735 || strcmp (buf, "abc") != 0)
738 /* This test fails on IRIX 6.5, Solaris 2.6, Cygwin 1.5, Haiku (with an
739 assertion failure inside libc), but not on OpenBSD 4.0. */
741 static const wchar_t wstring[] = { 'a', 0 };
743 if (sprintf (buf, "%ls", wstring) < 0
744 || strcmp (buf, "a") != 0)
747 /* Test whether precisions in %ls are supported as specified in ISO C 99
749 "If a precision is specified, no more than that many bytes are written
750 (including shift sequences, if any), and the array shall contain a
751 null wide character if, to equal the multibyte character sequence
752 length given by the precision, the function would need to access a
753 wide character one past the end of the array."
754 This test fails on Solaris 10. */
756 static const wchar_t wstring[] = { 'a', 'b', (wchar_t) 0xfdfdfdfd, 0 };
758 if (sprintf (buf, "%.2ls", wstring) < 0
759 || strcmp (buf, "ab") != 0)
764 [gl_cv_func_printf_directive_ls=yes],
765 [gl_cv_func_printf_directive_ls=no],
769 openbsd*) gl_cv_func_printf_directive_ls="guessing no";;
770 irix*) gl_cv_func_printf_directive_ls="guessing no";;
771 solaris*) gl_cv_func_printf_directive_ls="guessing no";;
772 cygwin*) gl_cv_func_printf_directive_ls="guessing no";;
773 beos* | haiku*) gl_cv_func_printf_directive_ls="guessing no";;
774 # Guess yes on native Windows.
775 mingw*) gl_cv_func_printf_directive_ls="guessing yes";;
776 *) gl_cv_func_printf_directive_ls="guessing yes";;
783 dnl Test whether the *printf family of functions supports POSIX/XSI format
784 dnl strings with positions. (POSIX:2001)
785 dnl Result is gl_cv_func_printf_positions.
787 AC_DEFUN([gl_PRINTF_POSITIONS],
789 AC_REQUIRE([AC_PROG_CC])
790 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
791 AC_CACHE_CHECK([whether printf supports POSIX/XSI format strings with positions],
792 [gl_cv_func_printf_positions],
798 /* The string "%2$d %1$d", with dollar characters protected from the shell's
799 dollar expansion (possibly an autoconf bug). */
800 static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' };
801 static char buf[100];
804 sprintf (buf, format, 33, 55);
805 return (strcmp (buf, "55 33") != 0);
807 [gl_cv_func_printf_positions=yes],
808 [gl_cv_func_printf_positions=no],
812 netbsd[1-3]* | netbsdelf[1-3]* | netbsdaout[1-3]* | netbsdcoff[1-3]*)
813 gl_cv_func_printf_positions="guessing no";;
814 beos*) gl_cv_func_printf_positions="guessing no";;
815 # Guess no on native Windows.
816 mingw* | pw*) gl_cv_func_printf_positions="guessing no";;
817 *) gl_cv_func_printf_positions="guessing yes";;
824 dnl Test whether the *printf family of functions supports POSIX/XSI format
825 dnl strings with the ' flag for grouping of decimal digits. (POSIX:2001)
826 dnl Result is gl_cv_func_printf_flag_grouping.
828 AC_DEFUN([gl_PRINTF_FLAG_GROUPING],
830 AC_REQUIRE([AC_PROG_CC])
831 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
832 AC_CACHE_CHECK([whether printf supports the grouping flag],
833 [gl_cv_func_printf_flag_grouping],
839 static char buf[100];
842 if (sprintf (buf, "%'d %d", 1234567, 99) < 0
843 || buf[strlen (buf) - 1] != '9')
847 [gl_cv_func_printf_flag_grouping=yes],
848 [gl_cv_func_printf_flag_grouping=no],
852 cygwin*) gl_cv_func_printf_flag_grouping="guessing no";;
853 netbsd*) gl_cv_func_printf_flag_grouping="guessing no";;
854 # Guess no on native Windows.
855 mingw* | pw*) gl_cv_func_printf_flag_grouping="guessing no";;
856 *) gl_cv_func_printf_flag_grouping="guessing yes";;
863 dnl Test whether the *printf family of functions supports the - flag correctly.
865 dnl <https://lists.gnu.org/archive/html/bug-coreutils/2008-02/msg00035.html>
866 dnl Result is gl_cv_func_printf_flag_leftadjust.
868 AC_DEFUN([gl_PRINTF_FLAG_LEFTADJUST],
870 AC_REQUIRE([AC_PROG_CC])
871 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
872 AC_CACHE_CHECK([whether printf supports the left-adjust flag correctly],
873 [gl_cv_func_printf_flag_leftadjust],
879 static char buf[100];
882 /* Check that a '-' flag is not annihilated by a negative width. */
883 if (sprintf (buf, "a%-*sc", -3, "b") < 0
884 || strcmp (buf, "ab c") != 0)
888 [gl_cv_func_printf_flag_leftadjust=yes],
889 [gl_cv_func_printf_flag_leftadjust=no],
893 # Guess yes on HP-UX 11.
894 hpux11*) gl_cv_func_printf_flag_leftadjust="guessing yes";;
895 # Guess no on HP-UX 10 and older.
896 hpux*) gl_cv_func_printf_flag_leftadjust="guessing no";;
897 # Guess yes on native Windows.
898 mingw*) gl_cv_func_printf_flag_leftadjust="guessing yes";;
899 # Guess yes otherwise.
900 *) gl_cv_func_printf_flag_leftadjust="guessing yes";;
907 dnl Test whether the *printf family of functions supports padding of non-finite
908 dnl values with the 0 flag correctly. (ISO C99 + TC1 + TC2.) See
909 dnl <https://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html>
910 dnl Result is gl_cv_func_printf_flag_zero.
912 AC_DEFUN([gl_PRINTF_FLAG_ZERO],
914 AC_REQUIRE([AC_PROG_CC])
915 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
916 AC_CACHE_CHECK([whether printf supports the zero flag correctly],
917 [gl_cv_func_printf_flag_zero],
923 static char buf[100];
924 static double zero = 0.0;
927 if (sprintf (buf, "%010f", 1.0 / zero, 33, 44, 55) < 0
928 || (strcmp (buf, " inf") != 0
929 && strcmp (buf, " infinity") != 0))
933 [gl_cv_func_printf_flag_zero=yes],
934 [gl_cv_func_printf_flag_zero=no],
938 # Guess yes on glibc systems.
939 *-gnu*) gl_cv_func_printf_flag_zero="guessing yes";;
941 beos*) gl_cv_func_printf_flag_zero="guessing yes";;
942 # Guess no on native Windows.
943 mingw*) gl_cv_func_printf_flag_zero="guessing no";;
944 # If we don't know, assume the worst.
945 *) gl_cv_func_printf_flag_zero="guessing no";;
952 dnl Test whether the *printf family of functions supports large precisions.
953 dnl On mingw, precisions larger than 512 are treated like 512, in integer,
954 dnl floating-point or pointer output. On Solaris 10/x86, precisions larger
955 dnl than 510 in floating-point output crash the program. On Solaris 10/SPARC,
956 dnl precisions larger than 510 in floating-point output yield wrong results.
957 dnl On AIX 7.1, precisions larger than 998 in floating-point output yield
958 dnl wrong results. On BeOS, precisions larger than 1044 crash the program.
959 dnl Result is gl_cv_func_printf_precision.
961 AC_DEFUN([gl_PRINTF_PRECISION],
963 AC_REQUIRE([AC_PROG_CC])
964 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
965 AC_CACHE_CHECK([whether printf supports large precisions],
966 [gl_cv_func_printf_precision],
972 static char buf[5000];
977 /* On BeOS, this would crash and show a dialog box. Avoid the crash. */
980 if (sprintf (buf, "%.4000d %d", 1, 33, 44) < 4000 + 3)
982 if (sprintf (buf, "%.4000f %d", 1.0, 33, 44) < 4000 + 5)
984 if (sprintf (buf, "%.511f %d", 1.0, 33, 44) < 511 + 5
987 if (sprintf (buf, "%.999f %d", 1.0, 33, 44) < 999 + 5
992 [gl_cv_func_printf_precision=yes],
993 [gl_cv_func_printf_precision=no],
997 # Guess no only on Solaris, native Windows, and BeOS systems.
998 solaris*) gl_cv_func_printf_precision="guessing no" ;;
999 mingw* | pw*) gl_cv_func_printf_precision="guessing no" ;;
1000 beos*) gl_cv_func_printf_precision="guessing no" ;;
1001 *) gl_cv_func_printf_precision="guessing yes" ;;
1008 dnl Test whether the *printf family of functions recovers gracefully in case
1009 dnl of an out-of-memory condition, or whether it crashes the entire program.
1010 dnl Result is gl_cv_func_printf_enomem.
1012 AC_DEFUN([gl_PRINTF_ENOMEM],
1014 AC_REQUIRE([AC_PROG_CC])
1015 AC_REQUIRE([gl_MULTIARCH])
1016 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1017 AC_CACHE_CHECK([whether printf survives out-of-memory conditions],
1018 [gl_cv_func_printf_enomem],
1020 gl_cv_func_printf_enomem="guessing no"
1021 if test "$cross_compiling" = no; then
1022 if test $APPLE_UNIVERSAL_BUILD = 0; then
1023 AC_LANG_CONFTEST([AC_LANG_SOURCE([
1027 #include <sys/types.h>
1028 #include <sys/time.h>
1029 #include <sys/resource.h>
1033 struct rlimit limit;
1036 /* Some printf implementations allocate temporary space with malloc. */
1037 /* On BSD systems, malloc() is limited by RLIMIT_DATA. */
1039 if (getrlimit (RLIMIT_DATA, &limit) < 0)
1041 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
1042 limit.rlim_max = 5000000;
1043 limit.rlim_cur = limit.rlim_max;
1044 if (setrlimit (RLIMIT_DATA, &limit) < 0)
1047 /* On Linux systems, malloc() is limited by RLIMIT_AS. */
1049 if (getrlimit (RLIMIT_AS, &limit) < 0)
1051 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
1052 limit.rlim_max = 5000000;
1053 limit.rlim_cur = limit.rlim_max;
1054 if (setrlimit (RLIMIT_AS, &limit) < 0)
1057 /* Some printf implementations allocate temporary space on the stack. */
1059 if (getrlimit (RLIMIT_STACK, &limit) < 0)
1061 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
1062 limit.rlim_max = 5000000;
1063 limit.rlim_cur = limit.rlim_max;
1064 if (setrlimit (RLIMIT_STACK, &limit) < 0)
1067 ret = printf ("%.5000000f", 1.0);
1068 return !(ret == 5000002 || (ret < 0 && errno == ENOMEM));
1072 if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
1073 (./conftest 2>&AS_MESSAGE_LOG_FD
1075 _AS_ECHO_LOG([\$? = $result])
1076 if test $result != 0 && test $result != 77; then result=1; fi
1078 ) >/dev/null 2>/dev/null
1080 0) gl_cv_func_printf_enomem="yes" ;;
1081 77) gl_cv_func_printf_enomem="guessing no" ;;
1082 *) gl_cv_func_printf_enomem="no" ;;
1085 gl_cv_func_printf_enomem="guessing no"
1089 dnl A universal build on Apple Mac OS X platforms.
1090 dnl The result would be 'no' in 32-bit mode and 'yes' in 64-bit mode.
1091 dnl But we need a configuration result that is valid in both modes.
1092 gl_cv_func_printf_enomem="guessing no"
1095 if test "$gl_cv_func_printf_enomem" = "guessing no"; then
1098 # Guess yes on glibc systems.
1099 *-gnu*) gl_cv_func_printf_enomem="guessing yes";;
1100 # Guess yes on Solaris.
1101 solaris*) gl_cv_func_printf_enomem="guessing yes";;
1103 aix*) gl_cv_func_printf_enomem="guessing yes";;
1104 # Guess yes on HP-UX/hppa.
1105 hpux*) case "$host_cpu" in
1106 hppa*) gl_cv_func_printf_enomem="guessing yes";;
1107 *) gl_cv_func_printf_enomem="guessing no";;
1110 # Guess yes on IRIX.
1111 irix*) gl_cv_func_printf_enomem="guessing yes";;
1112 # Guess yes on OSF/1.
1113 osf*) gl_cv_func_printf_enomem="guessing yes";;
1114 # Guess yes on BeOS.
1115 beos*) gl_cv_func_printf_enomem="guessing yes";;
1116 # Guess yes on Haiku.
1117 haiku*) gl_cv_func_printf_enomem="guessing yes";;
1118 # If we don't know, assume the worst.
1119 *) gl_cv_func_printf_enomem="guessing no";;
1126 dnl Test whether the snprintf function exists. (ISO C99, POSIX:2001)
1127 dnl Result is ac_cv_func_snprintf.
1129 AC_DEFUN([gl_SNPRINTF_PRESENCE],
1131 AC_CHECK_FUNCS_ONCE([snprintf])
1134 dnl Test whether the string produced by the snprintf function is always NUL
1135 dnl terminated. (ISO C99, POSIX:2001)
1136 dnl Result is gl_cv_func_snprintf_truncation_c99.
1138 AC_DEFUN([gl_SNPRINTF_TRUNCATION_C99],
1140 AC_REQUIRE([AC_PROG_CC])
1141 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1142 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1143 AC_CACHE_CHECK([whether snprintf truncates the result as in C99],
1144 [gl_cv_func_snprintf_truncation_c99],
1151 # define my_snprintf snprintf
1153 # include <stdarg.h>
1154 static int my_snprintf (char *buf, int size, const char *format, ...)
1158 va_start (args, format);
1159 ret = vsnprintf (buf, size, format, args);
1164 static char buf[100];
1167 strcpy (buf, "ABCDEF");
1168 my_snprintf (buf, 3, "%d %d", 4567, 89);
1169 if (memcmp (buf, "45\0DEF", 6) != 0)
1173 [gl_cv_func_snprintf_truncation_c99=yes],
1174 [gl_cv_func_snprintf_truncation_c99=no],
1178 # Guess yes on glibc systems.
1179 *-gnu*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1180 # Guess yes on FreeBSD >= 5.
1181 freebsd[1-4].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1182 freebsd* | kfreebsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1183 # Guess yes on Mac OS X >= 10.3.
1184 darwin[1-6].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1185 darwin*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1186 # Guess yes on OpenBSD >= 3.9.
1187 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
1188 gl_cv_func_snprintf_truncation_c99="guessing no";;
1189 openbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1190 # Guess yes on Solaris >= 2.6.
1191 solaris2.[0-5] | solaris2.[0-5].*)
1192 gl_cv_func_snprintf_truncation_c99="guessing no";;
1193 solaris*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1194 # Guess yes on AIX >= 4.
1195 aix[1-3]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1196 aix*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1197 # Guess yes on HP-UX >= 11.
1198 hpux[7-9]* | hpux10*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1199 hpux*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1200 # Guess yes on IRIX >= 6.5.
1201 irix6.5) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1202 # Guess yes on OSF/1 >= 5.
1203 osf[3-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1204 osf*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1205 # Guess yes on NetBSD >= 3.
1206 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1207 gl_cv_func_snprintf_truncation_c99="guessing no";;
1208 netbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1209 # Guess yes on BeOS.
1210 beos*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1211 # Guess no on native Windows.
1212 mingw*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1213 # If we don't know, assume the worst.
1214 *) gl_cv_func_snprintf_truncation_c99="guessing no";;
1221 dnl Test whether the return value of the snprintf function is the number
1222 dnl of bytes (excluding the terminating NUL) that would have been produced
1223 dnl if the buffer had been large enough. (ISO C99, POSIX:2001)
1224 dnl For example, this test program fails on IRIX 6.5:
1225 dnl ---------------------------------------------------------------------
1226 dnl #include <stdio.h>
1229 dnl static char buf[8];
1230 dnl int retval = snprintf (buf, 3, "%d", 12345);
1231 dnl return retval >= 0 && retval < 3;
1233 dnl ---------------------------------------------------------------------
1234 dnl Result is gl_cv_func_snprintf_retval_c99.
1236 AC_DEFUN_ONCE([gl_SNPRINTF_RETVAL_C99],
1238 AC_REQUIRE([AC_PROG_CC])
1239 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1240 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1241 AC_CACHE_CHECK([whether snprintf returns a byte count as in C99],
1242 [gl_cv_func_snprintf_retval_c99],
1249 # define my_snprintf snprintf
1251 # include <stdarg.h>
1252 static int my_snprintf (char *buf, int size, const char *format, ...)
1256 va_start (args, format);
1257 ret = vsnprintf (buf, size, format, args);
1262 static char buf[100];
1265 strcpy (buf, "ABCDEF");
1266 if (my_snprintf (buf, 3, "%d %d", 4567, 89) != 7)
1268 if (my_snprintf (buf, 0, "%d %d", 4567, 89) != 7)
1270 if (my_snprintf (NULL, 0, "%d %d", 4567, 89) != 7)
1274 [gl_cv_func_snprintf_retval_c99=yes],
1275 [gl_cv_func_snprintf_retval_c99=no],
1278 # Guess yes on glibc systems.
1279 *-gnu*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1280 # Guess yes on FreeBSD >= 5.
1281 freebsd[1-4].*) gl_cv_func_snprintf_retval_c99="guessing no";;
1282 freebsd* | kfreebsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1283 # Guess yes on Mac OS X >= 10.3.
1284 darwin[1-6].*) gl_cv_func_snprintf_retval_c99="guessing no";;
1285 darwin*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1286 # Guess yes on OpenBSD >= 3.9.
1287 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
1288 gl_cv_func_snprintf_retval_c99="guessing no";;
1289 openbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1290 # Guess yes on Solaris >= 2.10.
1291 solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";;
1292 solaris*) gl_cv_func_printf_sizes_c99="guessing no";;
1293 # Guess yes on AIX >= 4.
1294 aix[1-3]*) gl_cv_func_snprintf_retval_c99="guessing no";;
1295 aix*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1296 # Guess yes on NetBSD >= 3.
1297 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1298 gl_cv_func_snprintf_retval_c99="guessing no";;
1299 netbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1300 # Guess yes on BeOS.
1301 beos*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1303 # Guess yes on MSVC, no on mingw.
1304 mingw*) AC_EGREP_CPP([Known], [
1309 [gl_cv_func_snprintf_retval_c99="guessing yes"],
1310 [gl_cv_func_snprintf_retval_c99="guessing no"])
1312 # If we don't know, assume the worst.
1313 *) gl_cv_func_snprintf_retval_c99="guessing no";;
1319 dnl Test whether the snprintf function supports the %n format directive
1320 dnl also in truncated portions of the format string. (ISO C99, POSIX:2001)
1321 dnl Result is gl_cv_func_snprintf_directive_n.
1323 AC_DEFUN([gl_SNPRINTF_DIRECTIVE_N],
1325 AC_REQUIRE([AC_PROG_CC])
1326 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1327 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1328 AC_CACHE_CHECK([whether snprintf fully supports the 'n' directive],
1329 [gl_cv_func_snprintf_directive_n],
1336 # define my_snprintf snprintf
1338 # include <stdarg.h>
1339 static int my_snprintf (char *buf, int size, const char *format, ...)
1343 va_start (args, format);
1344 ret = vsnprintf (buf, size, format, args);
1349 static char fmtstring[10];
1350 static char buf[100];
1354 /* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2)
1355 support %n in format strings in read-only memory but not in writable
1357 strcpy (fmtstring, "%d %n");
1358 my_snprintf (buf, 4, fmtstring, 12345, &count, 33, 44, 55);
1363 [gl_cv_func_snprintf_directive_n=yes],
1364 [gl_cv_func_snprintf_directive_n=no],
1368 # Guess yes on glibc systems.
1369 *-gnu*) gl_cv_func_snprintf_directive_n="guessing yes";;
1370 # Guess yes on FreeBSD >= 5.
1371 freebsd[1-4].*) gl_cv_func_snprintf_directive_n="guessing no";;
1372 freebsd* | kfreebsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
1373 # Guess yes on Mac OS X >= 10.3.
1374 darwin[1-6].*) gl_cv_func_snprintf_directive_n="guessing no";;
1375 darwin*) gl_cv_func_snprintf_directive_n="guessing yes";;
1376 # Guess yes on Solaris >= 2.6.
1377 solaris2.[0-5] | solaris2.[0-5].*)
1378 gl_cv_func_snprintf_directive_n="guessing no";;
1379 solaris*) gl_cv_func_snprintf_directive_n="guessing yes";;
1380 # Guess yes on AIX >= 4.
1381 aix[1-3]*) gl_cv_func_snprintf_directive_n="guessing no";;
1382 aix*) gl_cv_func_snprintf_directive_n="guessing yes";;
1383 # Guess yes on IRIX >= 6.5.
1384 irix6.5) gl_cv_func_snprintf_directive_n="guessing yes";;
1385 # Guess yes on OSF/1 >= 5.
1386 osf[3-4]*) gl_cv_func_snprintf_directive_n="guessing no";;
1387 osf*) gl_cv_func_snprintf_directive_n="guessing yes";;
1388 # Guess yes on NetBSD >= 3.
1389 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1390 gl_cv_func_snprintf_directive_n="guessing no";;
1391 netbsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
1392 # Guess yes on BeOS.
1393 beos*) gl_cv_func_snprintf_directive_n="guessing yes";;
1394 # Guess no on native Windows.
1395 mingw*) gl_cv_func_snprintf_directive_n="guessing no";;
1396 # If we don't know, assume the worst.
1397 *) gl_cv_func_snprintf_directive_n="guessing no";;
1404 dnl Test whether the snprintf function, when passed a size = 1, writes any
1405 dnl output without bounds in this case, behaving like sprintf. This is the
1406 dnl case on Linux libc5.
1407 dnl Result is gl_cv_func_snprintf_size1.
1409 AC_DEFUN([gl_SNPRINTF_SIZE1],
1411 AC_REQUIRE([AC_PROG_CC])
1412 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1413 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1414 AC_CACHE_CHECK([whether snprintf respects a size of 1],
1415 [gl_cv_func_snprintf_size1],
1421 # define my_snprintf snprintf
1423 # include <stdarg.h>
1424 static int my_snprintf (char *buf, int size, const char *format, ...)
1428 va_start (args, format);
1429 ret = vsnprintf (buf, size, format, args);
1436 static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1437 my_snprintf (buf, 1, "%d", 12345);
1438 return buf[1] != 'E';
1440 [gl_cv_func_snprintf_size1=yes],
1441 [gl_cv_func_snprintf_size1=no],
1443 # Guess yes on native Windows.
1444 mingw*) gl_cv_func_snprintf_size1="guessing yes" ;;
1445 *) gl_cv_func_snprintf_size1="guessing yes" ;;
1451 dnl Test whether the vsnprintf function, when passed a zero size, produces no
1452 dnl output. (ISO C99, POSIX:2001)
1453 dnl For example, snprintf nevertheless writes a NUL byte in this case
1455 dnl ---------------------------------------------------------------------
1456 dnl #include <stdio.h>
1459 dnl static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1460 dnl snprintf (buf, 0, "%d", 12345);
1461 dnl return buf[0] != 'D';
1463 dnl ---------------------------------------------------------------------
1464 dnl And vsnprintf writes any output without bounds in this case, behaving like
1465 dnl vsprintf, on HP-UX 11 and OSF/1 5.1:
1466 dnl ---------------------------------------------------------------------
1467 dnl #include <stdarg.h>
1468 dnl #include <stdio.h>
1469 dnl static int my_snprintf (char *buf, int size, const char *format, ...)
1473 dnl va_start (args, format);
1474 dnl ret = vsnprintf (buf, size, format, args);
1480 dnl static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1481 dnl my_snprintf (buf, 0, "%d", 12345);
1482 dnl return buf[0] != 'D';
1484 dnl ---------------------------------------------------------------------
1485 dnl Result is gl_cv_func_vsnprintf_zerosize_c99.
1487 AC_DEFUN([gl_VSNPRINTF_ZEROSIZE_C99],
1489 AC_REQUIRE([AC_PROG_CC])
1490 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1491 AC_CACHE_CHECK([whether vsnprintf respects a zero size as in C99],
1492 [gl_cv_func_vsnprintf_zerosize_c99],
1498 static int my_snprintf (char *buf, int size, const char *format, ...)
1502 va_start (args, format);
1503 ret = vsnprintf (buf, size, format, args);
1509 static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1510 my_snprintf (buf, 0, "%d", 12345);
1511 return buf[0] != 'D';
1513 [gl_cv_func_vsnprintf_zerosize_c99=yes],
1514 [gl_cv_func_vsnprintf_zerosize_c99=no],
1518 # Guess yes on glibc systems.
1519 *-gnu*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1520 # Guess yes on FreeBSD >= 5.
1521 freebsd[1-4].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1522 freebsd* | kfreebsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1523 # Guess yes on Mac OS X >= 10.3.
1524 darwin[1-6].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1525 darwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1526 # Guess yes on Cygwin.
1527 cygwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1528 # Guess yes on Solaris >= 2.6.
1529 solaris2.[0-5] | solaris2.[0-5].*)
1530 gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1531 solaris*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1532 # Guess yes on AIX >= 4.
1533 aix[1-3]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1534 aix*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1535 # Guess yes on IRIX >= 6.5.
1536 irix6.5) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1537 # Guess yes on NetBSD >= 3.
1538 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1539 gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1540 netbsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1541 # Guess yes on BeOS.
1542 beos*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1543 # Guess yes on native Windows.
1544 mingw* | pw*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1545 # If we don't know, assume the worst.
1546 *) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1553 dnl The results of these tests on various platforms are:
1555 dnl 1 = gl_PRINTF_SIZES_C99
1556 dnl 2 = gl_PRINTF_LONG_DOUBLE
1557 dnl 3 = gl_PRINTF_INFINITE
1558 dnl 4 = gl_PRINTF_INFINITE_LONG_DOUBLE
1559 dnl 5 = gl_PRINTF_DIRECTIVE_A
1560 dnl 6 = gl_PRINTF_DIRECTIVE_F
1561 dnl 7 = gl_PRINTF_DIRECTIVE_N
1562 dnl 8 = gl_PRINTF_DIRECTIVE_LS
1563 dnl 9 = gl_PRINTF_POSITIONS
1564 dnl 10 = gl_PRINTF_FLAG_GROUPING
1565 dnl 11 = gl_PRINTF_FLAG_LEFTADJUST
1566 dnl 12 = gl_PRINTF_FLAG_ZERO
1567 dnl 13 = gl_PRINTF_PRECISION
1568 dnl 14 = gl_PRINTF_ENOMEM
1569 dnl 15 = gl_SNPRINTF_PRESENCE
1570 dnl 16 = gl_SNPRINTF_TRUNCATION_C99
1571 dnl 17 = gl_SNPRINTF_RETVAL_C99
1572 dnl 18 = gl_SNPRINTF_DIRECTIVE_N
1573 dnl 19 = gl_SNPRINTF_SIZE1
1574 dnl 20 = gl_VSNPRINTF_ZEROSIZE_C99
1576 dnl 1 = checking whether printf supports size specifiers as in C99...
1577 dnl 2 = checking whether printf supports 'long double' arguments...
1578 dnl 3 = checking whether printf supports infinite 'double' arguments...
1579 dnl 4 = checking whether printf supports infinite 'long double' arguments...
1580 dnl 5 = checking whether printf supports the 'a' and 'A' directives...
1581 dnl 6 = checking whether printf supports the 'F' directive...
1582 dnl 7 = checking whether printf supports the 'n' directive...
1583 dnl 8 = checking whether printf supports the 'ls' directive...
1584 dnl 9 = checking whether printf supports POSIX/XSI format strings with positions...
1585 dnl 10 = checking whether printf supports the grouping flag...
1586 dnl 11 = checking whether printf supports the left-adjust flag correctly...
1587 dnl 12 = checking whether printf supports the zero flag correctly...
1588 dnl 13 = checking whether printf supports large precisions...
1589 dnl 14 = checking whether printf survives out-of-memory conditions...
1590 dnl 15 = checking for snprintf...
1591 dnl 16 = checking whether snprintf truncates the result as in C99...
1592 dnl 17 = checking whether snprintf returns a byte count as in C99...
1593 dnl 18 = checking whether snprintf fully supports the 'n' directive...
1594 dnl 19 = checking whether snprintf respects a size of 1...
1595 dnl 20 = checking whether vsnprintf respects a zero size as in C99...
1597 dnl . = yes, # = no.
1599 dnl 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1600 dnl glibc 2.5 . . . . . . . . . . . . . . . . . . . .
1601 dnl glibc 2.3.6 . . . . # . . . . . . . . . . . . . . .
1602 dnl FreeBSD 5.4, 6.1 . . . . # . . . . . . # . # . . . . . .
1603 dnl Mac OS X 10.5.8 . . . # # . . . . . . # . . . . . . . .
1604 dnl Mac OS X 10.3.9 . . . . # . . . . . . # . # . . . . . .
1605 dnl OpenBSD 3.9, 4.0 . . # # # # . # . # . # . # . . . . . .
1606 dnl Cygwin 1.7.0 (2009) . . . # . . . ? . . . . . ? . . . . . .
1607 dnl Cygwin 1.5.25 (2008) . . . # # . . # . . . . . # . . . . . .
1608 dnl Cygwin 1.5.19 (2006) # . . # # # . # . # . # # # . . . . . .
1609 dnl Solaris 11 2011-11 . . # # # . . # . . . # . . . . . . . .
1610 dnl Solaris 10 . . # # # . . # . . . # # . . . . . . .
1611 dnl Solaris 2.6 ... 9 # . # # # # . # . . . # # . . . # . . .
1612 dnl Solaris 2.5.1 # . # # # # . # . . . # . . # # # # # #
1613 dnl AIX 7.1 . . # # # . . . . . . # # . . . . . . .
1614 dnl AIX 5.2 . . # # # . . . . . . # . . . . . . . .
1615 dnl AIX 4.3.2, 5.1 # . # # # # . . . . . # . . . . # . . .
1616 dnl HP-UX 11.31 . . . . # . . . . . . # . . . . # # . .
1617 dnl HP-UX 11.{00,11,23} # . . . # # . . . . . # . . . . # # . #
1618 dnl HP-UX 10.20 # . # . # # . ? . . # # . . . . # # ? #
1619 dnl IRIX 6.5 # . # # # # . # . . . # . . . . # . . .
1620 dnl OSF/1 5.1 # . # # # # . . . . . # . . . . # . . #
1621 dnl OSF/1 4.0d # . # # # # . . . . . # . . # # # # # #
1622 dnl NetBSD 5.0 . . . # # . . . . . . # . # . . . . . .
1623 dnl NetBSD 4.0 . ? ? ? ? ? . ? . ? ? ? ? ? . . . ? ? ?
1624 dnl NetBSD 3.0 . . . . # # . ? # # ? # . # . . . . . .
1625 dnl Haiku . . . # # # . # . . . . . ? . . ? . . .
1626 dnl BeOS # # . # # # . ? # . ? . # ? . . ? . . .
1627 dnl old mingw / msvcrt # # # # # # . . # # . # # ? . # # # . .
1628 dnl MSVC 9 # # # # # # # . # # . # # ? # # # # . .
1629 dnl mingw 2009-2011 . # . # . . . . # # . . . ? . . . . . .
1630 dnl mingw-w64 2011 # # # # # # . . # # . # # ? . # # # . .