2 dnl Copyright (C) 2003, 2007-2015 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)
370 if (sprintf (buf, "%Le", x.value) <= 0)
372 if (sprintf (buf, "%Lg", x.value) <= 0)
375 { /* Pseudo-Infinity. */
376 static union { unsigned int word[4]; long double value; } x =
377 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
378 if (sprintf (buf, "%Lf", x.value) <= 0)
380 if (sprintf (buf, "%Le", x.value) <= 0)
382 if (sprintf (buf, "%Lg", x.value) <= 0)
386 static union { unsigned int word[4]; long double value; } x =
387 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
388 if (sprintf (buf, "%Lf", x.value) <= 0)
390 if (sprintf (buf, "%Le", x.value) <= 0)
392 if (sprintf (buf, "%Lg", x.value) <= 0)
395 { /* Unnormalized number. */
396 static union { unsigned int word[4]; long double value; } x =
397 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
398 if (sprintf (buf, "%Lf", x.value) <= 0)
400 if (sprintf (buf, "%Le", x.value) <= 0)
402 if (sprintf (buf, "%Lg", x.value) <= 0)
405 { /* Pseudo-Denormal. */
406 static union { unsigned int word[4]; long double value; } x =
407 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
408 if (sprintf (buf, "%Lf", x.value) <= 0)
410 if (sprintf (buf, "%Le", x.value) <= 0)
412 if (sprintf (buf, "%Lg", x.value) <= 0)
418 [gl_cv_func_printf_infinite_long_double=yes],
419 [gl_cv_func_printf_infinite_long_double=no],
423 # Guess no on ia64, x86_64, i386.
424 ia64 | x86_64 | i*86) gl_cv_func_printf_infinite_long_double="guessing no";;
427 # Guess yes on glibc systems.
428 *-gnu*) gl_cv_func_printf_infinite_long_double="guessing yes";;
429 # Guess yes on FreeBSD >= 6.
430 freebsd[1-5].*) gl_cv_func_printf_infinite_long_double="guessing no";;
431 freebsd* | kfreebsd*) gl_cv_func_printf_infinite_long_double="guessing yes";;
432 # Guess yes on HP-UX >= 11.
433 hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite_long_double="guessing no";;
434 hpux*) gl_cv_func_printf_infinite_long_double="guessing yes";;
435 # If we don't know, assume the worst.
436 *) gl_cv_func_printf_infinite_long_double="guessing no";;
445 gl_cv_func_printf_infinite_long_double="irrelevant"
450 dnl Test whether the *printf family of functions supports the 'a' and 'A'
451 dnl conversion specifier for hexadecimal output of floating-point numbers.
452 dnl (ISO C99, POSIX:2001)
453 dnl Result is gl_cv_func_printf_directive_a.
455 AC_DEFUN([gl_PRINTF_DIRECTIVE_A],
457 AC_REQUIRE([AC_PROG_CC])
458 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
459 AC_CACHE_CHECK([whether printf supports the 'a' and 'A' directives],
460 [gl_cv_func_printf_directive_a],
466 static char buf[100];
467 static double zero = 0.0;
471 if (sprintf (buf, "%a %d", 3.1416015625, 33, 44, 55) < 0
472 || (strcmp (buf, "0x1.922p+1 33") != 0
473 && strcmp (buf, "0x3.244p+0 33") != 0
474 && strcmp (buf, "0x6.488p-1 33") != 0
475 && strcmp (buf, "0xc.91p-2 33") != 0))
477 if (sprintf (buf, "%A %d", -3.1416015625, 33, 44, 55) < 0
478 || (strcmp (buf, "-0X1.922P+1 33") != 0
479 && strcmp (buf, "-0X3.244P+0 33") != 0
480 && strcmp (buf, "-0X6.488P-1 33") != 0
481 && strcmp (buf, "-0XC.91P-2 33") != 0))
483 /* This catches a FreeBSD 6.1 bug: it doesn't round. */
484 if (sprintf (buf, "%.2a %d", 1.51, 33, 44, 55) < 0
485 || (strcmp (buf, "0x1.83p+0 33") != 0
486 && strcmp (buf, "0x3.05p-1 33") != 0
487 && strcmp (buf, "0x6.0ap-2 33") != 0
488 && strcmp (buf, "0xc.14p-3 33") != 0))
490 /* This catches a FreeBSD 6.1 bug. See
491 <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
492 if (sprintf (buf, "%010a %d", 1.0 / zero, 33, 44, 55) < 0
495 /* This catches a Mac OS X 10.3.9 (Darwin 7.9) bug. */
496 if (sprintf (buf, "%.1a", 1.999) < 0
497 || (strcmp (buf, "0x1.0p+1") != 0
498 && strcmp (buf, "0x2.0p+0") != 0
499 && strcmp (buf, "0x4.0p-1") != 0
500 && strcmp (buf, "0x8.0p-2") != 0))
502 /* This catches the same Mac OS X 10.3.9 (Darwin 7.9) bug and also a
503 glibc 2.4 bug <http://sourceware.org/bugzilla/show_bug.cgi?id=2908>. */
504 if (sprintf (buf, "%.1La", 1.999L) < 0
505 || (strcmp (buf, "0x1.0p+1") != 0
506 && strcmp (buf, "0x2.0p+0") != 0
507 && strcmp (buf, "0x4.0p-1") != 0
508 && strcmp (buf, "0x8.0p-2") != 0))
512 [gl_cv_func_printf_directive_a=yes],
513 [gl_cv_func_printf_directive_a=no],
516 # Guess yes on glibc >= 2.5 systems.
518 AC_EGREP_CPP([BZ2908], [
519 #include <features.h>
520 #ifdef __GNU_LIBRARY__
521 #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 5) || (__GLIBC__ > 2)) && !defined __UCLIBC__
526 [gl_cv_func_printf_directive_a="guessing yes"],
527 [gl_cv_func_printf_directive_a="guessing no"])
529 # If we don't know, assume the worst.
530 *) gl_cv_func_printf_directive_a="guessing no";;
536 dnl Test whether the *printf family of functions supports the %F format
537 dnl directive. (ISO C99, POSIX:2001)
538 dnl Result is gl_cv_func_printf_directive_f.
540 AC_DEFUN([gl_PRINTF_DIRECTIVE_F],
542 AC_REQUIRE([AC_PROG_CC])
543 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
544 AC_CACHE_CHECK([whether printf supports the 'F' directive],
545 [gl_cv_func_printf_directive_f],
551 static char buf[100];
552 static double zero = 0.0;
556 if (sprintf (buf, "%F %d", 1234567.0, 33, 44, 55) < 0
557 || strcmp (buf, "1234567.000000 33") != 0)
559 if (sprintf (buf, "%F", 1.0 / zero) < 0
560 || (strcmp (buf, "INF") != 0 && strcmp (buf, "INFINITY") != 0))
562 /* This catches a Cygwin 1.5.x bug. */
563 if (sprintf (buf, "%.F", 1234.0) < 0
564 || strcmp (buf, "1234") != 0)
568 [gl_cv_func_printf_directive_f=yes],
569 [gl_cv_func_printf_directive_f=no],
573 # Guess yes on glibc systems.
574 *-gnu*) gl_cv_func_printf_directive_f="guessing yes";;
575 # Guess yes on FreeBSD >= 6.
576 freebsd[1-5].*) gl_cv_func_printf_directive_f="guessing no";;
577 freebsd* | kfreebsd*) gl_cv_func_printf_directive_f="guessing yes";;
578 # Guess yes on Mac OS X >= 10.3.
579 darwin[1-6].*) gl_cv_func_printf_directive_f="guessing no";;
580 darwin*) gl_cv_func_printf_directive_f="guessing yes";;
581 # Guess yes on Solaris >= 2.10.
582 solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";;
583 solaris*) gl_cv_func_printf_sizes_c99="guessing no";;
584 # If we don't know, assume the worst.
585 *) gl_cv_func_printf_directive_f="guessing no";;
592 dnl Test whether the *printf family of functions supports the %n format
593 dnl directive. (ISO C99, POSIX:2001)
594 dnl Result is gl_cv_func_printf_directive_n.
596 AC_DEFUN([gl_PRINTF_DIRECTIVE_N],
598 AC_REQUIRE([AC_PROG_CC])
599 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
600 AC_CACHE_CHECK([whether printf supports the 'n' directive],
601 [gl_cv_func_printf_directive_n],
609 /* See page about "Parameter Validation" on msdn.microsoft.com. */
611 invalid_parameter_handler (const wchar_t *expression,
612 const wchar_t *function,
613 const wchar_t *file, unsigned int line,
619 static char fmtstring[10];
620 static char buf[100];
625 _set_invalid_parameter_handler (invalid_parameter_handler);
627 /* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2)
628 support %n in format strings in read-only memory but not in writable
630 strcpy (fmtstring, "%d %n");
631 if (sprintf (buf, fmtstring, 123, &count, 33, 44, 55) < 0
632 || strcmp (buf, "123 ") != 0
637 [gl_cv_func_printf_directive_n=yes],
638 [gl_cv_func_printf_directive_n=no],
642 mingw*) gl_cv_func_printf_directive_n="guessing no";;
643 *) gl_cv_func_printf_directive_n="guessing yes";;
650 dnl Test whether the *printf family of functions supports the %ls format
651 dnl directive and in particular, when a precision is specified, whether
652 dnl the functions stop converting the wide string argument when the number
653 dnl of bytes that have been produced by this conversion equals or exceeds
655 dnl Result is gl_cv_func_printf_directive_ls.
657 AC_DEFUN([gl_PRINTF_DIRECTIVE_LS],
659 AC_REQUIRE([AC_PROG_CC])
660 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
661 AC_CACHE_CHECK([whether printf supports the 'ls' directive],
662 [gl_cv_func_printf_directive_ls],
666 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
668 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
669 included before <wchar.h>. */
679 /* Test whether %ls works at all.
680 This test fails on OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku, but not on
683 static const wchar_t wstring[] = { 'a', 'b', 'c', 0 };
685 if (sprintf (buf, "%ls", wstring) < 0
686 || strcmp (buf, "abc") != 0)
689 /* This test fails on IRIX 6.5, Solaris 2.6, Cygwin 1.5, Haiku (with an
690 assertion failure inside libc), but not on OpenBSD 4.0. */
692 static const wchar_t wstring[] = { 'a', 0 };
694 if (sprintf (buf, "%ls", wstring) < 0
695 || strcmp (buf, "a") != 0)
698 /* Test whether precisions in %ls are supported as specified in ISO C 99
700 "If a precision is specified, no more than that many bytes are written
701 (including shift sequences, if any), and the array shall contain a
702 null wide character if, to equal the multibyte character sequence
703 length given by the precision, the function would need to access a
704 wide character one past the end of the array."
705 This test fails on Solaris 10. */
707 static const wchar_t wstring[] = { 'a', 'b', (wchar_t) 0xfdfdfdfd, 0 };
709 if (sprintf (buf, "%.2ls", wstring) < 0
710 || strcmp (buf, "ab") != 0)
715 [gl_cv_func_printf_directive_ls=yes],
716 [gl_cv_func_printf_directive_ls=no],
720 openbsd*) gl_cv_func_printf_directive_ls="guessing no";;
721 irix*) gl_cv_func_printf_directive_ls="guessing no";;
722 solaris*) gl_cv_func_printf_directive_ls="guessing no";;
723 cygwin*) gl_cv_func_printf_directive_ls="guessing no";;
724 beos* | haiku*) gl_cv_func_printf_directive_ls="guessing no";;
725 *) gl_cv_func_printf_directive_ls="guessing yes";;
732 dnl Test whether the *printf family of functions supports POSIX/XSI format
733 dnl strings with positions. (POSIX:2001)
734 dnl Result is gl_cv_func_printf_positions.
736 AC_DEFUN([gl_PRINTF_POSITIONS],
738 AC_REQUIRE([AC_PROG_CC])
739 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
740 AC_CACHE_CHECK([whether printf supports POSIX/XSI format strings with positions],
741 [gl_cv_func_printf_positions],
747 /* The string "%2$d %1$d", with dollar characters protected from the shell's
748 dollar expansion (possibly an autoconf bug). */
749 static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' };
750 static char buf[100];
753 sprintf (buf, format, 33, 55);
754 return (strcmp (buf, "55 33") != 0);
756 [gl_cv_func_printf_positions=yes],
757 [gl_cv_func_printf_positions=no],
761 netbsd[1-3]* | netbsdelf[1-3]* | netbsdaout[1-3]* | netbsdcoff[1-3]*)
762 gl_cv_func_printf_positions="guessing no";;
763 beos*) gl_cv_func_printf_positions="guessing no";;
764 mingw* | pw*) gl_cv_func_printf_positions="guessing no";;
765 *) gl_cv_func_printf_positions="guessing yes";;
772 dnl Test whether the *printf family of functions supports POSIX/XSI format
773 dnl strings with the ' flag for grouping of decimal digits. (POSIX:2001)
774 dnl Result is gl_cv_func_printf_flag_grouping.
776 AC_DEFUN([gl_PRINTF_FLAG_GROUPING],
778 AC_REQUIRE([AC_PROG_CC])
779 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
780 AC_CACHE_CHECK([whether printf supports the grouping flag],
781 [gl_cv_func_printf_flag_grouping],
787 static char buf[100];
790 if (sprintf (buf, "%'d %d", 1234567, 99) < 0
791 || buf[strlen (buf) - 1] != '9')
795 [gl_cv_func_printf_flag_grouping=yes],
796 [gl_cv_func_printf_flag_grouping=no],
800 cygwin*) gl_cv_func_printf_flag_grouping="guessing no";;
801 netbsd*) gl_cv_func_printf_flag_grouping="guessing no";;
802 mingw* | pw*) gl_cv_func_printf_flag_grouping="guessing no";;
803 *) gl_cv_func_printf_flag_grouping="guessing yes";;
810 dnl Test whether the *printf family of functions supports the - flag correctly.
812 dnl <http://lists.gnu.org/archive/html/bug-coreutils/2008-02/msg00035.html>
813 dnl Result is gl_cv_func_printf_flag_leftadjust.
815 AC_DEFUN([gl_PRINTF_FLAG_LEFTADJUST],
817 AC_REQUIRE([AC_PROG_CC])
818 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
819 AC_CACHE_CHECK([whether printf supports the left-adjust flag correctly],
820 [gl_cv_func_printf_flag_leftadjust],
826 static char buf[100];
829 /* Check that a '-' flag is not annihilated by a negative width. */
830 if (sprintf (buf, "a%-*sc", -3, "b") < 0
831 || strcmp (buf, "ab c") != 0)
835 [gl_cv_func_printf_flag_leftadjust=yes],
836 [gl_cv_func_printf_flag_leftadjust=no],
840 # Guess yes on HP-UX 11.
841 hpux11*) gl_cv_func_printf_flag_leftadjust="guessing yes";;
842 # Guess no on HP-UX 10 and older.
843 hpux*) gl_cv_func_printf_flag_leftadjust="guessing no";;
844 # Guess yes otherwise.
845 *) gl_cv_func_printf_flag_leftadjust="guessing yes";;
852 dnl Test whether the *printf family of functions supports padding of non-finite
853 dnl values with the 0 flag correctly. (ISO C99 + TC1 + TC2.) See
854 dnl <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html>
855 dnl Result is gl_cv_func_printf_flag_zero.
857 AC_DEFUN([gl_PRINTF_FLAG_ZERO],
859 AC_REQUIRE([AC_PROG_CC])
860 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
861 AC_CACHE_CHECK([whether printf supports the zero flag correctly],
862 [gl_cv_func_printf_flag_zero],
868 static char buf[100];
869 static double zero = 0.0;
872 if (sprintf (buf, "%010f", 1.0 / zero, 33, 44, 55) < 0
873 || (strcmp (buf, " inf") != 0
874 && strcmp (buf, " infinity") != 0))
878 [gl_cv_func_printf_flag_zero=yes],
879 [gl_cv_func_printf_flag_zero=no],
883 # Guess yes on glibc systems.
884 *-gnu*) gl_cv_func_printf_flag_zero="guessing yes";;
886 beos*) gl_cv_func_printf_flag_zero="guessing yes";;
887 # If we don't know, assume the worst.
888 *) gl_cv_func_printf_flag_zero="guessing no";;
895 dnl Test whether the *printf family of functions supports large precisions.
896 dnl On mingw, precisions larger than 512 are treated like 512, in integer,
897 dnl floating-point or pointer output. On Solaris 10/x86, precisions larger
898 dnl than 510 in floating-point output crash the program. On Solaris 10/SPARC,
899 dnl precisions larger than 510 in floating-point output yield wrong results.
900 dnl On AIX 7.1, precisions larger than 998 in floating-point output yield
901 dnl wrong results. On BeOS, precisions larger than 1044 crash the program.
902 dnl Result is gl_cv_func_printf_precision.
904 AC_DEFUN([gl_PRINTF_PRECISION],
906 AC_REQUIRE([AC_PROG_CC])
907 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
908 AC_CACHE_CHECK([whether printf supports large precisions],
909 [gl_cv_func_printf_precision],
915 static char buf[5000];
920 /* On BeOS, this would crash and show a dialog box. Avoid the crash. */
923 if (sprintf (buf, "%.4000d %d", 1, 33, 44) < 4000 + 3)
925 if (sprintf (buf, "%.4000f %d", 1.0, 33, 44) < 4000 + 5)
927 if (sprintf (buf, "%.511f %d", 1.0, 33, 44) < 511 + 5
930 if (sprintf (buf, "%.999f %d", 1.0, 33, 44) < 999 + 5
935 [gl_cv_func_printf_precision=yes],
936 [gl_cv_func_printf_precision=no],
940 # Guess no only on Solaris, native Windows, and BeOS systems.
941 solaris*) gl_cv_func_printf_precision="guessing no" ;;
942 mingw* | pw*) gl_cv_func_printf_precision="guessing no" ;;
943 beos*) gl_cv_func_printf_precision="guessing no" ;;
944 *) gl_cv_func_printf_precision="guessing yes" ;;
951 dnl Test whether the *printf family of functions recovers gracefully in case
952 dnl of an out-of-memory condition, or whether it crashes the entire program.
953 dnl Result is gl_cv_func_printf_enomem.
955 AC_DEFUN([gl_PRINTF_ENOMEM],
957 AC_REQUIRE([AC_PROG_CC])
958 AC_REQUIRE([gl_MULTIARCH])
959 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
960 AC_CACHE_CHECK([whether printf survives out-of-memory conditions],
961 [gl_cv_func_printf_enomem],
963 gl_cv_func_printf_enomem="guessing no"
964 if test "$cross_compiling" = no; then
965 if test $APPLE_UNIVERSAL_BUILD = 0; then
966 AC_LANG_CONFTEST([AC_LANG_SOURCE([
970 #include <sys/types.h>
971 #include <sys/time.h>
972 #include <sys/resource.h>
979 /* Some printf implementations allocate temporary space with malloc. */
980 /* On BSD systems, malloc() is limited by RLIMIT_DATA. */
982 if (getrlimit (RLIMIT_DATA, &limit) < 0)
984 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
985 limit.rlim_max = 5000000;
986 limit.rlim_cur = limit.rlim_max;
987 if (setrlimit (RLIMIT_DATA, &limit) < 0)
990 /* On Linux systems, malloc() is limited by RLIMIT_AS. */
992 if (getrlimit (RLIMIT_AS, &limit) < 0)
994 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
995 limit.rlim_max = 5000000;
996 limit.rlim_cur = limit.rlim_max;
997 if (setrlimit (RLIMIT_AS, &limit) < 0)
1000 /* Some printf implementations allocate temporary space on the stack. */
1002 if (getrlimit (RLIMIT_STACK, &limit) < 0)
1004 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
1005 limit.rlim_max = 5000000;
1006 limit.rlim_cur = limit.rlim_max;
1007 if (setrlimit (RLIMIT_STACK, &limit) < 0)
1010 ret = printf ("%.5000000f", 1.0);
1011 return !(ret == 5000002 || (ret < 0 && errno == ENOMEM));
1015 if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
1016 (./conftest 2>&AS_MESSAGE_LOG_FD
1018 _AS_ECHO_LOG([\$? = $result])
1019 if test $result != 0 && test $result != 77; then result=1; fi
1021 ) >/dev/null 2>/dev/null
1023 0) gl_cv_func_printf_enomem="yes" ;;
1024 77) gl_cv_func_printf_enomem="guessing no" ;;
1025 *) gl_cv_func_printf_enomem="no" ;;
1028 gl_cv_func_printf_enomem="guessing no"
1032 dnl A universal build on Apple Mac OS X platforms.
1033 dnl The result would be 'no' in 32-bit mode and 'yes' in 64-bit mode.
1034 dnl But we need a configuration result that is valid in both modes.
1035 gl_cv_func_printf_enomem="guessing no"
1038 if test "$gl_cv_func_printf_enomem" = "guessing no"; then
1041 # Guess yes on glibc systems.
1042 *-gnu*) gl_cv_func_printf_enomem="guessing yes";;
1043 # Guess yes on Solaris.
1044 solaris*) gl_cv_func_printf_enomem="guessing yes";;
1046 aix*) gl_cv_func_printf_enomem="guessing yes";;
1047 # Guess yes on HP-UX/hppa.
1048 hpux*) case "$host_cpu" in
1049 hppa*) gl_cv_func_printf_enomem="guessing yes";;
1050 *) gl_cv_func_printf_enomem="guessing no";;
1053 # Guess yes on IRIX.
1054 irix*) gl_cv_func_printf_enomem="guessing yes";;
1055 # Guess yes on OSF/1.
1056 osf*) gl_cv_func_printf_enomem="guessing yes";;
1057 # Guess yes on BeOS.
1058 beos*) gl_cv_func_printf_enomem="guessing yes";;
1059 # Guess yes on Haiku.
1060 haiku*) gl_cv_func_printf_enomem="guessing yes";;
1061 # If we don't know, assume the worst.
1062 *) gl_cv_func_printf_enomem="guessing no";;
1069 dnl Test whether the snprintf function exists. (ISO C99, POSIX:2001)
1070 dnl Result is ac_cv_func_snprintf.
1072 AC_DEFUN([gl_SNPRINTF_PRESENCE],
1074 AC_CHECK_FUNCS_ONCE([snprintf])
1077 dnl Test whether the string produced by the snprintf function is always NUL
1078 dnl terminated. (ISO C99, POSIX:2001)
1079 dnl Result is gl_cv_func_snprintf_truncation_c99.
1081 AC_DEFUN([gl_SNPRINTF_TRUNCATION_C99],
1083 AC_REQUIRE([AC_PROG_CC])
1084 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1085 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1086 AC_CACHE_CHECK([whether snprintf truncates the result as in C99],
1087 [gl_cv_func_snprintf_truncation_c99],
1094 # define my_snprintf snprintf
1096 # include <stdarg.h>
1097 static int my_snprintf (char *buf, int size, const char *format, ...)
1101 va_start (args, format);
1102 ret = vsnprintf (buf, size, format, args);
1107 static char buf[100];
1110 strcpy (buf, "ABCDEF");
1111 my_snprintf (buf, 3, "%d %d", 4567, 89);
1112 if (memcmp (buf, "45\0DEF", 6) != 0)
1116 [gl_cv_func_snprintf_truncation_c99=yes],
1117 [gl_cv_func_snprintf_truncation_c99=no],
1121 # Guess yes on glibc systems.
1122 *-gnu*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1123 # Guess yes on FreeBSD >= 5.
1124 freebsd[1-4].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1125 freebsd* | kfreebsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1126 # Guess yes on Mac OS X >= 10.3.
1127 darwin[1-6].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1128 darwin*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1129 # Guess yes on OpenBSD >= 3.9.
1130 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
1131 gl_cv_func_snprintf_truncation_c99="guessing no";;
1132 openbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1133 # Guess yes on Solaris >= 2.6.
1134 solaris2.[0-5] | solaris2.[0-5].*)
1135 gl_cv_func_snprintf_truncation_c99="guessing no";;
1136 solaris*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1137 # Guess yes on AIX >= 4.
1138 aix[1-3]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1139 aix*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1140 # Guess yes on HP-UX >= 11.
1141 hpux[7-9]* | hpux10*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1142 hpux*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1143 # Guess yes on IRIX >= 6.5.
1144 irix6.5) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1145 # Guess yes on OSF/1 >= 5.
1146 osf[3-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1147 osf*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1148 # Guess yes on NetBSD >= 3.
1149 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1150 gl_cv_func_snprintf_truncation_c99="guessing no";;
1151 netbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1152 # Guess yes on BeOS.
1153 beos*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1154 # If we don't know, assume the worst.
1155 *) gl_cv_func_snprintf_truncation_c99="guessing no";;
1162 dnl Test whether the return value of the snprintf function is the number
1163 dnl of bytes (excluding the terminating NUL) that would have been produced
1164 dnl if the buffer had been large enough. (ISO C99, POSIX:2001)
1165 dnl For example, this test program fails on IRIX 6.5:
1166 dnl ---------------------------------------------------------------------
1167 dnl #include <stdio.h>
1170 dnl static char buf[8];
1171 dnl int retval = snprintf (buf, 3, "%d", 12345);
1172 dnl return retval >= 0 && retval < 3;
1174 dnl ---------------------------------------------------------------------
1175 dnl Result is gl_cv_func_snprintf_retval_c99.
1177 AC_DEFUN_ONCE([gl_SNPRINTF_RETVAL_C99],
1179 AC_REQUIRE([AC_PROG_CC])
1180 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1181 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1182 AC_CACHE_CHECK([whether snprintf returns a byte count as in C99],
1183 [gl_cv_func_snprintf_retval_c99],
1190 # define my_snprintf snprintf
1192 # include <stdarg.h>
1193 static int my_snprintf (char *buf, int size, const char *format, ...)
1197 va_start (args, format);
1198 ret = vsnprintf (buf, size, format, args);
1203 static char buf[100];
1206 strcpy (buf, "ABCDEF");
1207 if (my_snprintf (buf, 3, "%d %d", 4567, 89) != 7)
1209 if (my_snprintf (buf, 0, "%d %d", 4567, 89) != 7)
1211 if (my_snprintf (NULL, 0, "%d %d", 4567, 89) != 7)
1215 [gl_cv_func_snprintf_retval_c99=yes],
1216 [gl_cv_func_snprintf_retval_c99=no],
1220 # Guess yes on glibc systems.
1221 *-gnu*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1222 # Guess yes on FreeBSD >= 5.
1223 freebsd[1-4].*) gl_cv_func_snprintf_retval_c99="guessing no";;
1224 freebsd* | kfreebsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1225 # Guess yes on Mac OS X >= 10.3.
1226 darwin[1-6].*) gl_cv_func_snprintf_retval_c99="guessing no";;
1227 darwin*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1228 # Guess yes on OpenBSD >= 3.9.
1229 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
1230 gl_cv_func_snprintf_retval_c99="guessing no";;
1231 openbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1232 # Guess yes on Solaris >= 2.10.
1233 solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";;
1234 solaris*) gl_cv_func_printf_sizes_c99="guessing no";;
1235 # Guess yes on AIX >= 4.
1236 aix[1-3]*) gl_cv_func_snprintf_retval_c99="guessing no";;
1237 aix*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1238 # Guess yes on NetBSD >= 3.
1239 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1240 gl_cv_func_snprintf_retval_c99="guessing no";;
1241 netbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1242 # Guess yes on BeOS.
1243 beos*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1244 # If we don't know, assume the worst.
1245 *) gl_cv_func_snprintf_retval_c99="guessing no";;
1252 dnl Test whether the snprintf function supports the %n format directive
1253 dnl also in truncated portions of the format string. (ISO C99, POSIX:2001)
1254 dnl Result is gl_cv_func_snprintf_directive_n.
1256 AC_DEFUN([gl_SNPRINTF_DIRECTIVE_N],
1258 AC_REQUIRE([AC_PROG_CC])
1259 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1260 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1261 AC_CACHE_CHECK([whether snprintf fully supports the 'n' directive],
1262 [gl_cv_func_snprintf_directive_n],
1269 # define my_snprintf snprintf
1271 # include <stdarg.h>
1272 static int my_snprintf (char *buf, int size, const char *format, ...)
1276 va_start (args, format);
1277 ret = vsnprintf (buf, size, format, args);
1282 static char fmtstring[10];
1283 static char buf[100];
1287 /* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2)
1288 support %n in format strings in read-only memory but not in writable
1290 strcpy (fmtstring, "%d %n");
1291 my_snprintf (buf, 4, fmtstring, 12345, &count, 33, 44, 55);
1296 [gl_cv_func_snprintf_directive_n=yes],
1297 [gl_cv_func_snprintf_directive_n=no],
1301 # Guess yes on glibc systems.
1302 *-gnu*) gl_cv_func_snprintf_directive_n="guessing yes";;
1303 # Guess yes on FreeBSD >= 5.
1304 freebsd[1-4].*) gl_cv_func_snprintf_directive_n="guessing no";;
1305 freebsd* | kfreebsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
1306 # Guess yes on Mac OS X >= 10.3.
1307 darwin[1-6].*) gl_cv_func_snprintf_directive_n="guessing no";;
1308 darwin*) gl_cv_func_snprintf_directive_n="guessing yes";;
1309 # Guess yes on Solaris >= 2.6.
1310 solaris2.[0-5] | solaris2.[0-5].*)
1311 gl_cv_func_snprintf_directive_n="guessing no";;
1312 solaris*) gl_cv_func_snprintf_directive_n="guessing yes";;
1313 # Guess yes on AIX >= 4.
1314 aix[1-3]*) gl_cv_func_snprintf_directive_n="guessing no";;
1315 aix*) gl_cv_func_snprintf_directive_n="guessing yes";;
1316 # Guess yes on IRIX >= 6.5.
1317 irix6.5) gl_cv_func_snprintf_directive_n="guessing yes";;
1318 # Guess yes on OSF/1 >= 5.
1319 osf[3-4]*) gl_cv_func_snprintf_directive_n="guessing no";;
1320 osf*) gl_cv_func_snprintf_directive_n="guessing yes";;
1321 # Guess yes on NetBSD >= 3.
1322 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1323 gl_cv_func_snprintf_directive_n="guessing no";;
1324 netbsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
1325 # Guess yes on BeOS.
1326 beos*) gl_cv_func_snprintf_directive_n="guessing yes";;
1327 # If we don't know, assume the worst.
1328 *) gl_cv_func_snprintf_directive_n="guessing no";;
1335 dnl Test whether the snprintf function, when passed a size = 1, writes any
1336 dnl output without bounds in this case, behaving like sprintf. This is the
1337 dnl case on Linux libc5.
1338 dnl Result is gl_cv_func_snprintf_size1.
1340 AC_DEFUN([gl_SNPRINTF_SIZE1],
1342 AC_REQUIRE([AC_PROG_CC])
1343 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1344 AC_CACHE_CHECK([whether snprintf respects a size of 1],
1345 [gl_cv_func_snprintf_size1],
1351 # define my_snprintf snprintf
1353 # include <stdarg.h>
1354 static int my_snprintf (char *buf, int size, const char *format, ...)
1358 va_start (args, format);
1359 ret = vsnprintf (buf, size, format, args);
1366 static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1367 my_snprintf (buf, 1, "%d", 12345);
1368 return buf[1] != 'E';
1370 [gl_cv_func_snprintf_size1=yes],
1371 [gl_cv_func_snprintf_size1=no],
1372 [gl_cv_func_snprintf_size1="guessing yes"])
1376 dnl Test whether the vsnprintf function, when passed a zero size, produces no
1377 dnl output. (ISO C99, POSIX:2001)
1378 dnl For example, snprintf nevertheless writes a NUL byte in this case
1380 dnl ---------------------------------------------------------------------
1381 dnl #include <stdio.h>
1384 dnl static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1385 dnl snprintf (buf, 0, "%d", 12345);
1386 dnl return buf[0] != 'D';
1388 dnl ---------------------------------------------------------------------
1389 dnl And vsnprintf writes any output without bounds in this case, behaving like
1390 dnl vsprintf, on HP-UX 11 and OSF/1 5.1:
1391 dnl ---------------------------------------------------------------------
1392 dnl #include <stdarg.h>
1393 dnl #include <stdio.h>
1394 dnl static int my_snprintf (char *buf, int size, const char *format, ...)
1398 dnl va_start (args, format);
1399 dnl ret = vsnprintf (buf, size, format, args);
1405 dnl static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1406 dnl my_snprintf (buf, 0, "%d", 12345);
1407 dnl return buf[0] != 'D';
1409 dnl ---------------------------------------------------------------------
1410 dnl Result is gl_cv_func_vsnprintf_zerosize_c99.
1412 AC_DEFUN([gl_VSNPRINTF_ZEROSIZE_C99],
1414 AC_REQUIRE([AC_PROG_CC])
1415 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1416 AC_CACHE_CHECK([whether vsnprintf respects a zero size as in C99],
1417 [gl_cv_func_vsnprintf_zerosize_c99],
1423 static int my_snprintf (char *buf, int size, const char *format, ...)
1427 va_start (args, format);
1428 ret = vsnprintf (buf, size, format, args);
1434 static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1435 my_snprintf (buf, 0, "%d", 12345);
1436 return buf[0] != 'D';
1438 [gl_cv_func_vsnprintf_zerosize_c99=yes],
1439 [gl_cv_func_vsnprintf_zerosize_c99=no],
1443 # Guess yes on glibc systems.
1444 *-gnu*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1445 # Guess yes on FreeBSD >= 5.
1446 freebsd[1-4].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1447 freebsd* | kfreebsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1448 # Guess yes on Mac OS X >= 10.3.
1449 darwin[1-6].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1450 darwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1451 # Guess yes on Cygwin.
1452 cygwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1453 # Guess yes on Solaris >= 2.6.
1454 solaris2.[0-5] | solaris2.[0-5].*)
1455 gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1456 solaris*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1457 # Guess yes on AIX >= 4.
1458 aix[1-3]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1459 aix*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1460 # Guess yes on IRIX >= 6.5.
1461 irix6.5) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1462 # Guess yes on NetBSD >= 3.
1463 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1464 gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1465 netbsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1466 # Guess yes on BeOS.
1467 beos*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1468 # Guess yes on mingw.
1469 mingw* | pw*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1470 # If we don't know, assume the worst.
1471 *) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1478 dnl The results of these tests on various platforms are:
1480 dnl 1 = gl_PRINTF_SIZES_C99
1481 dnl 2 = gl_PRINTF_LONG_DOUBLE
1482 dnl 3 = gl_PRINTF_INFINITE
1483 dnl 4 = gl_PRINTF_INFINITE_LONG_DOUBLE
1484 dnl 5 = gl_PRINTF_DIRECTIVE_A
1485 dnl 6 = gl_PRINTF_DIRECTIVE_F
1486 dnl 7 = gl_PRINTF_DIRECTIVE_N
1487 dnl 8 = gl_PRINTF_DIRECTIVE_LS
1488 dnl 9 = gl_PRINTF_POSITIONS
1489 dnl 10 = gl_PRINTF_FLAG_GROUPING
1490 dnl 11 = gl_PRINTF_FLAG_LEFTADJUST
1491 dnl 12 = gl_PRINTF_FLAG_ZERO
1492 dnl 13 = gl_PRINTF_PRECISION
1493 dnl 14 = gl_PRINTF_ENOMEM
1494 dnl 15 = gl_SNPRINTF_PRESENCE
1495 dnl 16 = gl_SNPRINTF_TRUNCATION_C99
1496 dnl 17 = gl_SNPRINTF_RETVAL_C99
1497 dnl 18 = gl_SNPRINTF_DIRECTIVE_N
1498 dnl 19 = gl_SNPRINTF_SIZE1
1499 dnl 20 = gl_VSNPRINTF_ZEROSIZE_C99
1501 dnl 1 = checking whether printf supports size specifiers as in C99...
1502 dnl 2 = checking whether printf supports 'long double' arguments...
1503 dnl 3 = checking whether printf supports infinite 'double' arguments...
1504 dnl 4 = checking whether printf supports infinite 'long double' arguments...
1505 dnl 5 = checking whether printf supports the 'a' and 'A' directives...
1506 dnl 6 = checking whether printf supports the 'F' directive...
1507 dnl 7 = checking whether printf supports the 'n' directive...
1508 dnl 8 = checking whether printf supports the 'ls' directive...
1509 dnl 9 = checking whether printf supports POSIX/XSI format strings with positions...
1510 dnl 10 = checking whether printf supports the grouping flag...
1511 dnl 11 = checking whether printf supports the left-adjust flag correctly...
1512 dnl 12 = checking whether printf supports the zero flag correctly...
1513 dnl 13 = checking whether printf supports large precisions...
1514 dnl 14 = checking whether printf survives out-of-memory conditions...
1515 dnl 15 = checking for snprintf...
1516 dnl 16 = checking whether snprintf truncates the result as in C99...
1517 dnl 17 = checking whether snprintf returns a byte count as in C99...
1518 dnl 18 = checking whether snprintf fully supports the 'n' directive...
1519 dnl 19 = checking whether snprintf respects a size of 1...
1520 dnl 20 = checking whether vsnprintf respects a zero size as in C99...
1522 dnl . = yes, # = no.
1524 dnl 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1525 dnl glibc 2.5 . . . . . . . . . . . . . . . . . . . .
1526 dnl glibc 2.3.6 . . . . # . . . . . . . . . . . . . . .
1527 dnl FreeBSD 5.4, 6.1 . . . . # . . . . . . # . # . . . . . .
1528 dnl Mac OS X 10.5.8 . . . # # . . . . . . # . . . . . . . .
1529 dnl Mac OS X 10.3.9 . . . . # . . . . . . # . # . . . . . .
1530 dnl OpenBSD 3.9, 4.0 . . # # # # . # . # . # . # . . . . . .
1531 dnl Cygwin 1.7.0 (2009) . . . # . . . ? . . . . . ? . . . . . .
1532 dnl Cygwin 1.5.25 (2008) . . . # # . . # . . . . . # . . . . . .
1533 dnl Cygwin 1.5.19 (2006) # . . # # # . # . # . # # # . . . . . .
1534 dnl Solaris 11 2011-11 . . # # # . . # . . . # . . . . . . . .
1535 dnl Solaris 10 . . # # # . . # . . . # # . . . . . . .
1536 dnl Solaris 2.6 ... 9 # . # # # # . # . . . # # . . . # . . .
1537 dnl Solaris 2.5.1 # . # # # # . # . . . # . . # # # # # #
1538 dnl AIX 7.1 . . # # # . . . . . . # # . . . . . . .
1539 dnl AIX 5.2 . . # # # . . . . . . # . . . . . . . .
1540 dnl AIX 4.3.2, 5.1 # . # # # # . . . . . # . . . . # . . .
1541 dnl HP-UX 11.31 . . . . # . . . . . . # . . . . # # . .
1542 dnl HP-UX 11.{00,11,23} # . . . # # . . . . . # . . . . # # . #
1543 dnl HP-UX 10.20 # . # . # # . ? . . # # . . . . # # ? #
1544 dnl IRIX 6.5 # . # # # # . # . . . # . . . . # . . .
1545 dnl OSF/1 5.1 # . # # # # . . . . . # . . . . # . . #
1546 dnl OSF/1 4.0d # . # # # # . . . . . # . . # # # # # #
1547 dnl NetBSD 5.0 . . . # # . . . . . . # . # . . . . . .
1548 dnl NetBSD 4.0 . ? ? ? ? ? . ? . ? ? ? ? ? . . . ? ? ?
1549 dnl NetBSD 3.0 . . . . # # . ? # # ? # . # . . . . . .
1550 dnl Haiku . . . # # # . # . . . . . ? . . ? . . .
1551 dnl BeOS # # . # # # . ? # . ? . # ? . . ? . . .
1552 dnl old mingw / msvcrt # # # # # # . . # # . # # ? . # # # . .
1553 dnl MSVC 9 # # # # # # # . # # . # # ? # # # # . .
1554 dnl mingw 2009-2011 . # . # . . . . # # . . . ? . . . . . .
1555 dnl mingw-w64 2011 # # # # # # . . # # . # # ? . # # # . .