2 dnl Copyright (C) 2003, 2007-2016 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 dnl Test whether the *printf family of functions supports the 'j', 'z', 't',
8 dnl 'L' size specifiers. (ISO C99, POSIX:2001)
9 dnl Result is gl_cv_func_printf_sizes_c99.
11 AC_DEFUN([gl_PRINTF_SIZES_C99],
13 AC_REQUIRE([AC_PROG_CC])
14 AC_REQUIRE([gl_AC_HEADER_STDINT_H])
15 AC_REQUIRE([gl_AC_HEADER_INTTYPES_H])
16 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
17 AC_CACHE_CHECK([whether printf supports size specifiers as in C99],
18 [gl_cv_func_printf_sizes_c99],
25 #include <sys/types.h>
26 #if HAVE_STDINT_H_WITH_UINTMAX
29 #if HAVE_INTTYPES_H_WITH_UINTMAX
30 # include <inttypes.h>
36 #if HAVE_STDINT_H_WITH_UINTMAX || HAVE_INTTYPES_H_WITH_UINTMAX
38 if (sprintf (buf, "%ju %d", (uintmax_t) 12345671, 33, 44, 55) < 0
39 || strcmp (buf, "12345671 33") != 0)
45 if (sprintf (buf, "%zu %d", (size_t) 12345672, 33, 44, 55) < 0
46 || strcmp (buf, "12345672 33") != 0)
49 if (sprintf (buf, "%tu %d", (ptrdiff_t) 12345673, 33, 44, 55) < 0
50 || strcmp (buf, "12345673 33") != 0)
53 if (sprintf (buf, "%Lg %d", (long double) 1.5, 33, 44, 55) < 0
54 || strcmp (buf, "1.5 33") != 0)
58 [gl_cv_func_printf_sizes_c99=yes],
59 [gl_cv_func_printf_sizes_c99=no],
63 # Guess yes on glibc systems.
64 *-gnu*) gl_cv_func_printf_sizes_c99="guessing yes";;
65 # Guess yes on FreeBSD >= 5.
66 freebsd[1-4].*) gl_cv_func_printf_sizes_c99="guessing no";;
67 freebsd* | kfreebsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
68 # Guess yes on Mac OS X >= 10.3.
69 darwin[1-6].*) gl_cv_func_printf_sizes_c99="guessing no";;
70 darwin*) gl_cv_func_printf_sizes_c99="guessing yes";;
71 # Guess yes on OpenBSD >= 3.9.
72 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
73 gl_cv_func_printf_sizes_c99="guessing no";;
74 openbsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
75 # Guess yes on Solaris >= 2.10.
76 solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";;
77 solaris*) gl_cv_func_printf_sizes_c99="guessing no";;
78 # Guess yes on NetBSD >= 3.
79 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
80 gl_cv_func_printf_sizes_c99="guessing no";;
81 netbsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
82 # If we don't know, assume the worst.
83 *) gl_cv_func_printf_sizes_c99="guessing no";;
90 dnl Test whether the *printf family of functions supports 'long double'
91 dnl arguments together with the 'L' size specifier. (ISO C99, POSIX:2001)
92 dnl Result is gl_cv_func_printf_long_double.
94 AC_DEFUN([gl_PRINTF_LONG_DOUBLE],
96 AC_REQUIRE([AC_PROG_CC])
97 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
98 AC_CACHE_CHECK([whether printf supports 'long double' arguments],
99 [gl_cv_func_printf_long_double],
105 static char buf[10000];
110 if (sprintf (buf, "%Lf %d", 1.75L, 33, 44, 55) < 0
111 || strcmp (buf, "1.750000 33") != 0)
114 if (sprintf (buf, "%Le %d", 1.75L, 33, 44, 55) < 0
115 || strcmp (buf, "1.750000e+00 33") != 0)
118 if (sprintf (buf, "%Lg %d", 1.75L, 33, 44, 55) < 0
119 || strcmp (buf, "1.75 33") != 0)
123 [gl_cv_func_printf_long_double=yes],
124 [gl_cv_func_printf_long_double=no],
128 beos*) gl_cv_func_printf_long_double="guessing no";;
129 mingw* | pw*) gl_cv_func_printf_long_double="guessing no";;
130 *) gl_cv_func_printf_long_double="guessing yes";;
137 dnl Test whether the *printf family of functions supports infinite and NaN
138 dnl 'double' arguments and negative zero arguments in the %f, %e, %g
139 dnl directives. (ISO C99, POSIX:2001)
140 dnl Result is gl_cv_func_printf_infinite.
142 AC_DEFUN([gl_PRINTF_INFINITE],
144 AC_REQUIRE([AC_PROG_CC])
145 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
146 AC_CACHE_CHECK([whether printf supports infinite 'double' arguments],
147 [gl_cv_func_printf_infinite],
154 strisnan (const char *string, size_t start_index, size_t end_index)
156 if (start_index < end_index)
158 if (string[start_index] == '-')
160 if (start_index + 3 <= end_index
161 && memcmp (string + start_index, "nan", 3) == 0)
164 if (start_index == end_index
165 || (string[start_index] == '(' && string[end_index - 1] == ')'))
174 static double plus_zero = 0.0;
175 double minus_zero = - plus_zero;
176 return memcmp (&plus_zero, &minus_zero, sizeof (double)) != 0;
178 static char buf[10000];
179 static double zero = 0.0;
183 if (sprintf (buf, "%f", 1.0 / zero) < 0
184 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
186 if (sprintf (buf, "%f", -1.0 / zero) < 0
187 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
189 if (sprintf (buf, "%f", zero / zero) < 0
190 || !strisnan (buf, 0, strlen (buf)))
192 if (sprintf (buf, "%e", 1.0 / zero) < 0
193 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
195 if (sprintf (buf, "%e", -1.0 / zero) < 0
196 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
198 if (sprintf (buf, "%e", zero / zero) < 0
199 || !strisnan (buf, 0, strlen (buf)))
201 if (sprintf (buf, "%g", 1.0 / zero) < 0
202 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
204 if (sprintf (buf, "%g", -1.0 / zero) < 0
205 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
207 if (sprintf (buf, "%g", zero / zero) < 0
208 || !strisnan (buf, 0, strlen (buf)))
210 /* This test fails on HP-UX 10.20. */
211 if (have_minus_zero ())
212 if (sprintf (buf, "%g", - zero) < 0
213 || strcmp (buf, "-0") != 0)
217 [gl_cv_func_printf_infinite=yes],
218 [gl_cv_func_printf_infinite=no],
222 # Guess yes on glibc systems.
223 *-gnu*) gl_cv_func_printf_infinite="guessing yes";;
224 # Guess yes on FreeBSD >= 6.
225 freebsd[1-5].*) gl_cv_func_printf_infinite="guessing no";;
226 freebsd* | kfreebsd*) gl_cv_func_printf_infinite="guessing yes";;
227 # Guess yes on Mac OS X >= 10.3.
228 darwin[1-6].*) gl_cv_func_printf_infinite="guessing no";;
229 darwin*) gl_cv_func_printf_infinite="guessing yes";;
230 # Guess yes on HP-UX >= 11.
231 hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite="guessing no";;
232 hpux*) gl_cv_func_printf_infinite="guessing yes";;
233 # Guess yes on NetBSD >= 3.
234 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
235 gl_cv_func_printf_infinite="guessing no";;
236 netbsd*) gl_cv_func_printf_infinite="guessing yes";;
238 beos*) gl_cv_func_printf_infinite="guessing yes";;
239 # If we don't know, assume the worst.
240 *) gl_cv_func_printf_infinite="guessing no";;
247 dnl Test whether the *printf family of functions supports infinite and NaN
248 dnl 'long double' arguments in the %f, %e, %g directives. (ISO C99, POSIX:2001)
249 dnl Result is gl_cv_func_printf_infinite_long_double.
251 AC_DEFUN([gl_PRINTF_INFINITE_LONG_DOUBLE],
253 AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
254 AC_REQUIRE([AC_PROG_CC])
255 AC_REQUIRE([gl_BIGENDIAN])
256 AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
257 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
258 dnl The user can set or unset the variable gl_printf_safe to indicate
259 dnl that he wishes a safe handling of non-IEEE-754 'long double' values.
260 if test -n "$gl_printf_safe"; then
261 AC_DEFINE([CHECK_PRINTF_SAFE], [1],
262 [Define if you wish *printf() functions that have a safe handling of
263 non-IEEE-754 'long double' values.])
265 case "$gl_cv_func_printf_long_double" in
267 AC_CACHE_CHECK([whether printf supports infinite 'long double' arguments],
268 [gl_cv_func_printf_infinite_long_double],
277 strisnan (const char *string, size_t start_index, size_t end_index)
279 if (start_index < end_index)
281 if (string[start_index] == '-')
283 if (start_index + 3 <= end_index
284 && memcmp (string + start_index, "nan", 3) == 0)
287 if (start_index == end_index
288 || (string[start_index] == '(' && string[end_index - 1] == ')'))
294 static char buf[10000];
295 static long double zeroL = 0.0L;
300 if (sprintf (buf, "%Lf", 1.0L / zeroL) < 0
301 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
303 if (sprintf (buf, "%Lf", -1.0L / zeroL) < 0
304 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
306 if (sprintf (buf, "%Lf", zeroL / zeroL) < 0
307 || !strisnan (buf, 0, strlen (buf)))
309 if (sprintf (buf, "%Le", 1.0L / zeroL) < 0
310 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
312 if (sprintf (buf, "%Le", -1.0L / zeroL) < 0
313 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
315 if (sprintf (buf, "%Le", zeroL / zeroL) < 0
316 || !strisnan (buf, 0, strlen (buf)))
318 if (sprintf (buf, "%Lg", 1.0L / zeroL) < 0
319 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
321 if (sprintf (buf, "%Lg", -1.0L / zeroL) < 0
322 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
324 if (sprintf (buf, "%Lg", zeroL / zeroL) < 0
325 || !strisnan (buf, 0, strlen (buf)))
327 #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
328 /* Representation of an 80-bit 'long double' as an initializer for a sequence
329 of 'unsigned int' words. */
330 # ifdef WORDS_BIGENDIAN
331 # define LDBL80_WORDS(exponent,manthi,mantlo) \
332 { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
333 ((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16), \
334 (unsigned int) (mantlo) << 16 \
337 # define LDBL80_WORDS(exponent,manthi,mantlo) \
338 { mantlo, manthi, exponent }
341 static union { unsigned int word[4]; long double value; } x =
342 { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
343 if (sprintf (buf, "%Lf", x.value) < 0
344 || !strisnan (buf, 0, strlen (buf)))
346 if (sprintf (buf, "%Le", x.value) < 0
347 || !strisnan (buf, 0, strlen (buf)))
349 if (sprintf (buf, "%Lg", x.value) < 0
350 || !strisnan (buf, 0, strlen (buf)))
354 /* Signalling NaN. */
355 static union { unsigned int word[4]; long double value; } x =
356 { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
357 if (sprintf (buf, "%Lf", x.value) < 0
358 || !strisnan (buf, 0, strlen (buf)))
360 if (sprintf (buf, "%Le", x.value) < 0
361 || !strisnan (buf, 0, strlen (buf)))
363 if (sprintf (buf, "%Lg", x.value) < 0
364 || !strisnan (buf, 0, strlen (buf)))
368 static union { unsigned int word[4]; long double value; } x =
369 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
370 if (sprintf (buf, "%Lf", x.value) <= 0)
372 if (sprintf (buf, "%Le", x.value) <= 0)
374 if (sprintf (buf, "%Lg", x.value) <= 0)
377 { /* Pseudo-Infinity. */
378 static union { unsigned int word[4]; long double value; } x =
379 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
380 if (sprintf (buf, "%Lf", x.value) <= 0)
382 if (sprintf (buf, "%Le", x.value) <= 0)
384 if (sprintf (buf, "%Lg", x.value) <= 0)
388 static union { unsigned int word[4]; long double value; } x =
389 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
390 if (sprintf (buf, "%Lf", x.value) <= 0)
392 if (sprintf (buf, "%Le", x.value) <= 0)
394 if (sprintf (buf, "%Lg", x.value) <= 0)
397 { /* Unnormalized number. */
398 static union { unsigned int word[4]; long double value; } x =
399 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
400 if (sprintf (buf, "%Lf", x.value) <= 0)
402 if (sprintf (buf, "%Le", x.value) <= 0)
404 if (sprintf (buf, "%Lg", x.value) <= 0)
407 { /* Pseudo-Denormal. */
408 static union { unsigned int word[4]; long double value; } x =
409 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
410 if (sprintf (buf, "%Lf", x.value) <= 0)
412 if (sprintf (buf, "%Le", x.value) <= 0)
414 if (sprintf (buf, "%Lg", x.value) <= 0)
420 [gl_cv_func_printf_infinite_long_double=yes],
421 [gl_cv_func_printf_infinite_long_double=no],
425 # Guess no on ia64, x86_64, i386.
426 ia64 | x86_64 | i*86) gl_cv_func_printf_infinite_long_double="guessing no";;
429 # Guess yes on glibc systems.
430 *-gnu*) gl_cv_func_printf_infinite_long_double="guessing yes";;
431 # Guess yes on FreeBSD >= 6.
432 freebsd[1-5].*) gl_cv_func_printf_infinite_long_double="guessing no";;
433 freebsd* | kfreebsd*) gl_cv_func_printf_infinite_long_double="guessing yes";;
434 # Guess yes on HP-UX >= 11.
435 hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite_long_double="guessing no";;
436 hpux*) gl_cv_func_printf_infinite_long_double="guessing yes";;
437 # If we don't know, assume the worst.
438 *) gl_cv_func_printf_infinite_long_double="guessing no";;
447 gl_cv_func_printf_infinite_long_double="irrelevant"
452 dnl Test whether the *printf family of functions supports the 'a' and 'A'
453 dnl conversion specifier for hexadecimal output of floating-point numbers.
454 dnl (ISO C99, POSIX:2001)
455 dnl Result is gl_cv_func_printf_directive_a.
457 AC_DEFUN([gl_PRINTF_DIRECTIVE_A],
459 AC_REQUIRE([AC_PROG_CC])
460 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
461 AC_CACHE_CHECK([whether printf supports the 'a' and 'A' directives],
462 [gl_cv_func_printf_directive_a],
468 static char buf[100];
469 static double zero = 0.0;
473 if (sprintf (buf, "%a %d", 3.1416015625, 33, 44, 55) < 0
474 || (strcmp (buf, "0x1.922p+1 33") != 0
475 && strcmp (buf, "0x3.244p+0 33") != 0
476 && strcmp (buf, "0x6.488p-1 33") != 0
477 && strcmp (buf, "0xc.91p-2 33") != 0))
479 if (sprintf (buf, "%A %d", -3.1416015625, 33, 44, 55) < 0
480 || (strcmp (buf, "-0X1.922P+1 33") != 0
481 && strcmp (buf, "-0X3.244P+0 33") != 0
482 && strcmp (buf, "-0X6.488P-1 33") != 0
483 && strcmp (buf, "-0XC.91P-2 33") != 0))
485 /* This catches a FreeBSD 6.1 bug: it doesn't round. */
486 if (sprintf (buf, "%.2a %d", 1.51, 33, 44, 55) < 0
487 || (strcmp (buf, "0x1.83p+0 33") != 0
488 && strcmp (buf, "0x3.05p-1 33") != 0
489 && strcmp (buf, "0x6.0ap-2 33") != 0
490 && strcmp (buf, "0xc.14p-3 33") != 0))
492 /* This catches a FreeBSD 6.1 bug. See
493 <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
494 if (sprintf (buf, "%010a %d", 1.0 / zero, 33, 44, 55) < 0
497 /* This catches a Mac OS X 10.3.9 (Darwin 7.9) bug. */
498 if (sprintf (buf, "%.1a", 1.999) < 0
499 || (strcmp (buf, "0x1.0p+1") != 0
500 && strcmp (buf, "0x2.0p+0") != 0
501 && strcmp (buf, "0x4.0p-1") != 0
502 && strcmp (buf, "0x8.0p-2") != 0))
504 /* This catches the same Mac OS X 10.3.9 (Darwin 7.9) bug and also a
505 glibc 2.4 bug <http://sourceware.org/bugzilla/show_bug.cgi?id=2908>. */
506 if (sprintf (buf, "%.1La", 1.999L) < 0
507 || (strcmp (buf, "0x1.0p+1") != 0
508 && strcmp (buf, "0x2.0p+0") != 0
509 && strcmp (buf, "0x4.0p-1") != 0
510 && strcmp (buf, "0x8.0p-2") != 0))
514 [gl_cv_func_printf_directive_a=yes],
515 [gl_cv_func_printf_directive_a=no],
518 # Guess yes on glibc >= 2.5 systems.
520 AC_EGREP_CPP([BZ2908], [
521 #include <features.h>
522 #ifdef __GNU_LIBRARY__
523 #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 5) || (__GLIBC__ > 2)) && !defined __UCLIBC__
528 [gl_cv_func_printf_directive_a="guessing yes"],
529 [gl_cv_func_printf_directive_a="guessing no"])
531 # If we don't know, assume the worst.
532 *) gl_cv_func_printf_directive_a="guessing no";;
538 dnl Test whether the *printf family of functions supports the %F format
539 dnl directive. (ISO C99, POSIX:2001)
540 dnl Result is gl_cv_func_printf_directive_f.
542 AC_DEFUN([gl_PRINTF_DIRECTIVE_F],
544 AC_REQUIRE([AC_PROG_CC])
545 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
546 AC_CACHE_CHECK([whether printf supports the 'F' directive],
547 [gl_cv_func_printf_directive_f],
553 static char buf[100];
554 static double zero = 0.0;
558 if (sprintf (buf, "%F %d", 1234567.0, 33, 44, 55) < 0
559 || strcmp (buf, "1234567.000000 33") != 0)
561 if (sprintf (buf, "%F", 1.0 / zero) < 0
562 || (strcmp (buf, "INF") != 0 && strcmp (buf, "INFINITY") != 0))
564 /* This catches a Cygwin 1.5.x bug. */
565 if (sprintf (buf, "%.F", 1234.0) < 0
566 || strcmp (buf, "1234") != 0)
570 [gl_cv_func_printf_directive_f=yes],
571 [gl_cv_func_printf_directive_f=no],
575 # Guess yes on glibc systems.
576 *-gnu*) gl_cv_func_printf_directive_f="guessing yes";;
577 # Guess yes on FreeBSD >= 6.
578 freebsd[1-5].*) gl_cv_func_printf_directive_f="guessing no";;
579 freebsd* | kfreebsd*) gl_cv_func_printf_directive_f="guessing yes";;
580 # Guess yes on Mac OS X >= 10.3.
581 darwin[1-6].*) gl_cv_func_printf_directive_f="guessing no";;
582 darwin*) gl_cv_func_printf_directive_f="guessing yes";;
583 # Guess yes on Solaris >= 2.10.
584 solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";;
585 solaris*) gl_cv_func_printf_sizes_c99="guessing no";;
586 # If we don't know, assume the worst.
587 *) gl_cv_func_printf_directive_f="guessing no";;
594 dnl Test whether the *printf family of functions supports the %n format
595 dnl directive. (ISO C99, POSIX:2001)
596 dnl Result is gl_cv_func_printf_directive_n.
598 AC_DEFUN([gl_PRINTF_DIRECTIVE_N],
600 AC_REQUIRE([AC_PROG_CC])
601 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
602 AC_CACHE_CHECK([whether printf supports the 'n' directive],
603 [gl_cv_func_printf_directive_n],
611 /* See page about "Parameter Validation" on msdn.microsoft.com. */
613 invalid_parameter_handler (const wchar_t *expression,
614 const wchar_t *function,
615 const wchar_t *file, unsigned int line,
621 static char fmtstring[10];
622 static char buf[100];
627 _set_invalid_parameter_handler (invalid_parameter_handler);
629 /* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2)
630 support %n in format strings in read-only memory but not in writable
632 strcpy (fmtstring, "%d %n");
633 if (sprintf (buf, fmtstring, 123, &count, 33, 44, 55) < 0
634 || strcmp (buf, "123 ") != 0
639 [gl_cv_func_printf_directive_n=yes],
640 [gl_cv_func_printf_directive_n=no],
644 mingw*) gl_cv_func_printf_directive_n="guessing no";;
645 *) gl_cv_func_printf_directive_n="guessing yes";;
652 dnl Test whether the *printf family of functions supports the %ls format
653 dnl directive and in particular, when a precision is specified, whether
654 dnl the functions stop converting the wide string argument when the number
655 dnl of bytes that have been produced by this conversion equals or exceeds
657 dnl Result is gl_cv_func_printf_directive_ls.
659 AC_DEFUN([gl_PRINTF_DIRECTIVE_LS],
661 AC_REQUIRE([AC_PROG_CC])
662 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
663 AC_CACHE_CHECK([whether printf supports the 'ls' directive],
664 [gl_cv_func_printf_directive_ls],
668 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
670 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
671 included before <wchar.h>. */
681 /* Test whether %ls works at all.
682 This test fails on OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku, but not on
685 static const wchar_t wstring[] = { 'a', 'b', 'c', 0 };
687 if (sprintf (buf, "%ls", wstring) < 0
688 || strcmp (buf, "abc") != 0)
691 /* This test fails on IRIX 6.5, Solaris 2.6, Cygwin 1.5, Haiku (with an
692 assertion failure inside libc), but not on OpenBSD 4.0. */
694 static const wchar_t wstring[] = { 'a', 0 };
696 if (sprintf (buf, "%ls", wstring) < 0
697 || strcmp (buf, "a") != 0)
700 /* Test whether precisions in %ls are supported as specified in ISO C 99
702 "If a precision is specified, no more than that many bytes are written
703 (including shift sequences, if any), and the array shall contain a
704 null wide character if, to equal the multibyte character sequence
705 length given by the precision, the function would need to access a
706 wide character one past the end of the array."
707 This test fails on Solaris 10. */
709 static const wchar_t wstring[] = { 'a', 'b', (wchar_t) 0xfdfdfdfd, 0 };
711 if (sprintf (buf, "%.2ls", wstring) < 0
712 || strcmp (buf, "ab") != 0)
717 [gl_cv_func_printf_directive_ls=yes],
718 [gl_cv_func_printf_directive_ls=no],
722 openbsd*) gl_cv_func_printf_directive_ls="guessing no";;
723 irix*) gl_cv_func_printf_directive_ls="guessing no";;
724 solaris*) gl_cv_func_printf_directive_ls="guessing no";;
725 cygwin*) gl_cv_func_printf_directive_ls="guessing no";;
726 beos* | haiku*) gl_cv_func_printf_directive_ls="guessing no";;
727 *) gl_cv_func_printf_directive_ls="guessing yes";;
734 dnl Test whether the *printf family of functions supports POSIX/XSI format
735 dnl strings with positions. (POSIX:2001)
736 dnl Result is gl_cv_func_printf_positions.
738 AC_DEFUN([gl_PRINTF_POSITIONS],
740 AC_REQUIRE([AC_PROG_CC])
741 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
742 AC_CACHE_CHECK([whether printf supports POSIX/XSI format strings with positions],
743 [gl_cv_func_printf_positions],
749 /* The string "%2$d %1$d", with dollar characters protected from the shell's
750 dollar expansion (possibly an autoconf bug). */
751 static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' };
752 static char buf[100];
755 sprintf (buf, format, 33, 55);
756 return (strcmp (buf, "55 33") != 0);
758 [gl_cv_func_printf_positions=yes],
759 [gl_cv_func_printf_positions=no],
763 netbsd[1-3]* | netbsdelf[1-3]* | netbsdaout[1-3]* | netbsdcoff[1-3]*)
764 gl_cv_func_printf_positions="guessing no";;
765 beos*) gl_cv_func_printf_positions="guessing no";;
766 mingw* | pw*) gl_cv_func_printf_positions="guessing no";;
767 *) gl_cv_func_printf_positions="guessing yes";;
774 dnl Test whether the *printf family of functions supports POSIX/XSI format
775 dnl strings with the ' flag for grouping of decimal digits. (POSIX:2001)
776 dnl Result is gl_cv_func_printf_flag_grouping.
778 AC_DEFUN([gl_PRINTF_FLAG_GROUPING],
780 AC_REQUIRE([AC_PROG_CC])
781 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
782 AC_CACHE_CHECK([whether printf supports the grouping flag],
783 [gl_cv_func_printf_flag_grouping],
789 static char buf[100];
792 if (sprintf (buf, "%'d %d", 1234567, 99) < 0
793 || buf[strlen (buf) - 1] != '9')
797 [gl_cv_func_printf_flag_grouping=yes],
798 [gl_cv_func_printf_flag_grouping=no],
802 cygwin*) gl_cv_func_printf_flag_grouping="guessing no";;
803 netbsd*) gl_cv_func_printf_flag_grouping="guessing no";;
804 mingw* | pw*) gl_cv_func_printf_flag_grouping="guessing no";;
805 *) gl_cv_func_printf_flag_grouping="guessing yes";;
812 dnl Test whether the *printf family of functions supports the - flag correctly.
814 dnl <http://lists.gnu.org/archive/html/bug-coreutils/2008-02/msg00035.html>
815 dnl Result is gl_cv_func_printf_flag_leftadjust.
817 AC_DEFUN([gl_PRINTF_FLAG_LEFTADJUST],
819 AC_REQUIRE([AC_PROG_CC])
820 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
821 AC_CACHE_CHECK([whether printf supports the left-adjust flag correctly],
822 [gl_cv_func_printf_flag_leftadjust],
828 static char buf[100];
831 /* Check that a '-' flag is not annihilated by a negative width. */
832 if (sprintf (buf, "a%-*sc", -3, "b") < 0
833 || strcmp (buf, "ab c") != 0)
837 [gl_cv_func_printf_flag_leftadjust=yes],
838 [gl_cv_func_printf_flag_leftadjust=no],
842 # Guess yes on HP-UX 11.
843 hpux11*) gl_cv_func_printf_flag_leftadjust="guessing yes";;
844 # Guess no on HP-UX 10 and older.
845 hpux*) gl_cv_func_printf_flag_leftadjust="guessing no";;
846 # Guess yes otherwise.
847 *) gl_cv_func_printf_flag_leftadjust="guessing yes";;
854 dnl Test whether the *printf family of functions supports padding of non-finite
855 dnl values with the 0 flag correctly. (ISO C99 + TC1 + TC2.) See
856 dnl <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html>
857 dnl Result is gl_cv_func_printf_flag_zero.
859 AC_DEFUN([gl_PRINTF_FLAG_ZERO],
861 AC_REQUIRE([AC_PROG_CC])
862 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
863 AC_CACHE_CHECK([whether printf supports the zero flag correctly],
864 [gl_cv_func_printf_flag_zero],
870 static char buf[100];
871 static double zero = 0.0;
874 if (sprintf (buf, "%010f", 1.0 / zero, 33, 44, 55) < 0
875 || (strcmp (buf, " inf") != 0
876 && strcmp (buf, " infinity") != 0))
880 [gl_cv_func_printf_flag_zero=yes],
881 [gl_cv_func_printf_flag_zero=no],
885 # Guess yes on glibc systems.
886 *-gnu*) gl_cv_func_printf_flag_zero="guessing yes";;
888 beos*) gl_cv_func_printf_flag_zero="guessing yes";;
889 # If we don't know, assume the worst.
890 *) gl_cv_func_printf_flag_zero="guessing no";;
897 dnl Test whether the *printf family of functions supports large precisions.
898 dnl On mingw, precisions larger than 512 are treated like 512, in integer,
899 dnl floating-point or pointer output. On Solaris 10/x86, precisions larger
900 dnl than 510 in floating-point output crash the program. On Solaris 10/SPARC,
901 dnl precisions larger than 510 in floating-point output yield wrong results.
902 dnl On AIX 7.1, precisions larger than 998 in floating-point output yield
903 dnl wrong results. On BeOS, precisions larger than 1044 crash the program.
904 dnl Result is gl_cv_func_printf_precision.
906 AC_DEFUN([gl_PRINTF_PRECISION],
908 AC_REQUIRE([AC_PROG_CC])
909 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
910 AC_CACHE_CHECK([whether printf supports large precisions],
911 [gl_cv_func_printf_precision],
917 static char buf[5000];
922 /* On BeOS, this would crash and show a dialog box. Avoid the crash. */
925 if (sprintf (buf, "%.4000d %d", 1, 33, 44) < 4000 + 3)
927 if (sprintf (buf, "%.4000f %d", 1.0, 33, 44) < 4000 + 5)
929 if (sprintf (buf, "%.511f %d", 1.0, 33, 44) < 511 + 5
932 if (sprintf (buf, "%.999f %d", 1.0, 33, 44) < 999 + 5
937 [gl_cv_func_printf_precision=yes],
938 [gl_cv_func_printf_precision=no],
942 # Guess no only on Solaris, native Windows, and BeOS systems.
943 solaris*) gl_cv_func_printf_precision="guessing no" ;;
944 mingw* | pw*) gl_cv_func_printf_precision="guessing no" ;;
945 beos*) gl_cv_func_printf_precision="guessing no" ;;
946 *) gl_cv_func_printf_precision="guessing yes" ;;
953 dnl Test whether the *printf family of functions recovers gracefully in case
954 dnl of an out-of-memory condition, or whether it crashes the entire program.
955 dnl Result is gl_cv_func_printf_enomem.
957 AC_DEFUN([gl_PRINTF_ENOMEM],
959 AC_REQUIRE([AC_PROG_CC])
960 AC_REQUIRE([gl_MULTIARCH])
961 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
962 AC_CACHE_CHECK([whether printf survives out-of-memory conditions],
963 [gl_cv_func_printf_enomem],
965 gl_cv_func_printf_enomem="guessing no"
966 if test "$cross_compiling" = no; then
967 if test $APPLE_UNIVERSAL_BUILD = 0; then
968 AC_LANG_CONFTEST([AC_LANG_SOURCE([
972 #include <sys/types.h>
973 #include <sys/time.h>
974 #include <sys/resource.h>
981 /* Some printf implementations allocate temporary space with malloc. */
982 /* On BSD systems, malloc() is limited by RLIMIT_DATA. */
984 if (getrlimit (RLIMIT_DATA, &limit) < 0)
986 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
987 limit.rlim_max = 5000000;
988 limit.rlim_cur = limit.rlim_max;
989 if (setrlimit (RLIMIT_DATA, &limit) < 0)
992 /* On Linux systems, malloc() is limited by RLIMIT_AS. */
994 if (getrlimit (RLIMIT_AS, &limit) < 0)
996 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
997 limit.rlim_max = 5000000;
998 limit.rlim_cur = limit.rlim_max;
999 if (setrlimit (RLIMIT_AS, &limit) < 0)
1002 /* Some printf implementations allocate temporary space on the stack. */
1004 if (getrlimit (RLIMIT_STACK, &limit) < 0)
1006 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
1007 limit.rlim_max = 5000000;
1008 limit.rlim_cur = limit.rlim_max;
1009 if (setrlimit (RLIMIT_STACK, &limit) < 0)
1012 ret = printf ("%.5000000f", 1.0);
1013 return !(ret == 5000002 || (ret < 0 && errno == ENOMEM));
1017 if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
1018 (./conftest 2>&AS_MESSAGE_LOG_FD
1020 _AS_ECHO_LOG([\$? = $result])
1021 if test $result != 0 && test $result != 77; then result=1; fi
1023 ) >/dev/null 2>/dev/null
1025 0) gl_cv_func_printf_enomem="yes" ;;
1026 77) gl_cv_func_printf_enomem="guessing no" ;;
1027 *) gl_cv_func_printf_enomem="no" ;;
1030 gl_cv_func_printf_enomem="guessing no"
1034 dnl A universal build on Apple Mac OS X platforms.
1035 dnl The result would be 'no' in 32-bit mode and 'yes' in 64-bit mode.
1036 dnl But we need a configuration result that is valid in both modes.
1037 gl_cv_func_printf_enomem="guessing no"
1040 if test "$gl_cv_func_printf_enomem" = "guessing no"; then
1043 # Guess yes on glibc systems.
1044 *-gnu*) gl_cv_func_printf_enomem="guessing yes";;
1045 # Guess yes on Solaris.
1046 solaris*) gl_cv_func_printf_enomem="guessing yes";;
1048 aix*) gl_cv_func_printf_enomem="guessing yes";;
1049 # Guess yes on HP-UX/hppa.
1050 hpux*) case "$host_cpu" in
1051 hppa*) gl_cv_func_printf_enomem="guessing yes";;
1052 *) gl_cv_func_printf_enomem="guessing no";;
1055 # Guess yes on IRIX.
1056 irix*) gl_cv_func_printf_enomem="guessing yes";;
1057 # Guess yes on OSF/1.
1058 osf*) gl_cv_func_printf_enomem="guessing yes";;
1059 # Guess yes on BeOS.
1060 beos*) gl_cv_func_printf_enomem="guessing yes";;
1061 # Guess yes on Haiku.
1062 haiku*) gl_cv_func_printf_enomem="guessing yes";;
1063 # If we don't know, assume the worst.
1064 *) gl_cv_func_printf_enomem="guessing no";;
1071 dnl Test whether the snprintf function exists. (ISO C99, POSIX:2001)
1072 dnl Result is ac_cv_func_snprintf.
1074 AC_DEFUN([gl_SNPRINTF_PRESENCE],
1076 AC_CHECK_FUNCS_ONCE([snprintf])
1079 dnl Test whether the string produced by the snprintf function is always NUL
1080 dnl terminated. (ISO C99, POSIX:2001)
1081 dnl Result is gl_cv_func_snprintf_truncation_c99.
1083 AC_DEFUN([gl_SNPRINTF_TRUNCATION_C99],
1085 AC_REQUIRE([AC_PROG_CC])
1086 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1087 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1088 AC_CACHE_CHECK([whether snprintf truncates the result as in C99],
1089 [gl_cv_func_snprintf_truncation_c99],
1096 # define my_snprintf snprintf
1098 # include <stdarg.h>
1099 static int my_snprintf (char *buf, int size, const char *format, ...)
1103 va_start (args, format);
1104 ret = vsnprintf (buf, size, format, args);
1109 static char buf[100];
1112 strcpy (buf, "ABCDEF");
1113 my_snprintf (buf, 3, "%d %d", 4567, 89);
1114 if (memcmp (buf, "45\0DEF", 6) != 0)
1118 [gl_cv_func_snprintf_truncation_c99=yes],
1119 [gl_cv_func_snprintf_truncation_c99=no],
1123 # Guess yes on glibc systems.
1124 *-gnu*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1125 # Guess yes on FreeBSD >= 5.
1126 freebsd[1-4].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1127 freebsd* | kfreebsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1128 # Guess yes on Mac OS X >= 10.3.
1129 darwin[1-6].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1130 darwin*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1131 # Guess yes on OpenBSD >= 3.9.
1132 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
1133 gl_cv_func_snprintf_truncation_c99="guessing no";;
1134 openbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1135 # Guess yes on Solaris >= 2.6.
1136 solaris2.[0-5] | solaris2.[0-5].*)
1137 gl_cv_func_snprintf_truncation_c99="guessing no";;
1138 solaris*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1139 # Guess yes on AIX >= 4.
1140 aix[1-3]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1141 aix*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1142 # Guess yes on HP-UX >= 11.
1143 hpux[7-9]* | hpux10*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1144 hpux*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1145 # Guess yes on IRIX >= 6.5.
1146 irix6.5) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1147 # Guess yes on OSF/1 >= 5.
1148 osf[3-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1149 osf*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1150 # Guess yes on NetBSD >= 3.
1151 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1152 gl_cv_func_snprintf_truncation_c99="guessing no";;
1153 netbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1154 # Guess yes on BeOS.
1155 beos*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1156 # If we don't know, assume the worst.
1157 *) gl_cv_func_snprintf_truncation_c99="guessing no";;
1164 dnl Test whether the return value of the snprintf function is the number
1165 dnl of bytes (excluding the terminating NUL) that would have been produced
1166 dnl if the buffer had been large enough. (ISO C99, POSIX:2001)
1167 dnl For example, this test program fails on IRIX 6.5:
1168 dnl ---------------------------------------------------------------------
1169 dnl #include <stdio.h>
1172 dnl static char buf[8];
1173 dnl int retval = snprintf (buf, 3, "%d", 12345);
1174 dnl return retval >= 0 && retval < 3;
1176 dnl ---------------------------------------------------------------------
1177 dnl Result is gl_cv_func_snprintf_retval_c99.
1179 AC_DEFUN_ONCE([gl_SNPRINTF_RETVAL_C99],
1181 AC_REQUIRE([AC_PROG_CC])
1182 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1183 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1184 AC_CACHE_CHECK([whether snprintf returns a byte count as in C99],
1185 [gl_cv_func_snprintf_retval_c99],
1192 # define my_snprintf snprintf
1194 # include <stdarg.h>
1195 static int my_snprintf (char *buf, int size, const char *format, ...)
1199 va_start (args, format);
1200 ret = vsnprintf (buf, size, format, args);
1205 static char buf[100];
1208 strcpy (buf, "ABCDEF");
1209 if (my_snprintf (buf, 3, "%d %d", 4567, 89) != 7)
1211 if (my_snprintf (buf, 0, "%d %d", 4567, 89) != 7)
1213 if (my_snprintf (NULL, 0, "%d %d", 4567, 89) != 7)
1217 [gl_cv_func_snprintf_retval_c99=yes],
1218 [gl_cv_func_snprintf_retval_c99=no],
1222 # Guess yes on glibc systems.
1223 *-gnu*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1224 # Guess yes on FreeBSD >= 5.
1225 freebsd[1-4].*) gl_cv_func_snprintf_retval_c99="guessing no";;
1226 freebsd* | kfreebsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1227 # Guess yes on Mac OS X >= 10.3.
1228 darwin[1-6].*) gl_cv_func_snprintf_retval_c99="guessing no";;
1229 darwin*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1230 # Guess yes on OpenBSD >= 3.9.
1231 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
1232 gl_cv_func_snprintf_retval_c99="guessing no";;
1233 openbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1234 # Guess yes on Solaris >= 2.10.
1235 solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";;
1236 solaris*) gl_cv_func_printf_sizes_c99="guessing no";;
1237 # Guess yes on AIX >= 4.
1238 aix[1-3]*) gl_cv_func_snprintf_retval_c99="guessing no";;
1239 aix*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1240 # Guess yes on NetBSD >= 3.
1241 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1242 gl_cv_func_snprintf_retval_c99="guessing no";;
1243 netbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1244 # Guess yes on BeOS.
1245 beos*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1246 # If we don't know, assume the worst.
1247 *) gl_cv_func_snprintf_retval_c99="guessing no";;
1254 dnl Test whether the snprintf function supports the %n format directive
1255 dnl also in truncated portions of the format string. (ISO C99, POSIX:2001)
1256 dnl Result is gl_cv_func_snprintf_directive_n.
1258 AC_DEFUN([gl_SNPRINTF_DIRECTIVE_N],
1260 AC_REQUIRE([AC_PROG_CC])
1261 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1262 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1263 AC_CACHE_CHECK([whether snprintf fully supports the 'n' directive],
1264 [gl_cv_func_snprintf_directive_n],
1271 # define my_snprintf snprintf
1273 # include <stdarg.h>
1274 static int my_snprintf (char *buf, int size, const char *format, ...)
1278 va_start (args, format);
1279 ret = vsnprintf (buf, size, format, args);
1284 static char fmtstring[10];
1285 static char buf[100];
1289 /* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2)
1290 support %n in format strings in read-only memory but not in writable
1292 strcpy (fmtstring, "%d %n");
1293 my_snprintf (buf, 4, fmtstring, 12345, &count, 33, 44, 55);
1298 [gl_cv_func_snprintf_directive_n=yes],
1299 [gl_cv_func_snprintf_directive_n=no],
1303 # Guess yes on glibc systems.
1304 *-gnu*) gl_cv_func_snprintf_directive_n="guessing yes";;
1305 # Guess yes on FreeBSD >= 5.
1306 freebsd[1-4].*) gl_cv_func_snprintf_directive_n="guessing no";;
1307 freebsd* | kfreebsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
1308 # Guess yes on Mac OS X >= 10.3.
1309 darwin[1-6].*) gl_cv_func_snprintf_directive_n="guessing no";;
1310 darwin*) gl_cv_func_snprintf_directive_n="guessing yes";;
1311 # Guess yes on Solaris >= 2.6.
1312 solaris2.[0-5] | solaris2.[0-5].*)
1313 gl_cv_func_snprintf_directive_n="guessing no";;
1314 solaris*) gl_cv_func_snprintf_directive_n="guessing yes";;
1315 # Guess yes on AIX >= 4.
1316 aix[1-3]*) gl_cv_func_snprintf_directive_n="guessing no";;
1317 aix*) gl_cv_func_snprintf_directive_n="guessing yes";;
1318 # Guess yes on IRIX >= 6.5.
1319 irix6.5) gl_cv_func_snprintf_directive_n="guessing yes";;
1320 # Guess yes on OSF/1 >= 5.
1321 osf[3-4]*) gl_cv_func_snprintf_directive_n="guessing no";;
1322 osf*) gl_cv_func_snprintf_directive_n="guessing yes";;
1323 # Guess yes on NetBSD >= 3.
1324 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1325 gl_cv_func_snprintf_directive_n="guessing no";;
1326 netbsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
1327 # Guess yes on BeOS.
1328 beos*) gl_cv_func_snprintf_directive_n="guessing yes";;
1329 # If we don't know, assume the worst.
1330 *) gl_cv_func_snprintf_directive_n="guessing no";;
1337 dnl Test whether the snprintf function, when passed a size = 1, writes any
1338 dnl output without bounds in this case, behaving like sprintf. This is the
1339 dnl case on Linux libc5.
1340 dnl Result is gl_cv_func_snprintf_size1.
1342 AC_DEFUN([gl_SNPRINTF_SIZE1],
1344 AC_REQUIRE([AC_PROG_CC])
1345 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1346 AC_CACHE_CHECK([whether snprintf respects a size of 1],
1347 [gl_cv_func_snprintf_size1],
1353 # define my_snprintf snprintf
1355 # include <stdarg.h>
1356 static int my_snprintf (char *buf, int size, const char *format, ...)
1360 va_start (args, format);
1361 ret = vsnprintf (buf, size, format, args);
1368 static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1369 my_snprintf (buf, 1, "%d", 12345);
1370 return buf[1] != 'E';
1372 [gl_cv_func_snprintf_size1=yes],
1373 [gl_cv_func_snprintf_size1=no],
1374 [gl_cv_func_snprintf_size1="guessing yes"])
1378 dnl Test whether the vsnprintf function, when passed a zero size, produces no
1379 dnl output. (ISO C99, POSIX:2001)
1380 dnl For example, snprintf nevertheless writes a NUL byte in this case
1382 dnl ---------------------------------------------------------------------
1383 dnl #include <stdio.h>
1386 dnl static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1387 dnl snprintf (buf, 0, "%d", 12345);
1388 dnl return buf[0] != 'D';
1390 dnl ---------------------------------------------------------------------
1391 dnl And vsnprintf writes any output without bounds in this case, behaving like
1392 dnl vsprintf, on HP-UX 11 and OSF/1 5.1:
1393 dnl ---------------------------------------------------------------------
1394 dnl #include <stdarg.h>
1395 dnl #include <stdio.h>
1396 dnl static int my_snprintf (char *buf, int size, const char *format, ...)
1400 dnl va_start (args, format);
1401 dnl ret = vsnprintf (buf, size, format, args);
1407 dnl static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1408 dnl my_snprintf (buf, 0, "%d", 12345);
1409 dnl return buf[0] != 'D';
1411 dnl ---------------------------------------------------------------------
1412 dnl Result is gl_cv_func_vsnprintf_zerosize_c99.
1414 AC_DEFUN([gl_VSNPRINTF_ZEROSIZE_C99],
1416 AC_REQUIRE([AC_PROG_CC])
1417 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1418 AC_CACHE_CHECK([whether vsnprintf respects a zero size as in C99],
1419 [gl_cv_func_vsnprintf_zerosize_c99],
1425 static int my_snprintf (char *buf, int size, const char *format, ...)
1429 va_start (args, format);
1430 ret = vsnprintf (buf, size, format, args);
1436 static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1437 my_snprintf (buf, 0, "%d", 12345);
1438 return buf[0] != 'D';
1440 [gl_cv_func_vsnprintf_zerosize_c99=yes],
1441 [gl_cv_func_vsnprintf_zerosize_c99=no],
1445 # Guess yes on glibc systems.
1446 *-gnu*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1447 # Guess yes on FreeBSD >= 5.
1448 freebsd[1-4].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1449 freebsd* | kfreebsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1450 # Guess yes on Mac OS X >= 10.3.
1451 darwin[1-6].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1452 darwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1453 # Guess yes on Cygwin.
1454 cygwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1455 # Guess yes on Solaris >= 2.6.
1456 solaris2.[0-5] | solaris2.[0-5].*)
1457 gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1458 solaris*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1459 # Guess yes on AIX >= 4.
1460 aix[1-3]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1461 aix*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1462 # Guess yes on IRIX >= 6.5.
1463 irix6.5) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1464 # Guess yes on NetBSD >= 3.
1465 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1466 gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1467 netbsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1468 # Guess yes on BeOS.
1469 beos*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1470 # Guess yes on mingw.
1471 mingw* | pw*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1472 # If we don't know, assume the worst.
1473 *) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1480 dnl The results of these tests on various platforms are:
1482 dnl 1 = gl_PRINTF_SIZES_C99
1483 dnl 2 = gl_PRINTF_LONG_DOUBLE
1484 dnl 3 = gl_PRINTF_INFINITE
1485 dnl 4 = gl_PRINTF_INFINITE_LONG_DOUBLE
1486 dnl 5 = gl_PRINTF_DIRECTIVE_A
1487 dnl 6 = gl_PRINTF_DIRECTIVE_F
1488 dnl 7 = gl_PRINTF_DIRECTIVE_N
1489 dnl 8 = gl_PRINTF_DIRECTIVE_LS
1490 dnl 9 = gl_PRINTF_POSITIONS
1491 dnl 10 = gl_PRINTF_FLAG_GROUPING
1492 dnl 11 = gl_PRINTF_FLAG_LEFTADJUST
1493 dnl 12 = gl_PRINTF_FLAG_ZERO
1494 dnl 13 = gl_PRINTF_PRECISION
1495 dnl 14 = gl_PRINTF_ENOMEM
1496 dnl 15 = gl_SNPRINTF_PRESENCE
1497 dnl 16 = gl_SNPRINTF_TRUNCATION_C99
1498 dnl 17 = gl_SNPRINTF_RETVAL_C99
1499 dnl 18 = gl_SNPRINTF_DIRECTIVE_N
1500 dnl 19 = gl_SNPRINTF_SIZE1
1501 dnl 20 = gl_VSNPRINTF_ZEROSIZE_C99
1503 dnl 1 = checking whether printf supports size specifiers as in C99...
1504 dnl 2 = checking whether printf supports 'long double' arguments...
1505 dnl 3 = checking whether printf supports infinite 'double' arguments...
1506 dnl 4 = checking whether printf supports infinite 'long double' arguments...
1507 dnl 5 = checking whether printf supports the 'a' and 'A' directives...
1508 dnl 6 = checking whether printf supports the 'F' directive...
1509 dnl 7 = checking whether printf supports the 'n' directive...
1510 dnl 8 = checking whether printf supports the 'ls' directive...
1511 dnl 9 = checking whether printf supports POSIX/XSI format strings with positions...
1512 dnl 10 = checking whether printf supports the grouping flag...
1513 dnl 11 = checking whether printf supports the left-adjust flag correctly...
1514 dnl 12 = checking whether printf supports the zero flag correctly...
1515 dnl 13 = checking whether printf supports large precisions...
1516 dnl 14 = checking whether printf survives out-of-memory conditions...
1517 dnl 15 = checking for snprintf...
1518 dnl 16 = checking whether snprintf truncates the result as in C99...
1519 dnl 17 = checking whether snprintf returns a byte count as in C99...
1520 dnl 18 = checking whether snprintf fully supports the 'n' directive...
1521 dnl 19 = checking whether snprintf respects a size of 1...
1522 dnl 20 = checking whether vsnprintf respects a zero size as in C99...
1524 dnl . = yes, # = no.
1526 dnl 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1527 dnl glibc 2.5 . . . . . . . . . . . . . . . . . . . .
1528 dnl glibc 2.3.6 . . . . # . . . . . . . . . . . . . . .
1529 dnl FreeBSD 5.4, 6.1 . . . . # . . . . . . # . # . . . . . .
1530 dnl Mac OS X 10.5.8 . . . # # . . . . . . # . . . . . . . .
1531 dnl Mac OS X 10.3.9 . . . . # . . . . . . # . # . . . . . .
1532 dnl OpenBSD 3.9, 4.0 . . # # # # . # . # . # . # . . . . . .
1533 dnl Cygwin 1.7.0 (2009) . . . # . . . ? . . . . . ? . . . . . .
1534 dnl Cygwin 1.5.25 (2008) . . . # # . . # . . . . . # . . . . . .
1535 dnl Cygwin 1.5.19 (2006) # . . # # # . # . # . # # # . . . . . .
1536 dnl Solaris 11 2011-11 . . # # # . . # . . . # . . . . . . . .
1537 dnl Solaris 10 . . # # # . . # . . . # # . . . . . . .
1538 dnl Solaris 2.6 ... 9 # . # # # # . # . . . # # . . . # . . .
1539 dnl Solaris 2.5.1 # . # # # # . # . . . # . . # # # # # #
1540 dnl AIX 7.1 . . # # # . . . . . . # # . . . . . . .
1541 dnl AIX 5.2 . . # # # . . . . . . # . . . . . . . .
1542 dnl AIX 4.3.2, 5.1 # . # # # # . . . . . # . . . . # . . .
1543 dnl HP-UX 11.31 . . . . # . . . . . . # . . . . # # . .
1544 dnl HP-UX 11.{00,11,23} # . . . # # . . . . . # . . . . # # . #
1545 dnl HP-UX 10.20 # . # . # # . ? . . # # . . . . # # ? #
1546 dnl IRIX 6.5 # . # # # # . # . . . # . . . . # . . .
1547 dnl OSF/1 5.1 # . # # # # . . . . . # . . . . # . . #
1548 dnl OSF/1 4.0d # . # # # # . . . . . # . . # # # # # #
1549 dnl NetBSD 5.0 . . . # # . . . . . . # . # . . . . . .
1550 dnl NetBSD 4.0 . ? ? ? ? ? . ? . ? ? ? ? ? . . . ? ? ?
1551 dnl NetBSD 3.0 . . . . # # . ? # # ? # . # . . . . . .
1552 dnl Haiku . . . # # # . # . . . . . ? . . ? . . .
1553 dnl BeOS # # . # # # . ? # . ? . # ? . . ? . . .
1554 dnl old mingw / msvcrt # # # # # # . . # # . # # ? . # # # . .
1555 dnl MSVC 9 # # # # # # # . # # . # # ? # # # # . .
1556 dnl mingw 2009-2011 . # . # . . . . # # . . . ? . . . . . .
1557 dnl mingw-w64 2011 # # # # # # . . # # . # # ? . # # # . .