2 dnl Copyright (C) 2003, 2007-2009 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],
24 #include <sys/types.h>
25 #if HAVE_STDINT_H_WITH_UINTMAX
28 #if HAVE_INTTYPES_H_WITH_UINTMAX
29 # include <inttypes.h>
34 #if HAVE_STDINT_H_WITH_UINTMAX || HAVE_INTTYPES_H_WITH_UINTMAX
36 if (sprintf (buf, "%ju %d", (uintmax_t) 12345671, 33, 44, 55) < 0
37 || strcmp (buf, "12345671 33") != 0)
41 if (sprintf (buf, "%zu %d", (size_t) 12345672, 33, 44, 55) < 0
42 || strcmp (buf, "12345672 33") != 0)
45 if (sprintf (buf, "%tu %d", (ptrdiff_t) 12345673, 33, 44, 55) < 0
46 || strcmp (buf, "12345673 33") != 0)
49 if (sprintf (buf, "%Lg %d", (long double) 1.5, 33, 44, 55) < 0
50 || strcmp (buf, "1.5 33") != 0)
53 }], [gl_cv_func_printf_sizes_c99=yes], [gl_cv_func_printf_sizes_c99=no],
57 # Guess yes on glibc systems.
58 *-gnu*) gl_cv_func_printf_sizes_c99="guessing yes";;
59 # Guess yes on FreeBSD >= 5.
60 freebsd[1-4]*) gl_cv_func_printf_sizes_c99="guessing no";;
61 freebsd* | kfreebsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
62 # Guess yes on MacOS X >= 10.3.
63 darwin[1-6].*) gl_cv_func_printf_sizes_c99="guessing no";;
64 darwin*) gl_cv_func_printf_sizes_c99="guessing yes";;
65 # Guess yes on OpenBSD >= 3.9.
66 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
67 gl_cv_func_printf_sizes_c99="guessing no";;
68 openbsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
69 # Guess yes on Solaris >= 2.10.
70 solaris2.[0-9]*) gl_cv_func_printf_sizes_c99="guessing no";;
71 solaris*) gl_cv_func_printf_sizes_c99="guessing yes";;
72 # Guess yes on NetBSD >= 3.
73 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
74 gl_cv_func_printf_sizes_c99="guessing no";;
75 netbsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
76 # If we don't know, assume the worst.
77 *) gl_cv_func_printf_sizes_c99="guessing no";;
84 dnl Test whether the *printf family of functions supports 'long double'
85 dnl arguments together with the 'L' size specifier. (ISO C99, POSIX:2001)
86 dnl Result is gl_cv_func_printf_long_double.
88 AC_DEFUN([gl_PRINTF_LONG_DOUBLE],
90 AC_REQUIRE([AC_PROG_CC])
91 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
92 AC_CACHE_CHECK([whether printf supports 'long double' arguments],
93 [gl_cv_func_printf_long_double],
98 static char buf[10000];
102 if (sprintf (buf, "%Lf %d", 1.75L, 33, 44, 55) < 0
103 || strcmp (buf, "1.750000 33") != 0)
106 if (sprintf (buf, "%Le %d", 1.75L, 33, 44, 55) < 0
107 || strcmp (buf, "1.750000e+00 33") != 0)
110 if (sprintf (buf, "%Lg %d", 1.75L, 33, 44, 55) < 0
111 || strcmp (buf, "1.75 33") != 0)
114 }], [gl_cv_func_printf_long_double=yes], [gl_cv_func_printf_long_double=no],
118 beos*) gl_cv_func_printf_long_double="guessing no";;
119 mingw* | pw*) gl_cv_func_printf_long_double="guessing no";;
120 *) gl_cv_func_printf_long_double="guessing yes";;
127 dnl Test whether the *printf family of functions supports infinite and NaN
128 dnl 'double' arguments and negative zero arguments in the %f, %e, %g
129 dnl directives. (ISO C99, POSIX:2001)
130 dnl Result is gl_cv_func_printf_infinite.
132 AC_DEFUN([gl_PRINTF_INFINITE],
134 AC_REQUIRE([AC_PROG_CC])
135 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
136 AC_CACHE_CHECK([whether printf supports infinite 'double' arguments],
137 [gl_cv_func_printf_infinite],
143 strisnan (const char *string, size_t start_index, size_t end_index)
145 if (start_index < end_index)
147 if (string[start_index] == '-')
149 if (start_index + 3 <= end_index
150 && memcmp (string + start_index, "nan", 3) == 0)
153 if (start_index == end_index
154 || (string[start_index] == '(' && string[end_index - 1] == ')'))
163 static double plus_zero = 0.0;
164 double minus_zero = - plus_zero;
165 return memcmp (&plus_zero, &minus_zero, sizeof (double)) != 0;
167 static char buf[10000];
168 static double zero = 0.0;
171 if (sprintf (buf, "%f", 1.0 / 0.0) < 0
172 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
174 if (sprintf (buf, "%f", -1.0 / 0.0) < 0
175 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
177 if (sprintf (buf, "%f", zero / zero) < 0
178 || !strisnan (buf, 0, strlen (buf)))
180 if (sprintf (buf, "%e", 1.0 / 0.0) < 0
181 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
183 if (sprintf (buf, "%e", -1.0 / 0.0) < 0
184 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
186 if (sprintf (buf, "%e", zero / zero) < 0
187 || !strisnan (buf, 0, strlen (buf)))
189 if (sprintf (buf, "%g", 1.0 / 0.0) < 0
190 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
192 if (sprintf (buf, "%g", -1.0 / 0.0) < 0
193 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
195 if (sprintf (buf, "%g", zero / zero) < 0
196 || !strisnan (buf, 0, strlen (buf)))
198 /* This test fails on HP-UX 10.20. */
199 if (have_minus_zero ())
200 if (sprintf (buf, "%g", - zero) < 0
201 || strcmp (buf, "-0") != 0)
204 }], [gl_cv_func_printf_infinite=yes], [gl_cv_func_printf_infinite=no],
208 # Guess yes on glibc systems.
209 *-gnu*) gl_cv_func_printf_infinite="guessing yes";;
210 # Guess yes on FreeBSD >= 6.
211 freebsd[1-5]*) gl_cv_func_printf_infinite="guessing no";;
212 freebsd* | kfreebsd*) gl_cv_func_printf_infinite="guessing yes";;
213 # Guess yes on MacOS X >= 10.3.
214 darwin[1-6].*) gl_cv_func_printf_infinite="guessing no";;
215 darwin*) gl_cv_func_printf_infinite="guessing yes";;
216 # Guess yes on HP-UX >= 11.
217 hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite="guessing no";;
218 hpux*) gl_cv_func_printf_infinite="guessing yes";;
219 # Guess yes on NetBSD >= 3.
220 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
221 gl_cv_func_printf_infinite="guessing no";;
222 netbsd*) gl_cv_func_printf_infinite="guessing yes";;
224 beos*) gl_cv_func_printf_infinite="guessing yes";;
225 # If we don't know, assume the worst.
226 *) gl_cv_func_printf_infinite="guessing no";;
233 dnl Test whether the *printf family of functions supports infinite and NaN
234 dnl 'long double' arguments in the %f, %e, %g directives. (ISO C99, POSIX:2001)
235 dnl Result is gl_cv_func_printf_infinite_long_double.
237 AC_DEFUN([gl_PRINTF_INFINITE_LONG_DOUBLE],
239 AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
240 AC_REQUIRE([AC_PROG_CC])
241 AC_REQUIRE([gl_BIGENDIAN])
242 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
243 dnl The user can set or unset the variable gl_printf_safe to indicate
244 dnl that he wishes a safe handling of non-IEEE-754 'long double' values.
245 if test -n "$gl_printf_safe"; then
246 AC_DEFINE([CHECK_PRINTF_SAFE], [1],
247 [Define if you wish *printf() functions that have a safe handling of
248 non-IEEE-754 'long double' values.])
250 case "$gl_cv_func_printf_long_double" in
252 AC_CACHE_CHECK([whether printf supports infinite 'long double' arguments],
253 [gl_cv_func_printf_infinite_long_double],
261 strisnan (const char *string, size_t start_index, size_t end_index)
263 if (start_index < end_index)
265 if (string[start_index] == '-')
267 if (start_index + 3 <= end_index
268 && memcmp (string + start_index, "nan", 3) == 0)
271 if (start_index == end_index
272 || (string[start_index] == '(' && string[end_index - 1] == ')'))
278 static char buf[10000];
279 static long double zeroL = 0.0L;
283 if (sprintf (buf, "%Lf", 1.0L / 0.0L) < 0
284 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
286 if (sprintf (buf, "%Lf", -1.0L / 0.0L) < 0
287 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
289 if (sprintf (buf, "%Lf", zeroL / zeroL) < 0
290 || !strisnan (buf, 0, strlen (buf)))
292 if (sprintf (buf, "%Le", 1.0L / 0.0L) < 0
293 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
295 if (sprintf (buf, "%Le", -1.0L / 0.0L) < 0
296 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
298 if (sprintf (buf, "%Le", zeroL / zeroL) < 0
299 || !strisnan (buf, 0, strlen (buf)))
301 if (sprintf (buf, "%Lg", 1.0L / 0.0L) < 0
302 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
304 if (sprintf (buf, "%Lg", -1.0L / 0.0L) < 0
305 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
307 if (sprintf (buf, "%Lg", zeroL / zeroL) < 0
308 || !strisnan (buf, 0, strlen (buf)))
310 #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_))
311 /* Representation of an 80-bit 'long double' as an initializer for a sequence
312 of 'unsigned int' words. */
313 # ifdef WORDS_BIGENDIAN
314 # define LDBL80_WORDS(exponent,manthi,mantlo) \
315 { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
316 ((unsigned int) (manthi) << 16) | (unsigned int) (mantlo) >> 16), \
317 (unsigned int) (mantlo) << 16 \
320 # define LDBL80_WORDS(exponent,manthi,mantlo) \
321 { mantlo, manthi, exponent }
324 static union { unsigned int word[4]; long double value; } x =
325 { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
326 if (sprintf (buf, "%Lf", x.value) < 0
327 || !strisnan (buf, 0, strlen (buf)))
329 if (sprintf (buf, "%Le", x.value) < 0
330 || !strisnan (buf, 0, strlen (buf)))
332 if (sprintf (buf, "%Lg", x.value) < 0
333 || !strisnan (buf, 0, strlen (buf)))
337 /* Signalling NaN. */
338 static union { unsigned int word[4]; long double value; } x =
339 { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
340 if (sprintf (buf, "%Lf", x.value) < 0
341 || !strisnan (buf, 0, strlen (buf)))
343 if (sprintf (buf, "%Le", x.value) < 0
344 || !strisnan (buf, 0, strlen (buf)))
346 if (sprintf (buf, "%Lg", x.value) < 0
347 || !strisnan (buf, 0, strlen (buf)))
351 static union { unsigned int word[4]; long double value; } x =
352 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
353 if (sprintf (buf, "%Lf", x.value) < 0
354 || !strisnan (buf, 0, strlen (buf)))
356 if (sprintf (buf, "%Le", x.value) < 0
357 || !strisnan (buf, 0, strlen (buf)))
359 if (sprintf (buf, "%Lg", x.value) < 0
360 || !strisnan (buf, 0, strlen (buf)))
363 { /* Pseudo-Infinity. */
364 static union { unsigned int word[4]; long double value; } x =
365 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
366 if (sprintf (buf, "%Lf", x.value) < 0
367 || !strisnan (buf, 0, strlen (buf)))
369 if (sprintf (buf, "%Le", x.value) < 0
370 || !strisnan (buf, 0, strlen (buf)))
372 if (sprintf (buf, "%Lg", x.value) < 0
373 || !strisnan (buf, 0, strlen (buf)))
377 static union { unsigned int word[4]; long double value; } x =
378 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
379 if (sprintf (buf, "%Lf", x.value) < 0
380 || !strisnan (buf, 0, strlen (buf)))
382 if (sprintf (buf, "%Le", x.value) < 0
383 || !strisnan (buf, 0, strlen (buf)))
385 if (sprintf (buf, "%Lg", x.value) < 0
386 || !strisnan (buf, 0, strlen (buf)))
389 { /* Unnormalized number. */
390 static union { unsigned int word[4]; long double value; } x =
391 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
392 if (sprintf (buf, "%Lf", x.value) < 0
393 || !strisnan (buf, 0, strlen (buf)))
395 if (sprintf (buf, "%Le", x.value) < 0
396 || !strisnan (buf, 0, strlen (buf)))
398 if (sprintf (buf, "%Lg", x.value) < 0
399 || !strisnan (buf, 0, strlen (buf)))
402 { /* Pseudo-Denormal. */
403 static union { unsigned int word[4]; long double value; } x =
404 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
405 if (sprintf (buf, "%Lf", x.value) < 0
406 || !strisnan (buf, 0, strlen (buf)))
408 if (sprintf (buf, "%Le", x.value) < 0
409 || !strisnan (buf, 0, strlen (buf)))
411 if (sprintf (buf, "%Lg", x.value) < 0
412 || !strisnan (buf, 0, strlen (buf)))
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 MacOS X >= 10.3.
433 darwin[1-6].*) gl_cv_func_printf_infinite_long_double="guessing no";;
434 darwin*) gl_cv_func_printf_infinite_long_double="guessing yes";;
435 # Guess yes on HP-UX >= 11.
436 hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite_long_double="guessing no";;
437 hpux*) gl_cv_func_printf_infinite_long_double="guessing yes";;
438 # Guess yes on NetBSD >= 3.
439 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
440 gl_cv_func_printf_infinite_long_double="guessing no";;
441 netbsd*) gl_cv_func_printf_infinite_long_double="guessing yes";;
442 # If we don't know, assume the worst.
443 *) gl_cv_func_printf_infinite_long_double="guessing no";;
452 gl_cv_func_printf_infinite_long_double="irrelevant"
457 dnl Test whether the *printf family of functions supports the 'a' and 'A'
458 dnl conversion specifier for hexadecimal output of floating-point numbers.
459 dnl (ISO C99, POSIX:2001)
460 dnl Result is gl_cv_func_printf_directive_a.
462 AC_DEFUN([gl_PRINTF_DIRECTIVE_A],
464 AC_REQUIRE([AC_PROG_CC])
465 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
466 AC_CACHE_CHECK([whether printf supports the 'a' and 'A' directives],
467 [gl_cv_func_printf_directive_a],
472 static char buf[100];
475 if (sprintf (buf, "%a %d", 3.1416015625, 33, 44, 55) < 0
476 || (strcmp (buf, "0x1.922p+1 33") != 0
477 && strcmp (buf, "0x3.244p+0 33") != 0
478 && strcmp (buf, "0x6.488p-1 33") != 0
479 && strcmp (buf, "0xc.91p-2 33") != 0))
481 if (sprintf (buf, "%A %d", -3.1416015625, 33, 44, 55) < 0
482 || (strcmp (buf, "-0X1.922P+1 33") != 0
483 && strcmp (buf, "-0X3.244P+0 33") != 0
484 && strcmp (buf, "-0X6.488P-1 33") != 0
485 && strcmp (buf, "-0XC.91P-2 33") != 0))
487 /* This catches a FreeBSD 6.1 bug: it doesn't round. */
488 if (sprintf (buf, "%.2a %d", 1.51, 33, 44, 55) < 0
489 || (strcmp (buf, "0x1.83p+0 33") != 0
490 && strcmp (buf, "0x3.05p-1 33") != 0
491 && strcmp (buf, "0x6.0ap-2 33") != 0
492 && strcmp (buf, "0xc.14p-3 33") != 0))
494 /* This catches a FreeBSD 6.1 bug. See
495 <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
496 if (sprintf (buf, "%010a %d", 1.0 / 0.0, 33, 44, 55) < 0
499 /* This catches a MacOS X 10.3.9 (Darwin 7.9) bug. */
500 if (sprintf (buf, "%.1a", 1.999) < 0
501 || (strcmp (buf, "0x1.0p+1") != 0
502 && strcmp (buf, "0x2.0p+0") != 0
503 && strcmp (buf, "0x4.0p-1") != 0
504 && strcmp (buf, "0x8.0p-2") != 0))
506 /* This catches the same MacOS X 10.3.9 (Darwin 7.9) bug and also a
507 glibc 2.4 bug <http://sourceware.org/bugzilla/show_bug.cgi?id=2908>. */
508 if (sprintf (buf, "%.1La", 1.999L) < 0
509 || (strcmp (buf, "0x1.0p+1") != 0
510 && strcmp (buf, "0x2.0p+0") != 0
511 && strcmp (buf, "0x4.0p-1") != 0
512 && strcmp (buf, "0x8.0p-2") != 0))
515 }], [gl_cv_func_printf_directive_a=yes], [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)
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],
552 static char buf[100];
555 if (sprintf (buf, "%F %d", 1234567.0, 33, 44, 55) < 0
556 || strcmp (buf, "1234567.000000 33") != 0)
558 if (sprintf (buf, "%F", 1.0 / 0.0) < 0
559 || (strcmp (buf, "INF") != 0 && strcmp (buf, "INFINITY") != 0))
561 /* This catches a Cygwin 2007 bug. */
562 if (sprintf (buf, "%.F", 1234.0) < 0
563 || strcmp (buf, "1234") != 0)
566 }], [gl_cv_func_printf_directive_f=yes], [gl_cv_func_printf_directive_f=no],
570 # Guess yes on glibc systems.
571 *-gnu*) gl_cv_func_printf_directive_f="guessing yes";;
572 # Guess yes on FreeBSD >= 6.
573 freebsd[1-5]*) gl_cv_func_printf_directive_f="guessing no";;
574 freebsd* | kfreebsd*) gl_cv_func_printf_directive_f="guessing yes";;
575 # Guess yes on MacOS X >= 10.3.
576 darwin[1-6].*) gl_cv_func_printf_directive_f="guessing no";;
577 darwin*) gl_cv_func_printf_directive_f="guessing yes";;
578 # Guess yes on Solaris >= 2.10.
579 solaris2.[0-9]*) gl_cv_func_printf_directive_f="guessing no";;
580 solaris*) gl_cv_func_printf_directive_f="guessing yes";;
581 # If we don't know, assume the worst.
582 *) gl_cv_func_printf_directive_f="guessing no";;
589 dnl Test whether the *printf family of functions supports the %n format
590 dnl directive. (ISO C99, POSIX:2001)
591 dnl Result is gl_cv_func_printf_directive_n.
593 AC_DEFUN([gl_PRINTF_DIRECTIVE_N],
595 AC_REQUIRE([AC_PROG_CC])
596 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
597 AC_CACHE_CHECK([whether printf supports the 'n' directive],
598 [gl_cv_func_printf_directive_n],
603 static char fmtstring[10];
604 static char buf[100];
608 /* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2)
609 support %n in format strings in read-only memory but not in writable
611 strcpy (fmtstring, "%d %n");
612 if (sprintf (buf, fmtstring, 123, &count, 33, 44, 55) < 0
613 || strcmp (buf, "123 ") != 0
617 }], [gl_cv_func_printf_directive_n=yes], [gl_cv_func_printf_directive_n=no],
621 *) gl_cv_func_printf_directive_n="guessing yes";;
628 dnl Test whether the *printf family of functions supports the %ls format
629 dnl directive and in particular, when a precision is specified, whether
630 dnl the functions stop converting the wide string argument when the number
631 dnl of bytes that have been produced by this conversion equals or exceeds
633 dnl Result is gl_cv_func_printf_directive_ls.
635 AC_DEFUN([gl_PRINTF_DIRECTIVE_LS],
637 AC_REQUIRE([AC_PROG_CC])
638 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
639 AC_CACHE_CHECK([whether printf supports the 'ls' directive],
640 [gl_cv_func_printf_directive_ls],
643 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
645 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
646 included before <wchar.h>. */
655 /* Test whether %ls works at all.
656 This test fails on OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku. */
658 static const wchar_t wstring[] = { 'a', 'b', 'c', 0 };
660 if (sprintf (buf, "%ls", wstring) < 0
661 || strcmp (buf, "abc") != 0)
664 /* Test whether precisions in %ls are supported as specified in ISO C 99
666 "If a precision is specified, no more than that many bytes are written
667 (including shift sequences, if any), and the array shall contain a
668 null wide character if, to equal the multibyte character sequence
669 length given by the precision, the function would need to access a
670 wide character one past the end of the array."
671 This test fails on Solaris 10. */
673 static const wchar_t wstring[] = { 'a', 'b', (wchar_t) 0xfdfdfdfd, 0 };
675 if (sprintf (buf, "%.2ls", wstring) < 0
676 || strcmp (buf, "ab") != 0)
680 }], [gl_cv_func_printf_directive_ls=yes], [gl_cv_func_printf_directive_ls=no],
684 openbsd*) gl_cv_func_printf_directive_ls="guessing no";;
685 solaris*) gl_cv_func_printf_directive_ls="guessing no";;
686 irix*) gl_cv_func_printf_directive_ls="guessing no";;
687 beos* | haiku*) gl_cv_func_printf_directive_ls="guessing no";;
688 *) gl_cv_func_printf_directive_ls="guessing yes";;
695 dnl Test whether the *printf family of functions supports POSIX/XSI format
696 dnl strings with positions. (POSIX:2001)
697 dnl Result is gl_cv_func_printf_positions.
699 AC_DEFUN([gl_PRINTF_POSITIONS],
701 AC_REQUIRE([AC_PROG_CC])
702 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
703 AC_CACHE_CHECK([whether printf supports POSIX/XSI format strings with positions],
704 [gl_cv_func_printf_positions],
709 /* The string "%2$d %1$d", with dollar characters protected from the shell's
710 dollar expansion (possibly an autoconf bug). */
711 static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' };
712 static char buf[100];
715 sprintf (buf, format, 33, 55);
716 return (strcmp (buf, "55 33") != 0);
717 }], [gl_cv_func_printf_positions=yes], [gl_cv_func_printf_positions=no],
721 netbsd[1-3]* | netbsdelf[1-3]* | netbsdaout[1-3]* | netbsdcoff[1-3]*)
722 gl_cv_func_printf_positions="guessing no";;
723 beos*) gl_cv_func_printf_positions="guessing no";;
724 mingw* | pw*) gl_cv_func_printf_positions="guessing no";;
725 *) gl_cv_func_printf_positions="guessing yes";;
732 dnl Test whether the *printf family of functions supports POSIX/XSI format
733 dnl strings with the ' flag for grouping of decimal digits. (POSIX:2001)
734 dnl Result is gl_cv_func_printf_flag_grouping.
736 AC_DEFUN([gl_PRINTF_FLAG_GROUPING],
738 AC_REQUIRE([AC_PROG_CC])
739 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
740 AC_CACHE_CHECK([whether printf supports the grouping flag],
741 [gl_cv_func_printf_flag_grouping],
746 static char buf[100];
749 if (sprintf (buf, "%'d %d", 1234567, 99) < 0
750 || buf[strlen (buf) - 1] != '9')
753 }], [gl_cv_func_printf_flag_grouping=yes], [gl_cv_func_printf_flag_grouping=no],
757 cygwin*) gl_cv_func_printf_flag_grouping="guessing no";;
758 netbsd*) gl_cv_func_printf_flag_grouping="guessing no";;
759 mingw* | pw*) gl_cv_func_printf_flag_grouping="guessing no";;
760 *) gl_cv_func_printf_flag_grouping="guessing yes";;
767 dnl Test whether the *printf family of functions supports the - flag correctly.
769 dnl <http://lists.gnu.org/archive/html/bug-coreutils/2008-02/msg00035.html>
770 dnl Result is gl_cv_func_printf_flag_leftadjust.
772 AC_DEFUN([gl_PRINTF_FLAG_LEFTADJUST],
774 AC_REQUIRE([AC_PROG_CC])
775 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
776 AC_CACHE_CHECK([whether printf supports the left-adjust flag correctly],
777 [gl_cv_func_printf_flag_leftadjust],
782 static char buf[100];
785 /* Check that a '-' flag is not annihilated by a negative width. */
786 if (sprintf (buf, "a%-*sc", -3, "b") < 0
787 || strcmp (buf, "ab c") != 0)
791 [gl_cv_func_printf_flag_leftadjust=yes],
792 [gl_cv_func_printf_flag_leftadjust=no],
796 # Guess yes on HP-UX 11.
797 hpux11*) gl_cv_func_printf_flag_leftadjust="guessing yes";;
798 # Guess no on HP-UX 10 and older.
799 hpux*) gl_cv_func_printf_flag_leftadjust="guessing no";;
800 # Guess yes otherwise.
801 *) gl_cv_func_printf_flag_leftadjust="guessing yes";;
808 dnl Test whether the *printf family of functions supports padding of non-finite
809 dnl values with the 0 flag correctly. (ISO C99 + TC1 + TC2.) See
810 dnl <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html>
811 dnl Result is gl_cv_func_printf_flag_zero.
813 AC_DEFUN([gl_PRINTF_FLAG_ZERO],
815 AC_REQUIRE([AC_PROG_CC])
816 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
817 AC_CACHE_CHECK([whether printf supports the zero flag correctly],
818 [gl_cv_func_printf_flag_zero],
823 static char buf[100];
826 if (sprintf (buf, "%010f", 1.0 / 0.0, 33, 44, 55) < 0
827 || (strcmp (buf, " inf") != 0
828 && strcmp (buf, " infinity") != 0))
831 }], [gl_cv_func_printf_flag_zero=yes], [gl_cv_func_printf_flag_zero=no],
835 # Guess yes on glibc systems.
836 *-gnu*) gl_cv_func_printf_flag_zero="guessing yes";;
838 beos*) gl_cv_func_printf_flag_zero="guessing yes";;
839 # If we don't know, assume the worst.
840 *) gl_cv_func_printf_flag_zero="guessing no";;
847 dnl Test whether the *printf family of functions supports large precisions.
848 dnl On mingw, precisions larger than 512 are treated like 512, in integer,
849 dnl floating-point or pointer output. On BeOS, precisions larger than 1044
850 dnl crash the program.
851 dnl Result is gl_cv_func_printf_precision.
853 AC_DEFUN([gl_PRINTF_PRECISION],
855 AC_REQUIRE([AC_PROG_CC])
856 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
857 AC_CACHE_CHECK([whether printf supports large precisions],
858 [gl_cv_func_printf_precision],
863 static char buf[5000];
867 /* On BeOS, this would crash and show a dialog box. Avoid the crash. */
870 if (sprintf (buf, "%.4000d %d", 1, 33, 44) < 4000 + 3)
873 }], [gl_cv_func_printf_precision=yes], [gl_cv_func_printf_precision=no],
877 # Guess no only on native Win32 and BeOS systems.
878 mingw* | pw*) gl_cv_func_printf_precision="guessing no" ;;
879 beos*) gl_cv_func_printf_precision="guessing no" ;;
880 *) gl_cv_func_printf_precision="guessing yes" ;;
887 dnl Test whether the *printf family of functions recovers gracefully in case
888 dnl of an out-of-memory condition, or whether it crashes the entire program.
889 dnl Result is gl_cv_func_printf_enomem.
891 AC_DEFUN([gl_PRINTF_ENOMEM],
893 AC_REQUIRE([AC_PROG_CC])
894 AC_REQUIRE([gl_MULTIARCH])
895 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
896 AC_CACHE_CHECK([whether printf survives out-of-memory conditions],
897 [gl_cv_func_printf_enomem],
899 gl_cv_func_printf_enomem="guessing no"
900 if test "$cross_compiling" = no; then
901 if test $APPLE_UNIVERSAL_BUILD = 0; then
902 AC_LANG_CONFTEST([AC_LANG_SOURCE([
906 #include <sys/types.h>
907 #include <sys/time.h>
908 #include <sys/resource.h>
915 /* Some printf implementations allocate temporary space with malloc. */
916 /* On BSD systems, malloc() is limited by RLIMIT_DATA. */
918 if (getrlimit (RLIMIT_DATA, &limit) < 0)
920 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
921 limit.rlim_max = 5000000;
922 limit.rlim_cur = limit.rlim_max;
923 if (setrlimit (RLIMIT_DATA, &limit) < 0)
926 /* On Linux systems, malloc() is limited by RLIMIT_AS. */
928 if (getrlimit (RLIMIT_AS, &limit) < 0)
930 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
931 limit.rlim_max = 5000000;
932 limit.rlim_cur = limit.rlim_max;
933 if (setrlimit (RLIMIT_AS, &limit) < 0)
936 /* Some printf implementations allocate temporary space on the stack. */
938 if (getrlimit (RLIMIT_STACK, &limit) < 0)
940 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
941 limit.rlim_max = 5000000;
942 limit.rlim_cur = limit.rlim_max;
943 if (setrlimit (RLIMIT_STACK, &limit) < 0)
946 ret = printf ("%.5000000f", 1.0);
947 return !(ret == 5000002 || (ret < 0 && errno == ENOMEM));
951 if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
954 if test $result != 0 && test $result != 77; then result=1; fi
956 ) >/dev/null 2>/dev/null
958 0) gl_cv_func_printf_enomem="yes" ;;
959 77) gl_cv_func_printf_enomem="guessing no" ;;
960 *) gl_cv_func_printf_enomem="no" ;;
963 gl_cv_func_printf_enomem="guessing no"
967 dnl A universal build on Apple MacOS X platforms.
968 dnl The result would be 'no' in 32-bit mode and 'yes' in 64-bit mode.
969 dnl But we need a configuration result that is valid in both modes.
970 gl_cv_func_printf_enomem="guessing no"
973 if test "$gl_cv_func_printf_enomem" = "guessing no"; then
976 # Guess yes on glibc systems.
977 *-gnu*) gl_cv_func_printf_enomem="guessing yes";;
978 # Guess yes on Solaris.
979 solaris*) gl_cv_func_printf_enomem="guessing yes";;
981 aix*) gl_cv_func_printf_enomem="guessing yes";;
982 # Guess yes on HP-UX/hppa.
983 hpux*) case "$host_cpu" in
984 hppa*) gl_cv_func_printf_enomem="guessing yes";;
985 *) gl_cv_func_printf_enomem="guessing no";;
989 irix*) gl_cv_func_printf_enomem="guessing yes";;
990 # Guess yes on OSF/1.
991 osf*) gl_cv_func_printf_enomem="guessing yes";;
993 beos*) gl_cv_func_printf_enomem="guessing yes";;
994 # Guess yes on Haiku.
995 haiku*) gl_cv_func_printf_enomem="guessing yes";;
996 # If we don't know, assume the worst.
997 *) gl_cv_func_printf_enomem="guessing no";;
1004 dnl Test whether the snprintf function exists. (ISO C99, POSIX:2001)
1005 dnl Result is ac_cv_func_snprintf.
1007 AC_DEFUN([gl_SNPRINTF_PRESENCE],
1009 AC_CHECK_FUNCS_ONCE([snprintf])
1012 dnl Test whether the string produced by the snprintf function is always NUL
1013 dnl terminated. (ISO C99, POSIX:2001)
1014 dnl Result is gl_cv_func_snprintf_truncation_c99.
1016 AC_DEFUN([gl_SNPRINTF_TRUNCATION_C99],
1018 AC_REQUIRE([AC_PROG_CC])
1019 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1020 AC_CACHE_CHECK([whether snprintf truncates the result as in C99],
1021 [gl_cv_func_snprintf_truncation_c99],
1026 static char buf[100];
1029 strcpy (buf, "ABCDEF");
1030 snprintf (buf, 3, "%d %d", 4567, 89);
1031 if (memcmp (buf, "45\0DEF", 6) != 0)
1034 }], [gl_cv_func_snprintf_truncation_c99=yes], [gl_cv_func_snprintf_truncation_c99=no],
1038 # Guess yes on glibc systems.
1039 *-gnu*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1040 # Guess yes on FreeBSD >= 5.
1041 freebsd[1-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1042 freebsd* | kfreebsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1043 # Guess yes on MacOS X >= 10.3.
1044 darwin[1-6].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1045 darwin*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1046 # Guess yes on OpenBSD >= 3.9.
1047 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
1048 gl_cv_func_snprintf_truncation_c99="guessing no";;
1049 openbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1050 # Guess yes on Solaris >= 2.6.
1051 solaris2.[0-5]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1052 solaris*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1053 # Guess yes on AIX >= 4.
1054 aix[1-3]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1055 aix*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1056 # Guess yes on HP-UX >= 11.
1057 hpux[7-9]* | hpux10*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1058 hpux*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1059 # Guess yes on IRIX >= 6.5.
1060 irix6.5) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1061 # Guess yes on OSF/1 >= 5.
1062 osf[3-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1063 osf*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1064 # Guess yes on NetBSD >= 3.
1065 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1066 gl_cv_func_snprintf_truncation_c99="guessing no";;
1067 netbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1068 # Guess yes on BeOS.
1069 beos*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1070 # If we don't know, assume the worst.
1071 *) gl_cv_func_snprintf_truncation_c99="guessing no";;
1078 dnl Test whether the return value of the snprintf function is the number
1079 dnl of bytes (excluding the terminating NUL) that would have been produced
1080 dnl if the buffer had been large enough. (ISO C99, POSIX:2001)
1081 dnl For example, this test program fails on IRIX 6.5:
1082 dnl ---------------------------------------------------------------------
1083 dnl #include <stdio.h>
1086 dnl static char buf[8];
1087 dnl int retval = snprintf (buf, 3, "%d", 12345);
1088 dnl return retval >= 0 && retval < 3;
1090 dnl ---------------------------------------------------------------------
1091 dnl Result is gl_cv_func_snprintf_retval_c99.
1093 AC_DEFUN([gl_SNPRINTF_RETVAL_C99],
1095 AC_REQUIRE([AC_PROG_CC])
1096 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1097 AC_CACHE_CHECK([whether snprintf returns a byte count as in C99],
1098 [gl_cv_func_snprintf_retval_c99],
1103 static char buf[100];
1106 strcpy (buf, "ABCDEF");
1107 if (snprintf (buf, 3, "%d %d", 4567, 89) != 7)
1110 }], [gl_cv_func_snprintf_retval_c99=yes], [gl_cv_func_snprintf_retval_c99=no],
1114 # Guess yes on glibc systems.
1115 *-gnu*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1116 # Guess yes on FreeBSD >= 5.
1117 freebsd[1-4]*) gl_cv_func_snprintf_retval_c99="guessing no";;
1118 freebsd* | kfreebsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1119 # Guess yes on MacOS X >= 10.3.
1120 darwin[1-6].*) gl_cv_func_snprintf_retval_c99="guessing no";;
1121 darwin*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1122 # Guess yes on OpenBSD >= 3.9.
1123 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
1124 gl_cv_func_snprintf_retval_c99="guessing no";;
1125 openbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1126 # Guess yes on Solaris >= 2.6.
1127 solaris2.[0-5]*) gl_cv_func_snprintf_retval_c99="guessing no";;
1128 solaris*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1129 # Guess yes on AIX >= 4.
1130 aix[1-3]*) gl_cv_func_snprintf_retval_c99="guessing no";;
1131 aix*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1132 # Guess yes on NetBSD >= 3.
1133 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1134 gl_cv_func_snprintf_retval_c99="guessing no";;
1135 netbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1136 # Guess yes on BeOS.
1137 beos*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1138 # If we don't know, assume the worst.
1139 *) gl_cv_func_snprintf_retval_c99="guessing no";;
1146 dnl Test whether the snprintf function supports the %n format directive
1147 dnl also in truncated portions of the format string. (ISO C99, POSIX:2001)
1148 dnl Result is gl_cv_func_snprintf_directive_n.
1150 AC_DEFUN([gl_SNPRINTF_DIRECTIVE_N],
1152 AC_REQUIRE([AC_PROG_CC])
1153 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1154 AC_CACHE_CHECK([whether snprintf fully supports the 'n' directive],
1155 [gl_cv_func_snprintf_directive_n],
1160 static char fmtstring[10];
1161 static char buf[100];
1165 /* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2)
1166 support %n in format strings in read-only memory but not in writable
1168 strcpy (fmtstring, "%d %n");
1169 snprintf (buf, 4, fmtstring, 12345, &count, 33, 44, 55);
1173 }], [gl_cv_func_snprintf_directive_n=yes], [gl_cv_func_snprintf_directive_n=no],
1177 # Guess yes on glibc systems.
1178 *-gnu*) gl_cv_func_snprintf_directive_n="guessing yes";;
1179 # Guess yes on FreeBSD >= 5.
1180 freebsd[1-4]*) gl_cv_func_snprintf_directive_n="guessing no";;
1181 freebsd* | kfreebsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
1182 # Guess yes on MacOS X >= 10.3.
1183 darwin[1-6].*) gl_cv_func_snprintf_directive_n="guessing no";;
1184 darwin*) gl_cv_func_snprintf_directive_n="guessing yes";;
1185 # Guess yes on Solaris >= 2.6.
1186 solaris2.[0-5]*) gl_cv_func_snprintf_directive_n="guessing no";;
1187 solaris*) gl_cv_func_snprintf_directive_n="guessing yes";;
1188 # Guess yes on AIX >= 4.
1189 aix[1-3]*) gl_cv_func_snprintf_directive_n="guessing no";;
1190 aix*) gl_cv_func_snprintf_directive_n="guessing yes";;
1191 # Guess yes on IRIX >= 6.5.
1192 irix6.5) gl_cv_func_snprintf_directive_n="guessing yes";;
1193 # Guess yes on OSF/1 >= 5.
1194 osf[3-4]*) gl_cv_func_snprintf_directive_n="guessing no";;
1195 osf*) gl_cv_func_snprintf_directive_n="guessing yes";;
1196 # Guess yes on NetBSD >= 3.
1197 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1198 gl_cv_func_snprintf_directive_n="guessing no";;
1199 netbsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
1200 # Guess yes on BeOS.
1201 beos*) gl_cv_func_snprintf_directive_n="guessing yes";;
1202 # If we don't know, assume the worst.
1203 *) gl_cv_func_snprintf_directive_n="guessing no";;
1210 dnl Test whether the snprintf function, when passed a size = 1, writes any
1211 dnl output without bounds in this case, behaving like sprintf. This is the
1212 dnl case on Linux libc5.
1213 dnl Result is gl_cv_func_snprintf_size1.
1215 AC_DEFUN([gl_SNPRINTF_SIZE1],
1217 AC_REQUIRE([AC_PROG_CC])
1218 AC_CACHE_CHECK([whether snprintf respects a size of 1],
1219 [gl_cv_func_snprintf_size1],
1225 static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1226 snprintf (buf, 1, "%d", 12345);
1227 return buf[1] != 'E';
1229 [gl_cv_func_snprintf_size1=yes],
1230 [gl_cv_func_snprintf_size1=no],
1231 [gl_cv_func_snprintf_size1="guessing yes"])
1235 dnl Test whether the vsnprintf function, when passed a zero size, produces no
1236 dnl output. (ISO C99, POSIX:2001)
1237 dnl For example, snprintf nevertheless writes a NUL byte in this case
1239 dnl ---------------------------------------------------------------------
1240 dnl #include <stdio.h>
1243 dnl static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1244 dnl snprintf (buf, 0, "%d", 12345);
1245 dnl return buf[0] != 'D';
1247 dnl ---------------------------------------------------------------------
1248 dnl And vsnprintf writes any output without bounds in this case, behaving like
1249 dnl vsprintf, on HP-UX 11 and OSF/1 5.1:
1250 dnl ---------------------------------------------------------------------
1251 dnl #include <stdarg.h>
1252 dnl #include <stdio.h>
1253 dnl static int my_snprintf (char *buf, int size, const char *format, ...)
1257 dnl va_start (args, format);
1258 dnl ret = vsnprintf (buf, size, format, args);
1264 dnl static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1265 dnl my_snprintf (buf, 0, "%d", 12345);
1266 dnl return buf[0] != 'D';
1268 dnl ---------------------------------------------------------------------
1269 dnl Result is gl_cv_func_vsnprintf_zerosize_c99.
1271 AC_DEFUN([gl_VSNPRINTF_ZEROSIZE_C99],
1273 AC_REQUIRE([AC_PROG_CC])
1274 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1275 AC_CACHE_CHECK([whether vsnprintf respects a zero size as in C99],
1276 [gl_cv_func_vsnprintf_zerosize_c99],
1281 static int my_snprintf (char *buf, int size, const char *format, ...)
1285 va_start (args, format);
1286 ret = vsnprintf (buf, size, format, args);
1292 static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1293 my_snprintf (buf, 0, "%d", 12345);
1294 return buf[0] != 'D';
1296 [gl_cv_func_vsnprintf_zerosize_c99=yes],
1297 [gl_cv_func_vsnprintf_zerosize_c99=no],
1301 # Guess yes on glibc systems.
1302 *-gnu*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1303 # Guess yes on FreeBSD >= 5.
1304 freebsd[1-4]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1305 freebsd* | kfreebsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1306 # Guess yes on MacOS X >= 10.3.
1307 darwin[1-6].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1308 darwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1309 # Guess yes on Cygwin.
1310 cygwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1311 # Guess yes on Solaris >= 2.6.
1312 solaris2.[0-5]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1313 solaris*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1314 # Guess yes on AIX >= 4.
1315 aix[1-3]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1316 aix*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1317 # Guess yes on IRIX >= 6.5.
1318 irix6.5) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1319 # Guess yes on NetBSD >= 3.
1320 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1321 gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1322 netbsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1323 # Guess yes on BeOS.
1324 beos*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1325 # Guess yes on mingw.
1326 mingw* | pw*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1327 # If we don't know, assume the worst.
1328 *) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1335 dnl The results of these tests on various platforms are:
1337 dnl 1 = gl_PRINTF_SIZES_C99
1338 dnl 2 = gl_PRINTF_LONG_DOUBLE
1339 dnl 3 = gl_PRINTF_INFINITE
1340 dnl 4 = gl_PRINTF_INFINITE_LONG_DOUBLE
1341 dnl 5 = gl_PRINTF_DIRECTIVE_A
1342 dnl 6 = gl_PRINTF_DIRECTIVE_F
1343 dnl 7 = gl_PRINTF_DIRECTIVE_N
1344 dnl 8 = gl_PRINTF_DIRECTIVE_LS
1345 dnl 9 = gl_PRINTF_POSITIONS
1346 dnl 10 = gl_PRINTF_FLAG_GROUPING
1347 dnl 11 = gl_PRINTF_FLAG_LEFTADJUST
1348 dnl 12 = gl_PRINTF_FLAG_ZERO
1349 dnl 13 = gl_PRINTF_PRECISION
1350 dnl 14 = gl_PRINTF_ENOMEM
1351 dnl 15 = gl_SNPRINTF_PRESENCE
1352 dnl 16 = gl_SNPRINTF_TRUNCATION_C99
1353 dnl 17 = gl_SNPRINTF_RETVAL_C99
1354 dnl 18 = gl_SNPRINTF_DIRECTIVE_N
1355 dnl 19 = gl_SNPRINTF_SIZE1
1356 dnl 20 = gl_VSNPRINTF_ZEROSIZE_C99
1358 dnl 1 = checking whether printf supports size specifiers as in C99...
1359 dnl 2 = checking whether printf supports 'long double' arguments...
1360 dnl 3 = checking whether printf supports infinite 'double' arguments...
1361 dnl 4 = checking whether printf supports infinite 'long double' arguments...
1362 dnl 5 = checking whether printf supports the 'a' and 'A' directives...
1363 dnl 6 = checking whether printf supports the 'F' directive...
1364 dnl 7 = checking whether printf supports the 'n' directive...
1365 dnl 8 = checking whether printf supports the 'ls' directive...
1366 dnl 9 = checking whether printf supports POSIX/XSI format strings with positions...
1367 dnl 10 = checking whether printf supports the grouping flag...
1368 dnl 11 = checking whether printf supports the left-adjust flag correctly...
1369 dnl 12 = checking whether printf supports the zero flag correctly...
1370 dnl 13 = checking whether printf supports large precisions...
1371 dnl 14 = checking whether printf survives out-of-memory conditions...
1372 dnl 15 = checking for snprintf...
1373 dnl 16 = checking whether snprintf truncates the result as in C99...
1374 dnl 17 = checking whether snprintf returns a byte count as in C99...
1375 dnl 18 = checking whether snprintf fully supports the 'n' directive...
1376 dnl 19 = checking whether snprintf respects a size of 1...
1377 dnl 20 = checking whether vsnprintf respects a zero size as in C99...
1379 dnl . = yes, # = no.
1381 dnl 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1382 dnl glibc 2.5 . . . . . . . . . . . . . . . . . . . .
1383 dnl glibc 2.3.6 . . . . # . . . . . . . . . . . . . . .
1384 dnl FreeBSD 5.4, 6.1 . . . . # . . . . . . # . # . . . . . .
1385 dnl MacOS X 10.3.9 . . . . # . . . . . . # . # . . . . . .
1386 dnl OpenBSD 3.9, 4.0 . . # # # # . # . # . # . # . . . . . .
1387 dnl Cygwin 2007 (= Cygwin 1.5.24) . . . . # # . . . . ? # ? ? . . . . . .
1388 dnl Cygwin 2006 (= Cygwin 1.5.19) # . . . # # . ? . # ? # ? ? . . . . . .
1389 dnl Solaris 10 . . # # # . . # . . . # . . . . . . . .
1390 dnl Solaris 2.6 ... 9 # . # # # # . # . . . # . . . . . . . .
1391 dnl Solaris 2.5.1 # . # # # # . # . . . # . . # # # # # #
1392 dnl AIX 5.2 . . # # # . . . . . . # . . . . . . . .
1393 dnl AIX 4.3.2, 5.1 # . # # # # . . . . . # . . . . . . . .
1394 dnl HP-UX 11.31 . . . . # . . . . . . # . . . . # # . .
1395 dnl HP-UX 11.{00,11,23} # . . . # # . . . . . # . . . . # # . #
1396 dnl HP-UX 10.20 # . # . # # . ? . . # # . . . . # # ? #
1397 dnl IRIX 6.5 # . # # # # . # . . . # . . . . # . . .
1398 dnl OSF/1 5.1 # . # # # # . . . . . # . . . . # . . #
1399 dnl OSF/1 4.0d # . # # # # . . . . . # . . # # # # # #
1400 dnl NetBSD 4.0 . ? ? ? ? ? . ? . ? ? ? ? ? . . . ? ? ?
1401 dnl NetBSD 3.0 . . . . # # . ? # # ? # . # . . . . . .
1402 dnl Haiku . . . # # # . # . . . . . ? . . . . . .
1403 dnl BeOS # # . # # # . ? # . ? . # ? . . . . . .
1404 dnl mingw # # # # # # . . # # . # # ? . # # # . .