2 dnl Copyright (C) 2003, 2007-2013 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)
43 if (sprintf (buf, "%zu %d", (size_t) 12345672, 33, 44, 55) < 0
44 || strcmp (buf, "12345672 33") != 0)
47 if (sprintf (buf, "%tu %d", (ptrdiff_t) 12345673, 33, 44, 55) < 0
48 || strcmp (buf, "12345673 33") != 0)
51 if (sprintf (buf, "%Lg %d", (long double) 1.5, 33, 44, 55) < 0
52 || strcmp (buf, "1.5 33") != 0)
56 [gl_cv_func_printf_sizes_c99=yes],
57 [gl_cv_func_printf_sizes_c99=no],
61 # Guess yes on glibc systems.
62 *-gnu*) gl_cv_func_printf_sizes_c99="guessing yes";;
63 # Guess yes on FreeBSD >= 5.
64 freebsd[1-4]*) gl_cv_func_printf_sizes_c99="guessing no";;
65 freebsd* | kfreebsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
66 # Guess yes on Mac OS X >= 10.3.
67 darwin[1-6].*) gl_cv_func_printf_sizes_c99="guessing no";;
68 darwin*) gl_cv_func_printf_sizes_c99="guessing yes";;
69 # Guess yes on OpenBSD >= 3.9.
70 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
71 gl_cv_func_printf_sizes_c99="guessing no";;
72 openbsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
73 # Guess yes on Solaris >= 2.10.
74 solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";;
75 solaris*) gl_cv_func_printf_sizes_c99="guessing no";;
76 # Guess yes on NetBSD >= 3.
77 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
78 gl_cv_func_printf_sizes_c99="guessing no";;
79 netbsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
80 # If we don't know, assume the worst.
81 *) gl_cv_func_printf_sizes_c99="guessing no";;
88 dnl Test whether the *printf family of functions supports 'long double'
89 dnl arguments together with the 'L' size specifier. (ISO C99, POSIX:2001)
90 dnl Result is gl_cv_func_printf_long_double.
92 AC_DEFUN([gl_PRINTF_LONG_DOUBLE],
94 AC_REQUIRE([AC_PROG_CC])
95 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
96 AC_CACHE_CHECK([whether printf supports 'long double' arguments],
97 [gl_cv_func_printf_long_double],
103 static char buf[10000];
108 if (sprintf (buf, "%Lf %d", 1.75L, 33, 44, 55) < 0
109 || strcmp (buf, "1.750000 33") != 0)
112 if (sprintf (buf, "%Le %d", 1.75L, 33, 44, 55) < 0
113 || strcmp (buf, "1.750000e+00 33") != 0)
116 if (sprintf (buf, "%Lg %d", 1.75L, 33, 44, 55) < 0
117 || strcmp (buf, "1.75 33") != 0)
121 [gl_cv_func_printf_long_double=yes],
122 [gl_cv_func_printf_long_double=no],
126 beos*) gl_cv_func_printf_long_double="guessing no";;
127 mingw* | pw*) gl_cv_func_printf_long_double="guessing no";;
128 *) gl_cv_func_printf_long_double="guessing yes";;
135 dnl Test whether the *printf family of functions supports infinite and NaN
136 dnl 'double' arguments and negative zero arguments in the %f, %e, %g
137 dnl directives. (ISO C99, POSIX:2001)
138 dnl Result is gl_cv_func_printf_infinite.
140 AC_DEFUN([gl_PRINTF_INFINITE],
142 AC_REQUIRE([AC_PROG_CC])
143 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
144 AC_CACHE_CHECK([whether printf supports infinite 'double' arguments],
145 [gl_cv_func_printf_infinite],
152 strisnan (const char *string, size_t start_index, size_t end_index)
154 if (start_index < end_index)
156 if (string[start_index] == '-')
158 if (start_index + 3 <= end_index
159 && memcmp (string + start_index, "nan", 3) == 0)
162 if (start_index == end_index
163 || (string[start_index] == '(' && string[end_index - 1] == ')'))
172 static double plus_zero = 0.0;
173 double minus_zero = - plus_zero;
174 return memcmp (&plus_zero, &minus_zero, sizeof (double)) != 0;
176 static char buf[10000];
177 static double zero = 0.0;
181 if (sprintf (buf, "%f", 1.0 / zero) < 0
182 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
184 if (sprintf (buf, "%f", -1.0 / zero) < 0
185 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
187 if (sprintf (buf, "%f", zero / zero) < 0
188 || !strisnan (buf, 0, strlen (buf)))
190 if (sprintf (buf, "%e", 1.0 / zero) < 0
191 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
193 if (sprintf (buf, "%e", -1.0 / zero) < 0
194 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
196 if (sprintf (buf, "%e", zero / zero) < 0
197 || !strisnan (buf, 0, strlen (buf)))
199 if (sprintf (buf, "%g", 1.0 / zero) < 0
200 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
202 if (sprintf (buf, "%g", -1.0 / zero) < 0
203 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
205 if (sprintf (buf, "%g", zero / zero) < 0
206 || !strisnan (buf, 0, strlen (buf)))
208 /* This test fails on HP-UX 10.20. */
209 if (have_minus_zero ())
210 if (sprintf (buf, "%g", - zero) < 0
211 || strcmp (buf, "-0") != 0)
215 [gl_cv_func_printf_infinite=yes],
216 [gl_cv_func_printf_infinite=no],
220 # Guess yes on glibc systems.
221 *-gnu*) gl_cv_func_printf_infinite="guessing yes";;
222 # Guess yes on FreeBSD >= 6.
223 freebsd[1-5]*) gl_cv_func_printf_infinite="guessing no";;
224 freebsd* | kfreebsd*) gl_cv_func_printf_infinite="guessing yes";;
225 # Guess yes on Mac OS X >= 10.3.
226 darwin[1-6].*) gl_cv_func_printf_infinite="guessing no";;
227 darwin*) gl_cv_func_printf_infinite="guessing yes";;
228 # Guess yes on HP-UX >= 11.
229 hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite="guessing no";;
230 hpux*) gl_cv_func_printf_infinite="guessing yes";;
231 # Guess yes on NetBSD >= 3.
232 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
233 gl_cv_func_printf_infinite="guessing no";;
234 netbsd*) gl_cv_func_printf_infinite="guessing yes";;
236 beos*) gl_cv_func_printf_infinite="guessing yes";;
237 # If we don't know, assume the worst.
238 *) gl_cv_func_printf_infinite="guessing no";;
245 dnl Test whether the *printf family of functions supports infinite and NaN
246 dnl 'long double' arguments in the %f, %e, %g directives. (ISO C99, POSIX:2001)
247 dnl Result is gl_cv_func_printf_infinite_long_double.
249 AC_DEFUN([gl_PRINTF_INFINITE_LONG_DOUBLE],
251 AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
252 AC_REQUIRE([AC_PROG_CC])
253 AC_REQUIRE([gl_BIGENDIAN])
254 AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
255 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
256 dnl The user can set or unset the variable gl_printf_safe to indicate
257 dnl that he wishes a safe handling of non-IEEE-754 'long double' values.
258 if test -n "$gl_printf_safe"; then
259 AC_DEFINE([CHECK_PRINTF_SAFE], [1],
260 [Define if you wish *printf() functions that have a safe handling of
261 non-IEEE-754 'long double' values.])
263 case "$gl_cv_func_printf_long_double" in
265 AC_CACHE_CHECK([whether printf supports infinite 'long double' arguments],
266 [gl_cv_func_printf_infinite_long_double],
275 strisnan (const char *string, size_t start_index, size_t end_index)
277 if (start_index < end_index)
279 if (string[start_index] == '-')
281 if (start_index + 3 <= end_index
282 && memcmp (string + start_index, "nan", 3) == 0)
285 if (start_index == end_index
286 || (string[start_index] == '(' && string[end_index - 1] == ')'))
292 static char buf[10000];
293 static long double zeroL = 0.0L;
298 if (sprintf (buf, "%Lf", 1.0L / zeroL) < 0
299 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
301 if (sprintf (buf, "%Lf", -1.0L / zeroL) < 0
302 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
304 if (sprintf (buf, "%Lf", zeroL / zeroL) < 0
305 || !strisnan (buf, 0, strlen (buf)))
307 if (sprintf (buf, "%Le", 1.0L / zeroL) < 0
308 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
310 if (sprintf (buf, "%Le", -1.0L / zeroL) < 0
311 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
313 if (sprintf (buf, "%Le", zeroL / zeroL) < 0
314 || !strisnan (buf, 0, strlen (buf)))
316 if (sprintf (buf, "%Lg", 1.0L / zeroL) < 0
317 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
319 if (sprintf (buf, "%Lg", -1.0L / zeroL) < 0
320 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
322 if (sprintf (buf, "%Lg", zeroL / zeroL) < 0
323 || !strisnan (buf, 0, strlen (buf)))
325 #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
326 /* Representation of an 80-bit 'long double' as an initializer for a sequence
327 of 'unsigned int' words. */
328 # ifdef WORDS_BIGENDIAN
329 # define LDBL80_WORDS(exponent,manthi,mantlo) \
330 { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
331 ((unsigned int) (manthi) << 16) | (unsigned int) (mantlo) >> 16), \
332 (unsigned int) (mantlo) << 16 \
335 # define LDBL80_WORDS(exponent,manthi,mantlo) \
336 { mantlo, manthi, exponent }
339 static union { unsigned int word[4]; long double value; } x =
340 { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
341 if (sprintf (buf, "%Lf", x.value) < 0
342 || !strisnan (buf, 0, strlen (buf)))
344 if (sprintf (buf, "%Le", x.value) < 0
345 || !strisnan (buf, 0, strlen (buf)))
347 if (sprintf (buf, "%Lg", x.value) < 0
348 || !strisnan (buf, 0, strlen (buf)))
352 /* Signalling NaN. */
353 static union { unsigned int word[4]; long double value; } x =
354 { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
355 if (sprintf (buf, "%Lf", x.value) < 0
356 || !strisnan (buf, 0, strlen (buf)))
358 if (sprintf (buf, "%Le", x.value) < 0
359 || !strisnan (buf, 0, strlen (buf)))
361 if (sprintf (buf, "%Lg", x.value) < 0
362 || !strisnan (buf, 0, strlen (buf)))
366 static union { unsigned int word[4]; long double value; } x =
367 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
368 if (sprintf (buf, "%Lf", x.value) < 0
369 || !strisnan (buf, 0, strlen (buf)))
371 if (sprintf (buf, "%Le", x.value) < 0
372 || !strisnan (buf, 0, strlen (buf)))
374 if (sprintf (buf, "%Lg", x.value) < 0
375 || !strisnan (buf, 0, strlen (buf)))
378 { /* Pseudo-Infinity. */
379 static union { unsigned int word[4]; long double value; } x =
380 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
381 if (sprintf (buf, "%Lf", x.value) < 0
382 || !strisnan (buf, 0, strlen (buf)))
384 if (sprintf (buf, "%Le", x.value) < 0
385 || !strisnan (buf, 0, strlen (buf)))
387 if (sprintf (buf, "%Lg", x.value) < 0
388 || !strisnan (buf, 0, strlen (buf)))
392 static union { unsigned int word[4]; long double value; } x =
393 { LDBL80_WORDS (0x4004, 0x00000000, 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)))
404 { /* Unnormalized number. */
405 static union { unsigned int word[4]; long double value; } x =
406 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
407 if (sprintf (buf, "%Lf", x.value) < 0
408 || !strisnan (buf, 0, strlen (buf)))
410 if (sprintf (buf, "%Le", x.value) < 0
411 || !strisnan (buf, 0, strlen (buf)))
413 if (sprintf (buf, "%Lg", x.value) < 0
414 || !strisnan (buf, 0, strlen (buf)))
417 { /* Pseudo-Denormal. */
418 static union { unsigned int word[4]; long double value; } x =
419 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
420 if (sprintf (buf, "%Lf", x.value) < 0
421 || !strisnan (buf, 0, strlen (buf)))
423 if (sprintf (buf, "%Le", x.value) < 0
424 || !strisnan (buf, 0, strlen (buf)))
426 if (sprintf (buf, "%Lg", x.value) < 0
427 || !strisnan (buf, 0, strlen (buf)))
433 [gl_cv_func_printf_infinite_long_double=yes],
434 [gl_cv_func_printf_infinite_long_double=no],
438 # Guess no on ia64, x86_64, i386.
439 ia64 | x86_64 | i*86) gl_cv_func_printf_infinite_long_double="guessing no";;
442 # Guess yes on glibc systems.
443 *-gnu*) gl_cv_func_printf_infinite_long_double="guessing yes";;
444 # Guess yes on FreeBSD >= 6.
445 freebsd[1-5]*) gl_cv_func_printf_infinite_long_double="guessing no";;
446 freebsd* | kfreebsd*) gl_cv_func_printf_infinite_long_double="guessing yes";;
447 # Guess yes on HP-UX >= 11.
448 hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite_long_double="guessing no";;
449 hpux*) gl_cv_func_printf_infinite_long_double="guessing yes";;
450 # If we don't know, assume the worst.
451 *) gl_cv_func_printf_infinite_long_double="guessing no";;
460 gl_cv_func_printf_infinite_long_double="irrelevant"
465 dnl Test whether the *printf family of functions supports the 'a' and 'A'
466 dnl conversion specifier for hexadecimal output of floating-point numbers.
467 dnl (ISO C99, POSIX:2001)
468 dnl Result is gl_cv_func_printf_directive_a.
470 AC_DEFUN([gl_PRINTF_DIRECTIVE_A],
472 AC_REQUIRE([AC_PROG_CC])
473 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
474 AC_CACHE_CHECK([whether printf supports the 'a' and 'A' directives],
475 [gl_cv_func_printf_directive_a],
481 static char buf[100];
482 static double zero = 0.0;
486 if (sprintf (buf, "%a %d", 3.1416015625, 33, 44, 55) < 0
487 || (strcmp (buf, "0x1.922p+1 33") != 0
488 && strcmp (buf, "0x3.244p+0 33") != 0
489 && strcmp (buf, "0x6.488p-1 33") != 0
490 && strcmp (buf, "0xc.91p-2 33") != 0))
492 if (sprintf (buf, "%A %d", -3.1416015625, 33, 44, 55) < 0
493 || (strcmp (buf, "-0X1.922P+1 33") != 0
494 && strcmp (buf, "-0X3.244P+0 33") != 0
495 && strcmp (buf, "-0X6.488P-1 33") != 0
496 && strcmp (buf, "-0XC.91P-2 33") != 0))
498 /* This catches a FreeBSD 6.1 bug: it doesn't round. */
499 if (sprintf (buf, "%.2a %d", 1.51, 33, 44, 55) < 0
500 || (strcmp (buf, "0x1.83p+0 33") != 0
501 && strcmp (buf, "0x3.05p-1 33") != 0
502 && strcmp (buf, "0x6.0ap-2 33") != 0
503 && strcmp (buf, "0xc.14p-3 33") != 0))
505 /* This catches a FreeBSD 6.1 bug. See
506 <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
507 if (sprintf (buf, "%010a %d", 1.0 / zero, 33, 44, 55) < 0
510 /* This catches a Mac OS X 10.3.9 (Darwin 7.9) bug. */
511 if (sprintf (buf, "%.1a", 1.999) < 0
512 || (strcmp (buf, "0x1.0p+1") != 0
513 && strcmp (buf, "0x2.0p+0") != 0
514 && strcmp (buf, "0x4.0p-1") != 0
515 && strcmp (buf, "0x8.0p-2") != 0))
517 /* This catches the same Mac OS X 10.3.9 (Darwin 7.9) bug and also a
518 glibc 2.4 bug <http://sourceware.org/bugzilla/show_bug.cgi?id=2908>. */
519 if (sprintf (buf, "%.1La", 1.999L) < 0
520 || (strcmp (buf, "0x1.0p+1") != 0
521 && strcmp (buf, "0x2.0p+0") != 0
522 && strcmp (buf, "0x4.0p-1") != 0
523 && strcmp (buf, "0x8.0p-2") != 0))
527 [gl_cv_func_printf_directive_a=yes],
528 [gl_cv_func_printf_directive_a=no],
531 # Guess yes on glibc >= 2.5 systems.
533 AC_EGREP_CPP([BZ2908], [
534 #include <features.h>
535 #ifdef __GNU_LIBRARY__
536 #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 5) || (__GLIBC__ > 2)) && !defined __UCLIBC__
541 [gl_cv_func_printf_directive_a="guessing yes"],
542 [gl_cv_func_printf_directive_a="guessing no"])
544 # If we don't know, assume the worst.
545 *) gl_cv_func_printf_directive_a="guessing no";;
551 dnl Test whether the *printf family of functions supports the %F format
552 dnl directive. (ISO C99, POSIX:2001)
553 dnl Result is gl_cv_func_printf_directive_f.
555 AC_DEFUN([gl_PRINTF_DIRECTIVE_F],
557 AC_REQUIRE([AC_PROG_CC])
558 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
559 AC_CACHE_CHECK([whether printf supports the 'F' directive],
560 [gl_cv_func_printf_directive_f],
566 static char buf[100];
567 static double zero = 0.0;
571 if (sprintf (buf, "%F %d", 1234567.0, 33, 44, 55) < 0
572 || strcmp (buf, "1234567.000000 33") != 0)
574 if (sprintf (buf, "%F", 1.0 / zero) < 0
575 || (strcmp (buf, "INF") != 0 && strcmp (buf, "INFINITY") != 0))
577 /* This catches a Cygwin 1.5.x bug. */
578 if (sprintf (buf, "%.F", 1234.0) < 0
579 || strcmp (buf, "1234") != 0)
583 [gl_cv_func_printf_directive_f=yes],
584 [gl_cv_func_printf_directive_f=no],
588 # Guess yes on glibc systems.
589 *-gnu*) gl_cv_func_printf_directive_f="guessing yes";;
590 # Guess yes on FreeBSD >= 6.
591 freebsd[1-5]*) gl_cv_func_printf_directive_f="guessing no";;
592 freebsd* | kfreebsd*) gl_cv_func_printf_directive_f="guessing yes";;
593 # Guess yes on Mac OS X >= 10.3.
594 darwin[1-6].*) gl_cv_func_printf_directive_f="guessing no";;
595 darwin*) gl_cv_func_printf_directive_f="guessing yes";;
596 # Guess yes on Solaris >= 2.10.
597 solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";;
598 solaris*) gl_cv_func_printf_sizes_c99="guessing no";;
599 # If we don't know, assume the worst.
600 *) gl_cv_func_printf_directive_f="guessing no";;
607 dnl Test whether the *printf family of functions supports the %n format
608 dnl directive. (ISO C99, POSIX:2001)
609 dnl Result is gl_cv_func_printf_directive_n.
611 AC_DEFUN([gl_PRINTF_DIRECTIVE_N],
613 AC_REQUIRE([AC_PROG_CC])
614 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
615 AC_CACHE_CHECK([whether printf supports the 'n' directive],
616 [gl_cv_func_printf_directive_n],
624 /* See page about "Parameter Validation" on msdn.microsoft.com. */
626 invalid_parameter_handler (const wchar_t *expression,
627 const wchar_t *function,
628 const wchar_t *file, unsigned int line,
634 static char fmtstring[10];
635 static char buf[100];
640 _set_invalid_parameter_handler (invalid_parameter_handler);
642 /* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2)
643 support %n in format strings in read-only memory but not in writable
645 strcpy (fmtstring, "%d %n");
646 if (sprintf (buf, fmtstring, 123, &count, 33, 44, 55) < 0
647 || strcmp (buf, "123 ") != 0
652 [gl_cv_func_printf_directive_n=yes],
653 [gl_cv_func_printf_directive_n=no],
657 mingw*) gl_cv_func_printf_directive_n="guessing no";;
658 *) gl_cv_func_printf_directive_n="guessing yes";;
665 dnl Test whether the *printf family of functions supports the %ls format
666 dnl directive and in particular, when a precision is specified, whether
667 dnl the functions stop converting the wide string argument when the number
668 dnl of bytes that have been produced by this conversion equals or exceeds
670 dnl Result is gl_cv_func_printf_directive_ls.
672 AC_DEFUN([gl_PRINTF_DIRECTIVE_LS],
674 AC_REQUIRE([AC_PROG_CC])
675 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
676 AC_CACHE_CHECK([whether printf supports the 'ls' directive],
677 [gl_cv_func_printf_directive_ls],
681 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
683 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
684 included before <wchar.h>. */
694 /* Test whether %ls works at all.
695 This test fails on OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku, but not on
698 static const wchar_t wstring[] = { 'a', 'b', 'c', 0 };
700 if (sprintf (buf, "%ls", wstring) < 0
701 || strcmp (buf, "abc") != 0)
704 /* This test fails on IRIX 6.5, Solaris 2.6, Cygwin 1.5, Haiku (with an
705 assertion failure inside libc), but not on OpenBSD 4.0. */
707 static const wchar_t wstring[] = { 'a', 0 };
709 if (sprintf (buf, "%ls", wstring) < 0
710 || strcmp (buf, "a") != 0)
713 /* Test whether precisions in %ls are supported as specified in ISO C 99
715 "If a precision is specified, no more than that many bytes are written
716 (including shift sequences, if any), and the array shall contain a
717 null wide character if, to equal the multibyte character sequence
718 length given by the precision, the function would need to access a
719 wide character one past the end of the array."
720 This test fails on Solaris 10. */
722 static const wchar_t wstring[] = { 'a', 'b', (wchar_t) 0xfdfdfdfd, 0 };
724 if (sprintf (buf, "%.2ls", wstring) < 0
725 || strcmp (buf, "ab") != 0)
730 [gl_cv_func_printf_directive_ls=yes],
731 [gl_cv_func_printf_directive_ls=no],
735 openbsd*) gl_cv_func_printf_directive_ls="guessing no";;
736 irix*) gl_cv_func_printf_directive_ls="guessing no";;
737 solaris*) gl_cv_func_printf_directive_ls="guessing no";;
738 cygwin*) gl_cv_func_printf_directive_ls="guessing no";;
739 beos* | haiku*) gl_cv_func_printf_directive_ls="guessing no";;
740 *) gl_cv_func_printf_directive_ls="guessing yes";;
747 dnl Test whether the *printf family of functions supports POSIX/XSI format
748 dnl strings with positions. (POSIX:2001)
749 dnl Result is gl_cv_func_printf_positions.
751 AC_DEFUN([gl_PRINTF_POSITIONS],
753 AC_REQUIRE([AC_PROG_CC])
754 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
755 AC_CACHE_CHECK([whether printf supports POSIX/XSI format strings with positions],
756 [gl_cv_func_printf_positions],
762 /* The string "%2$d %1$d", with dollar characters protected from the shell's
763 dollar expansion (possibly an autoconf bug). */
764 static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' };
765 static char buf[100];
768 sprintf (buf, format, 33, 55);
769 return (strcmp (buf, "55 33") != 0);
771 [gl_cv_func_printf_positions=yes],
772 [gl_cv_func_printf_positions=no],
776 netbsd[1-3]* | netbsdelf[1-3]* | netbsdaout[1-3]* | netbsdcoff[1-3]*)
777 gl_cv_func_printf_positions="guessing no";;
778 beos*) gl_cv_func_printf_positions="guessing no";;
779 mingw* | pw*) gl_cv_func_printf_positions="guessing no";;
780 *) gl_cv_func_printf_positions="guessing yes";;
787 dnl Test whether the *printf family of functions supports POSIX/XSI format
788 dnl strings with the ' flag for grouping of decimal digits. (POSIX:2001)
789 dnl Result is gl_cv_func_printf_flag_grouping.
791 AC_DEFUN([gl_PRINTF_FLAG_GROUPING],
793 AC_REQUIRE([AC_PROG_CC])
794 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
795 AC_CACHE_CHECK([whether printf supports the grouping flag],
796 [gl_cv_func_printf_flag_grouping],
802 static char buf[100];
805 if (sprintf (buf, "%'d %d", 1234567, 99) < 0
806 || buf[strlen (buf) - 1] != '9')
810 [gl_cv_func_printf_flag_grouping=yes],
811 [gl_cv_func_printf_flag_grouping=no],
815 cygwin*) gl_cv_func_printf_flag_grouping="guessing no";;
816 netbsd*) gl_cv_func_printf_flag_grouping="guessing no";;
817 mingw* | pw*) gl_cv_func_printf_flag_grouping="guessing no";;
818 *) gl_cv_func_printf_flag_grouping="guessing yes";;
825 dnl Test whether the *printf family of functions supports the - flag correctly.
827 dnl <http://lists.gnu.org/archive/html/bug-coreutils/2008-02/msg00035.html>
828 dnl Result is gl_cv_func_printf_flag_leftadjust.
830 AC_DEFUN([gl_PRINTF_FLAG_LEFTADJUST],
832 AC_REQUIRE([AC_PROG_CC])
833 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
834 AC_CACHE_CHECK([whether printf supports the left-adjust flag correctly],
835 [gl_cv_func_printf_flag_leftadjust],
841 static char buf[100];
844 /* Check that a '-' flag is not annihilated by a negative width. */
845 if (sprintf (buf, "a%-*sc", -3, "b") < 0
846 || strcmp (buf, "ab c") != 0)
850 [gl_cv_func_printf_flag_leftadjust=yes],
851 [gl_cv_func_printf_flag_leftadjust=no],
855 # Guess yes on HP-UX 11.
856 hpux11*) gl_cv_func_printf_flag_leftadjust="guessing yes";;
857 # Guess no on HP-UX 10 and older.
858 hpux*) gl_cv_func_printf_flag_leftadjust="guessing no";;
859 # Guess yes otherwise.
860 *) gl_cv_func_printf_flag_leftadjust="guessing yes";;
867 dnl Test whether the *printf family of functions supports padding of non-finite
868 dnl values with the 0 flag correctly. (ISO C99 + TC1 + TC2.) See
869 dnl <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html>
870 dnl Result is gl_cv_func_printf_flag_zero.
872 AC_DEFUN([gl_PRINTF_FLAG_ZERO],
874 AC_REQUIRE([AC_PROG_CC])
875 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
876 AC_CACHE_CHECK([whether printf supports the zero flag correctly],
877 [gl_cv_func_printf_flag_zero],
883 static char buf[100];
884 static double zero = 0.0;
887 if (sprintf (buf, "%010f", 1.0 / zero, 33, 44, 55) < 0
888 || (strcmp (buf, " inf") != 0
889 && strcmp (buf, " infinity") != 0))
893 [gl_cv_func_printf_flag_zero=yes],
894 [gl_cv_func_printf_flag_zero=no],
898 # Guess yes on glibc systems.
899 *-gnu*) gl_cv_func_printf_flag_zero="guessing yes";;
901 beos*) gl_cv_func_printf_flag_zero="guessing yes";;
902 # If we don't know, assume the worst.
903 *) gl_cv_func_printf_flag_zero="guessing no";;
910 dnl Test whether the *printf family of functions supports large precisions.
911 dnl On mingw, precisions larger than 512 are treated like 512, in integer,
912 dnl floating-point or pointer output. On Solaris 10/x86, precisions larger
913 dnl than 510 in floating-point output crash the program. On Solaris 10/SPARC,
914 dnl precisions larger than 510 in floating-point output yield wrong results.
915 dnl On AIX 7.1, precisions larger than 998 in floating-point output yield
916 dnl wrong results. On BeOS, precisions larger than 1044 crash the program.
917 dnl Result is gl_cv_func_printf_precision.
919 AC_DEFUN([gl_PRINTF_PRECISION],
921 AC_REQUIRE([AC_PROG_CC])
922 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
923 AC_CACHE_CHECK([whether printf supports large precisions],
924 [gl_cv_func_printf_precision],
930 static char buf[5000];
935 /* On BeOS, this would crash and show a dialog box. Avoid the crash. */
938 if (sprintf (buf, "%.4000d %d", 1, 33, 44) < 4000 + 3)
940 if (sprintf (buf, "%.4000f %d", 1.0, 33, 44) < 4000 + 5)
942 if (sprintf (buf, "%.511f %d", 1.0, 33, 44) < 511 + 5
945 if (sprintf (buf, "%.999f %d", 1.0, 33, 44) < 999 + 5
950 [gl_cv_func_printf_precision=yes],
951 [gl_cv_func_printf_precision=no],
955 # Guess no only on Solaris, native Windows, and BeOS systems.
956 solaris*) gl_cv_func_printf_precision="guessing no" ;;
957 mingw* | pw*) gl_cv_func_printf_precision="guessing no" ;;
958 beos*) gl_cv_func_printf_precision="guessing no" ;;
959 *) gl_cv_func_printf_precision="guessing yes" ;;
966 dnl Test whether the *printf family of functions recovers gracefully in case
967 dnl of an out-of-memory condition, or whether it crashes the entire program.
968 dnl Result is gl_cv_func_printf_enomem.
970 AC_DEFUN([gl_PRINTF_ENOMEM],
972 AC_REQUIRE([AC_PROG_CC])
973 AC_REQUIRE([gl_MULTIARCH])
974 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
975 AC_CACHE_CHECK([whether printf survives out-of-memory conditions],
976 [gl_cv_func_printf_enomem],
978 gl_cv_func_printf_enomem="guessing no"
979 if test "$cross_compiling" = no; then
980 if test $APPLE_UNIVERSAL_BUILD = 0; then
981 AC_LANG_CONFTEST([AC_LANG_SOURCE([
985 #include <sys/types.h>
986 #include <sys/time.h>
987 #include <sys/resource.h>
994 /* Some printf implementations allocate temporary space with malloc. */
995 /* On BSD systems, malloc() is limited by RLIMIT_DATA. */
997 if (getrlimit (RLIMIT_DATA, &limit) < 0)
999 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
1000 limit.rlim_max = 5000000;
1001 limit.rlim_cur = limit.rlim_max;
1002 if (setrlimit (RLIMIT_DATA, &limit) < 0)
1005 /* On Linux systems, malloc() is limited by RLIMIT_AS. */
1007 if (getrlimit (RLIMIT_AS, &limit) < 0)
1009 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
1010 limit.rlim_max = 5000000;
1011 limit.rlim_cur = limit.rlim_max;
1012 if (setrlimit (RLIMIT_AS, &limit) < 0)
1015 /* Some printf implementations allocate temporary space on the stack. */
1017 if (getrlimit (RLIMIT_STACK, &limit) < 0)
1019 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
1020 limit.rlim_max = 5000000;
1021 limit.rlim_cur = limit.rlim_max;
1022 if (setrlimit (RLIMIT_STACK, &limit) < 0)
1025 ret = printf ("%.5000000f", 1.0);
1026 return !(ret == 5000002 || (ret < 0 && errno == ENOMEM));
1030 if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
1031 (./conftest 2>&AS_MESSAGE_LOG_FD
1033 _AS_ECHO_LOG([\$? = $result])
1034 if test $result != 0 && test $result != 77; then result=1; fi
1036 ) >/dev/null 2>/dev/null
1038 0) gl_cv_func_printf_enomem="yes" ;;
1039 77) gl_cv_func_printf_enomem="guessing no" ;;
1040 *) gl_cv_func_printf_enomem="no" ;;
1043 gl_cv_func_printf_enomem="guessing no"
1047 dnl A universal build on Apple Mac OS X platforms.
1048 dnl The result would be 'no' in 32-bit mode and 'yes' in 64-bit mode.
1049 dnl But we need a configuration result that is valid in both modes.
1050 gl_cv_func_printf_enomem="guessing no"
1053 if test "$gl_cv_func_printf_enomem" = "guessing no"; then
1056 # Guess yes on glibc systems.
1057 *-gnu*) gl_cv_func_printf_enomem="guessing yes";;
1058 # Guess yes on Solaris.
1059 solaris*) gl_cv_func_printf_enomem="guessing yes";;
1061 aix*) gl_cv_func_printf_enomem="guessing yes";;
1062 # Guess yes on HP-UX/hppa.
1063 hpux*) case "$host_cpu" in
1064 hppa*) gl_cv_func_printf_enomem="guessing yes";;
1065 *) gl_cv_func_printf_enomem="guessing no";;
1068 # Guess yes on IRIX.
1069 irix*) gl_cv_func_printf_enomem="guessing yes";;
1070 # Guess yes on OSF/1.
1071 osf*) gl_cv_func_printf_enomem="guessing yes";;
1072 # Guess yes on BeOS.
1073 beos*) gl_cv_func_printf_enomem="guessing yes";;
1074 # Guess yes on Haiku.
1075 haiku*) gl_cv_func_printf_enomem="guessing yes";;
1076 # If we don't know, assume the worst.
1077 *) gl_cv_func_printf_enomem="guessing no";;
1084 dnl Test whether the snprintf function exists. (ISO C99, POSIX:2001)
1085 dnl Result is ac_cv_func_snprintf.
1087 AC_DEFUN([gl_SNPRINTF_PRESENCE],
1089 AC_CHECK_FUNCS_ONCE([snprintf])
1092 dnl Test whether the string produced by the snprintf function is always NUL
1093 dnl terminated. (ISO C99, POSIX:2001)
1094 dnl Result is gl_cv_func_snprintf_truncation_c99.
1096 AC_DEFUN([gl_SNPRINTF_TRUNCATION_C99],
1098 AC_REQUIRE([AC_PROG_CC])
1099 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1100 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1101 AC_CACHE_CHECK([whether snprintf truncates the result as in C99],
1102 [gl_cv_func_snprintf_truncation_c99],
1109 # define my_snprintf snprintf
1111 # include <stdarg.h>
1112 static int my_snprintf (char *buf, int size, const char *format, ...)
1116 va_start (args, format);
1117 ret = vsnprintf (buf, size, format, args);
1122 static char buf[100];
1125 strcpy (buf, "ABCDEF");
1126 my_snprintf (buf, 3, "%d %d", 4567, 89);
1127 if (memcmp (buf, "45\0DEF", 6) != 0)
1131 [gl_cv_func_snprintf_truncation_c99=yes],
1132 [gl_cv_func_snprintf_truncation_c99=no],
1136 # Guess yes on glibc systems.
1137 *-gnu*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1138 # Guess yes on FreeBSD >= 5.
1139 freebsd[1-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1140 freebsd* | kfreebsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1141 # Guess yes on Mac OS X >= 10.3.
1142 darwin[1-6].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1143 darwin*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1144 # Guess yes on OpenBSD >= 3.9.
1145 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
1146 gl_cv_func_snprintf_truncation_c99="guessing no";;
1147 openbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1148 # Guess yes on Solaris >= 2.6.
1149 solaris2.[0-5] | solaris2.[0-5].*)
1150 gl_cv_func_snprintf_truncation_c99="guessing no";;
1151 solaris*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1152 # Guess yes on AIX >= 4.
1153 aix[1-3]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1154 aix*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1155 # Guess yes on HP-UX >= 11.
1156 hpux[7-9]* | hpux10*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1157 hpux*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1158 # Guess yes on IRIX >= 6.5.
1159 irix6.5) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1160 # Guess yes on OSF/1 >= 5.
1161 osf[3-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1162 osf*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1163 # Guess yes on NetBSD >= 3.
1164 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1165 gl_cv_func_snprintf_truncation_c99="guessing no";;
1166 netbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1167 # Guess yes on BeOS.
1168 beos*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1169 # If we don't know, assume the worst.
1170 *) gl_cv_func_snprintf_truncation_c99="guessing no";;
1177 dnl Test whether the return value of the snprintf function is the number
1178 dnl of bytes (excluding the terminating NUL) that would have been produced
1179 dnl if the buffer had been large enough. (ISO C99, POSIX:2001)
1180 dnl For example, this test program fails on IRIX 6.5:
1181 dnl ---------------------------------------------------------------------
1182 dnl #include <stdio.h>
1185 dnl static char buf[8];
1186 dnl int retval = snprintf (buf, 3, "%d", 12345);
1187 dnl return retval >= 0 && retval < 3;
1189 dnl ---------------------------------------------------------------------
1190 dnl Result is gl_cv_func_snprintf_retval_c99.
1192 AC_DEFUN_ONCE([gl_SNPRINTF_RETVAL_C99],
1194 AC_REQUIRE([AC_PROG_CC])
1195 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1196 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1197 AC_CACHE_CHECK([whether snprintf returns a byte count as in C99],
1198 [gl_cv_func_snprintf_retval_c99],
1205 # define my_snprintf snprintf
1207 # include <stdarg.h>
1208 static int my_snprintf (char *buf, int size, const char *format, ...)
1212 va_start (args, format);
1213 ret = vsnprintf (buf, size, format, args);
1218 static char buf[100];
1221 strcpy (buf, "ABCDEF");
1222 if (my_snprintf (buf, 3, "%d %d", 4567, 89) != 7)
1224 if (my_snprintf (buf, 0, "%d %d", 4567, 89) != 7)
1226 if (my_snprintf (NULL, 0, "%d %d", 4567, 89) != 7)
1230 [gl_cv_func_snprintf_retval_c99=yes],
1231 [gl_cv_func_snprintf_retval_c99=no],
1235 # Guess yes on glibc systems.
1236 *-gnu*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1237 # Guess yes on FreeBSD >= 5.
1238 freebsd[1-4]*) gl_cv_func_snprintf_retval_c99="guessing no";;
1239 freebsd* | kfreebsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1240 # Guess yes on Mac OS X >= 10.3.
1241 darwin[1-6].*) gl_cv_func_snprintf_retval_c99="guessing no";;
1242 darwin*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1243 # Guess yes on OpenBSD >= 3.9.
1244 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
1245 gl_cv_func_snprintf_retval_c99="guessing no";;
1246 openbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1247 # Guess yes on Solaris >= 2.10.
1248 solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";;
1249 solaris*) gl_cv_func_printf_sizes_c99="guessing no";;
1250 # Guess yes on AIX >= 4.
1251 aix[1-3]*) gl_cv_func_snprintf_retval_c99="guessing no";;
1252 aix*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1253 # Guess yes on NetBSD >= 3.
1254 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1255 gl_cv_func_snprintf_retval_c99="guessing no";;
1256 netbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1257 # Guess yes on BeOS.
1258 beos*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1259 # If we don't know, assume the worst.
1260 *) gl_cv_func_snprintf_retval_c99="guessing no";;
1267 dnl Test whether the snprintf function supports the %n format directive
1268 dnl also in truncated portions of the format string. (ISO C99, POSIX:2001)
1269 dnl Result is gl_cv_func_snprintf_directive_n.
1271 AC_DEFUN([gl_SNPRINTF_DIRECTIVE_N],
1273 AC_REQUIRE([AC_PROG_CC])
1274 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1275 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1276 AC_CACHE_CHECK([whether snprintf fully supports the 'n' directive],
1277 [gl_cv_func_snprintf_directive_n],
1284 # define my_snprintf snprintf
1286 # include <stdarg.h>
1287 static int my_snprintf (char *buf, int size, const char *format, ...)
1291 va_start (args, format);
1292 ret = vsnprintf (buf, size, format, args);
1297 static char fmtstring[10];
1298 static char buf[100];
1302 /* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2)
1303 support %n in format strings in read-only memory but not in writable
1305 strcpy (fmtstring, "%d %n");
1306 my_snprintf (buf, 4, fmtstring, 12345, &count, 33, 44, 55);
1311 [gl_cv_func_snprintf_directive_n=yes],
1312 [gl_cv_func_snprintf_directive_n=no],
1316 # Guess yes on glibc systems.
1317 *-gnu*) gl_cv_func_snprintf_directive_n="guessing yes";;
1318 # Guess yes on FreeBSD >= 5.
1319 freebsd[1-4]*) gl_cv_func_snprintf_directive_n="guessing no";;
1320 freebsd* | kfreebsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
1321 # Guess yes on Mac OS X >= 10.3.
1322 darwin[1-6].*) gl_cv_func_snprintf_directive_n="guessing no";;
1323 darwin*) gl_cv_func_snprintf_directive_n="guessing yes";;
1324 # Guess yes on Solaris >= 2.6.
1325 solaris2.[0-5] | solaris2.[0-5].*)
1326 gl_cv_func_snprintf_directive_n="guessing no";;
1327 solaris*) gl_cv_func_snprintf_directive_n="guessing yes";;
1328 # Guess yes on AIX >= 4.
1329 aix[1-3]*) gl_cv_func_snprintf_directive_n="guessing no";;
1330 aix*) gl_cv_func_snprintf_directive_n="guessing yes";;
1331 # Guess yes on IRIX >= 6.5.
1332 irix6.5) gl_cv_func_snprintf_directive_n="guessing yes";;
1333 # Guess yes on OSF/1 >= 5.
1334 osf[3-4]*) gl_cv_func_snprintf_directive_n="guessing no";;
1335 osf*) gl_cv_func_snprintf_directive_n="guessing yes";;
1336 # Guess yes on NetBSD >= 3.
1337 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1338 gl_cv_func_snprintf_directive_n="guessing no";;
1339 netbsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
1340 # Guess yes on BeOS.
1341 beos*) gl_cv_func_snprintf_directive_n="guessing yes";;
1342 # If we don't know, assume the worst.
1343 *) gl_cv_func_snprintf_directive_n="guessing no";;
1350 dnl Test whether the snprintf function, when passed a size = 1, writes any
1351 dnl output without bounds in this case, behaving like sprintf. This is the
1352 dnl case on Linux libc5.
1353 dnl Result is gl_cv_func_snprintf_size1.
1355 AC_DEFUN([gl_SNPRINTF_SIZE1],
1357 AC_REQUIRE([AC_PROG_CC])
1358 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1359 AC_CACHE_CHECK([whether snprintf respects a size of 1],
1360 [gl_cv_func_snprintf_size1],
1366 # define my_snprintf snprintf
1368 # include <stdarg.h>
1369 static int my_snprintf (char *buf, int size, const char *format, ...)
1373 va_start (args, format);
1374 ret = vsnprintf (buf, size, format, args);
1381 static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1382 my_snprintf (buf, 1, "%d", 12345);
1383 return buf[1] != 'E';
1385 [gl_cv_func_snprintf_size1=yes],
1386 [gl_cv_func_snprintf_size1=no],
1387 [gl_cv_func_snprintf_size1="guessing yes"])
1391 dnl Test whether the vsnprintf function, when passed a zero size, produces no
1392 dnl output. (ISO C99, POSIX:2001)
1393 dnl For example, snprintf nevertheless writes a NUL byte in this case
1395 dnl ---------------------------------------------------------------------
1396 dnl #include <stdio.h>
1399 dnl static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1400 dnl snprintf (buf, 0, "%d", 12345);
1401 dnl return buf[0] != 'D';
1403 dnl ---------------------------------------------------------------------
1404 dnl And vsnprintf writes any output without bounds in this case, behaving like
1405 dnl vsprintf, on HP-UX 11 and OSF/1 5.1:
1406 dnl ---------------------------------------------------------------------
1407 dnl #include <stdarg.h>
1408 dnl #include <stdio.h>
1409 dnl static int my_snprintf (char *buf, int size, const char *format, ...)
1413 dnl va_start (args, format);
1414 dnl ret = vsnprintf (buf, size, format, args);
1420 dnl static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1421 dnl my_snprintf (buf, 0, "%d", 12345);
1422 dnl return buf[0] != 'D';
1424 dnl ---------------------------------------------------------------------
1425 dnl Result is gl_cv_func_vsnprintf_zerosize_c99.
1427 AC_DEFUN([gl_VSNPRINTF_ZEROSIZE_C99],
1429 AC_REQUIRE([AC_PROG_CC])
1430 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1431 AC_CACHE_CHECK([whether vsnprintf respects a zero size as in C99],
1432 [gl_cv_func_vsnprintf_zerosize_c99],
1438 static int my_snprintf (char *buf, int size, const char *format, ...)
1442 va_start (args, format);
1443 ret = vsnprintf (buf, size, format, args);
1449 static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1450 my_snprintf (buf, 0, "%d", 12345);
1451 return buf[0] != 'D';
1453 [gl_cv_func_vsnprintf_zerosize_c99=yes],
1454 [gl_cv_func_vsnprintf_zerosize_c99=no],
1458 # Guess yes on glibc systems.
1459 *-gnu*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1460 # Guess yes on FreeBSD >= 5.
1461 freebsd[1-4]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1462 freebsd* | kfreebsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1463 # Guess yes on Mac OS X >= 10.3.
1464 darwin[1-6].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1465 darwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1466 # Guess yes on Cygwin.
1467 cygwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1468 # Guess yes on Solaris >= 2.6.
1469 solaris2.[0-5] | solaris2.[0-5].*)
1470 gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1471 solaris*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1472 # Guess yes on AIX >= 4.
1473 aix[1-3]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1474 aix*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1475 # Guess yes on IRIX >= 6.5.
1476 irix6.5) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1477 # Guess yes on NetBSD >= 3.
1478 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1479 gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1480 netbsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1481 # Guess yes on BeOS.
1482 beos*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1483 # Guess yes on mingw.
1484 mingw* | pw*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1485 # If we don't know, assume the worst.
1486 *) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1493 dnl The results of these tests on various platforms are:
1495 dnl 1 = gl_PRINTF_SIZES_C99
1496 dnl 2 = gl_PRINTF_LONG_DOUBLE
1497 dnl 3 = gl_PRINTF_INFINITE
1498 dnl 4 = gl_PRINTF_INFINITE_LONG_DOUBLE
1499 dnl 5 = gl_PRINTF_DIRECTIVE_A
1500 dnl 6 = gl_PRINTF_DIRECTIVE_F
1501 dnl 7 = gl_PRINTF_DIRECTIVE_N
1502 dnl 8 = gl_PRINTF_DIRECTIVE_LS
1503 dnl 9 = gl_PRINTF_POSITIONS
1504 dnl 10 = gl_PRINTF_FLAG_GROUPING
1505 dnl 11 = gl_PRINTF_FLAG_LEFTADJUST
1506 dnl 12 = gl_PRINTF_FLAG_ZERO
1507 dnl 13 = gl_PRINTF_PRECISION
1508 dnl 14 = gl_PRINTF_ENOMEM
1509 dnl 15 = gl_SNPRINTF_PRESENCE
1510 dnl 16 = gl_SNPRINTF_TRUNCATION_C99
1511 dnl 17 = gl_SNPRINTF_RETVAL_C99
1512 dnl 18 = gl_SNPRINTF_DIRECTIVE_N
1513 dnl 19 = gl_SNPRINTF_SIZE1
1514 dnl 20 = gl_VSNPRINTF_ZEROSIZE_C99
1516 dnl 1 = checking whether printf supports size specifiers as in C99...
1517 dnl 2 = checking whether printf supports 'long double' arguments...
1518 dnl 3 = checking whether printf supports infinite 'double' arguments...
1519 dnl 4 = checking whether printf supports infinite 'long double' arguments...
1520 dnl 5 = checking whether printf supports the 'a' and 'A' directives...
1521 dnl 6 = checking whether printf supports the 'F' directive...
1522 dnl 7 = checking whether printf supports the 'n' directive...
1523 dnl 8 = checking whether printf supports the 'ls' directive...
1524 dnl 9 = checking whether printf supports POSIX/XSI format strings with positions...
1525 dnl 10 = checking whether printf supports the grouping flag...
1526 dnl 11 = checking whether printf supports the left-adjust flag correctly...
1527 dnl 12 = checking whether printf supports the zero flag correctly...
1528 dnl 13 = checking whether printf supports large precisions...
1529 dnl 14 = checking whether printf survives out-of-memory conditions...
1530 dnl 15 = checking for snprintf...
1531 dnl 16 = checking whether snprintf truncates the result as in C99...
1532 dnl 17 = checking whether snprintf returns a byte count as in C99...
1533 dnl 18 = checking whether snprintf fully supports the 'n' directive...
1534 dnl 19 = checking whether snprintf respects a size of 1...
1535 dnl 20 = checking whether vsnprintf respects a zero size as in C99...
1537 dnl . = yes, # = no.
1539 dnl 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1540 dnl glibc 2.5 . . . . . . . . . . . . . . . . . . . .
1541 dnl glibc 2.3.6 . . . . # . . . . . . . . . . . . . . .
1542 dnl FreeBSD 5.4, 6.1 . . . . # . . . . . . # . # . . . . . .
1543 dnl Mac OS X 10.5.8 . . . # # . . . . . . # . . . . . . . .
1544 dnl Mac OS X 10.3.9 . . . . # . . . . . . # . # . . . . . .
1545 dnl OpenBSD 3.9, 4.0 . . # # # # . # . # . # . # . . . . . .
1546 dnl Cygwin 1.7.0 (2009) . . . # . . . ? . . . . . ? . . . . . .
1547 dnl Cygwin 1.5.25 (2008) . . . # # . . # . . . . . # . . . . . .
1548 dnl Cygwin 1.5.19 (2006) # . . # # # . # . # . # # # . . . . . .
1549 dnl Solaris 11 2011-11 . . # # # . . # . . . # . . . . . . . .
1550 dnl Solaris 10 . . # # # . . # . . . # # . . . . . . .
1551 dnl Solaris 2.6 ... 9 # . # # # # . # . . . # # . . . # . . .
1552 dnl Solaris 2.5.1 # . # # # # . # . . . # . . # # # # # #
1553 dnl AIX 7.1 . . # # # . . . . . . # # . . . . . . .
1554 dnl AIX 5.2 . . # # # . . . . . . # . . . . . . . .
1555 dnl AIX 4.3.2, 5.1 # . # # # # . . . . . # . . . . # . . .
1556 dnl HP-UX 11.31 . . . . # . . . . . . # . . . . # # . .
1557 dnl HP-UX 11.{00,11,23} # . . . # # . . . . . # . . . . # # . #
1558 dnl HP-UX 10.20 # . # . # # . ? . . # # . . . . # # ? #
1559 dnl IRIX 6.5 # . # # # # . # . . . # . . . . # . . .
1560 dnl OSF/1 5.1 # . # # # # . . . . . # . . . . # . . #
1561 dnl OSF/1 4.0d # . # # # # . . . . . # . . # # # # # #
1562 dnl NetBSD 5.0 . . . # # . . . . . . # . # . . . . . .
1563 dnl NetBSD 4.0 . ? ? ? ? ? . ? . ? ? ? ? ? . . . ? ? ?
1564 dnl NetBSD 3.0 . . . . # # . ? # # ? # . # . . . . . .
1565 dnl Haiku . . . # # # . # . . . . . ? . . ? . . .
1566 dnl BeOS # # . # # # . ? # . ? . # ? . . ? . . .
1567 dnl old mingw / msvcrt # # # # # # . . # # . # # ? . # # # . .
1568 dnl MSVC 9 # # # # # # # . # # . # # ? # # # # . .
1569 dnl mingw 2009-2011 . # . # . . . . # # . . . ? . . . . . .
1570 dnl mingw-w64 2011 # # # # # # . . # # . # # ? . # # # . .