2 dnl Copyright (C) 2003, 2007 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 in the %f, %e, %g directives. (ISO C99, POSIX:2001)
129 dnl Result is gl_cv_func_printf_infinite.
131 AC_DEFUN([gl_PRINTF_INFINITE],
133 AC_REQUIRE([AC_PROG_CC])
134 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
135 AC_CACHE_CHECK([whether printf supports infinite 'double' arguments],
136 [gl_cv_func_printf_infinite],
142 strisnan (const char *string, size_t start_index, size_t end_index)
144 if (start_index < end_index)
146 if (string[start_index] == '-')
148 if (start_index + 3 <= end_index
149 && memcmp (string + start_index, "nan", 3) == 0)
152 if (start_index == end_index
153 || (string[start_index] == '(' && string[end_index - 1] == ')'))
159 static char buf[10000];
160 static double zero = 0.0;
163 if (sprintf (buf, "%f", 1.0 / 0.0) < 0
164 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
166 if (sprintf (buf, "%f", -1.0 / 0.0) < 0
167 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
169 if (sprintf (buf, "%f", zero / zero) < 0
170 || !strisnan (buf, 0, strlen (buf)))
172 if (sprintf (buf, "%e", 1.0 / 0.0) < 0
173 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
175 if (sprintf (buf, "%e", -1.0 / 0.0) < 0
176 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
178 if (sprintf (buf, "%e", zero / zero) < 0
179 || !strisnan (buf, 0, strlen (buf)))
181 if (sprintf (buf, "%g", 1.0 / 0.0) < 0
182 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
184 if (sprintf (buf, "%g", -1.0 / 0.0) < 0
185 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
187 if (sprintf (buf, "%g", zero / zero) < 0
188 || !strisnan (buf, 0, strlen (buf)))
191 }], [gl_cv_func_printf_infinite=yes], [gl_cv_func_printf_infinite=no],
195 # Guess yes on glibc systems.
196 *-gnu*) gl_cv_func_printf_infinite="guessing yes";;
197 # Guess yes on FreeBSD >= 6.
198 freebsd[1-5]*) gl_cv_func_printf_infinite="guessing no";;
199 freebsd* | kfreebsd*) gl_cv_func_printf_infinite="guessing yes";;
200 # Guess yes on MacOS X >= 10.3.
201 darwin[1-6].*) gl_cv_func_printf_infinite="guessing no";;
202 darwin*) gl_cv_func_printf_infinite="guessing yes";;
203 # Guess yes on HP-UX >= 11.
204 hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite="guessing no";;
205 hpux*) gl_cv_func_printf_infinite="guessing yes";;
206 # Guess yes on NetBSD >= 3.
207 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
208 gl_cv_func_printf_infinite="guessing no";;
209 netbsd*) gl_cv_func_printf_infinite="guessing yes";;
211 beos*) gl_cv_func_printf_infinite="guessing yes";;
212 # If we don't know, assume the worst.
213 *) gl_cv_func_printf_infinite="guessing no";;
220 dnl Test whether the *printf family of functions supports infinite and NaN
221 dnl 'long double' arguments in the %f, %e, %g directives. (ISO C99, POSIX:2001)
222 dnl Result is gl_cv_func_printf_infinite_long_double.
224 AC_DEFUN([gl_PRINTF_INFINITE_LONG_DOUBLE],
226 AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
227 AC_REQUIRE([AC_PROG_CC])
228 AC_REQUIRE([AC_C_BIGENDIAN])
229 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
230 dnl The user can set or unset the variable gl_printf_safe to indicate
231 dnl that he wishes a safe handling of non-IEEE-754 'long double' values.
232 if test -n "$gl_printf_safe"; then
233 AC_DEFINE([CHECK_PRINTF_SAFE], 1,
234 [Define if you wish *printf() functions that have a safe handling of
235 non-IEEE-754 'long double' values.])
237 case "$gl_cv_func_printf_long_double" in
239 AC_CACHE_CHECK([whether printf supports infinite 'long double' arguments],
240 [gl_cv_func_printf_infinite_long_double],
247 strisnan (const char *string, size_t start_index, size_t end_index)
249 if (start_index < end_index)
251 if (string[start_index] == '-')
253 if (start_index + 3 <= end_index
254 && memcmp (string + start_index, "nan", 3) == 0)
257 if (start_index == end_index
258 || (string[start_index] == '(' && string[end_index - 1] == ')'))
264 static char buf[10000];
265 static long double zeroL = 0.0L;
268 if (sprintf (buf, "%Lf", 1.0L / 0.0L) < 0
269 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
271 if (sprintf (buf, "%Lf", -1.0L / 0.0L) < 0
272 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
274 if (sprintf (buf, "%Lf", zeroL / zeroL) < 0
275 || !strisnan (buf, 0, strlen (buf)))
277 if (sprintf (buf, "%Le", 1.0L / 0.0L) < 0
278 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
280 if (sprintf (buf, "%Le", -1.0L / 0.0L) < 0
281 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
283 if (sprintf (buf, "%Le", zeroL / zeroL) < 0
284 || !strisnan (buf, 0, strlen (buf)))
286 if (sprintf (buf, "%Lg", 1.0L / 0.0L) < 0
287 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
289 if (sprintf (buf, "%Lg", -1.0L / 0.0L) < 0
290 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
292 if (sprintf (buf, "%Lg", zeroL / zeroL) < 0
293 || !strisnan (buf, 0, strlen (buf)))
295 #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_))
296 /* Representation of an 80-bit 'long double' as an initializer for a sequence
297 of 'unsigned int' words. */
298 # ifdef WORDS_BIGENDIAN
299 # define LDBL80_WORDS(exponent,manthi,mantlo) \
300 { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
301 ((unsigned int) (manthi) << 16) | (unsigned int) (mantlo) >> 16), \
302 (unsigned int) (mantlo) << 16 \
305 # define LDBL80_WORDS(exponent,manthi,mantlo) \
306 { mantlo, manthi, exponent }
309 static union { unsigned int word[4]; long double value; } x =
310 { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
311 if (sprintf (buf, "%Lf", x.value) < 0
312 || !strisnan (buf, 0, strlen (buf)))
314 if (sprintf (buf, "%Le", x.value) < 0
315 || !strisnan (buf, 0, strlen (buf)))
317 if (sprintf (buf, "%Lg", x.value) < 0
318 || !strisnan (buf, 0, strlen (buf)))
322 /* Signalling NaN. */
323 static union { unsigned int word[4]; long double value; } x =
324 { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
325 if (sprintf (buf, "%Lf", x.value) < 0
326 || !strisnan (buf, 0, strlen (buf)))
328 if (sprintf (buf, "%Le", x.value) < 0
329 || !strisnan (buf, 0, strlen (buf)))
331 if (sprintf (buf, "%Lg", x.value) < 0
332 || !strisnan (buf, 0, strlen (buf)))
336 static union { unsigned int word[4]; long double value; } x =
337 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
338 if (sprintf (buf, "%Lf", x.value) < 0
339 || !strisnan (buf, 0, strlen (buf)))
341 if (sprintf (buf, "%Le", x.value) < 0
342 || !strisnan (buf, 0, strlen (buf)))
344 if (sprintf (buf, "%Lg", x.value) < 0
345 || !strisnan (buf, 0, strlen (buf)))
348 { /* Pseudo-Infinity. */
349 static union { unsigned int word[4]; long double value; } x =
350 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
351 if (sprintf (buf, "%Lf", x.value) < 0
352 || !strisnan (buf, 0, strlen (buf)))
354 if (sprintf (buf, "%Le", x.value) < 0
355 || !strisnan (buf, 0, strlen (buf)))
357 if (sprintf (buf, "%Lg", x.value) < 0
358 || !strisnan (buf, 0, strlen (buf)))
362 static union { unsigned int word[4]; long double value; } x =
363 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
364 if (sprintf (buf, "%Lf", x.value) < 0
365 || !strisnan (buf, 0, strlen (buf)))
367 if (sprintf (buf, "%Le", x.value) < 0
368 || !strisnan (buf, 0, strlen (buf)))
370 if (sprintf (buf, "%Lg", x.value) < 0
371 || !strisnan (buf, 0, strlen (buf)))
374 { /* Unnormalized number. */
375 static union { unsigned int word[4]; long double value; } x =
376 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
377 if (sprintf (buf, "%Lf", x.value) < 0
378 || !strisnan (buf, 0, strlen (buf)))
380 if (sprintf (buf, "%Le", x.value) < 0
381 || !strisnan (buf, 0, strlen (buf)))
383 if (sprintf (buf, "%Lg", x.value) < 0
384 || !strisnan (buf, 0, strlen (buf)))
387 { /* Pseudo-Denormal. */
388 static union { unsigned int word[4]; long double value; } x =
389 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
390 if (sprintf (buf, "%Lf", x.value) < 0
391 || !strisnan (buf, 0, strlen (buf)))
393 if (sprintf (buf, "%Le", x.value) < 0
394 || !strisnan (buf, 0, strlen (buf)))
396 if (sprintf (buf, "%Lg", x.value) < 0
397 || !strisnan (buf, 0, strlen (buf)))
403 [gl_cv_func_printf_infinite_long_double=yes],
404 [gl_cv_func_printf_infinite_long_double=no],
408 # Guess no on ia64, x86_64, i386.
409 ia64 | x86_64 | i*86) gl_cv_func_printf_infinite_long_double="guessing no";;
412 # Guess yes on glibc systems.
413 *-gnu*) gl_cv_func_printf_infinite_long_double="guessing yes";;
414 # Guess yes on FreeBSD >= 6.
415 freebsd[1-5]*) gl_cv_func_printf_infinite_long_double="guessing no";;
416 freebsd* | kfreebsd*) gl_cv_func_printf_infinite_long_double="guessing yes";;
417 # Guess yes on MacOS X >= 10.3.
418 darwin[1-6].*) gl_cv_func_printf_infinite_long_double="guessing no";;
419 darwin*) gl_cv_func_printf_infinite_long_double="guessing yes";;
420 # Guess yes on HP-UX >= 11.
421 hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite_long_double="guessing no";;
422 hpux*) gl_cv_func_printf_infinite_long_double="guessing yes";;
423 # Guess yes on NetBSD >= 3.
424 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
425 gl_cv_func_printf_infinite_long_double="guessing no";;
426 netbsd*) gl_cv_func_printf_infinite_long_double="guessing yes";;
427 # If we don't know, assume the worst.
428 *) gl_cv_func_printf_infinite_long_double="guessing no";;
437 gl_cv_func_printf_infinite_long_double="irrelevant"
442 dnl Test whether the *printf family of functions supports the 'a' and 'A'
443 dnl conversion specifier for hexadecimal output of floating-point numbers.
444 dnl (ISO C99, POSIX:2001)
445 dnl Result is gl_cv_func_printf_directive_a.
447 AC_DEFUN([gl_PRINTF_DIRECTIVE_A],
449 AC_REQUIRE([AC_PROG_CC])
450 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
451 AC_CACHE_CHECK([whether printf supports the 'a' and 'A' directives],
452 [gl_cv_func_printf_directive_a],
457 static char buf[100];
460 if (sprintf (buf, "%a %d", 3.1416015625, 33, 44, 55) < 0
461 || (strcmp (buf, "0x1.922p+1 33") != 0
462 && strcmp (buf, "0x3.244p+0 33") != 0
463 && strcmp (buf, "0x6.488p-1 33") != 0
464 && strcmp (buf, "0xc.91p-2 33") != 0))
466 if (sprintf (buf, "%A %d", -3.1416015625, 33, 44, 55) < 0
467 || (strcmp (buf, "-0X1.922P+1 33") != 0
468 && strcmp (buf, "-0X3.244P+0 33") != 0
469 && strcmp (buf, "-0X6.488P-1 33") != 0
470 && strcmp (buf, "-0XC.91P-2 33") != 0))
472 /* This catches a FreeBSD 6.1 bug: it doesn't round. */
473 if (sprintf (buf, "%.2a %d", 1.51, 33, 44, 55) < 0
474 || (strcmp (buf, "0x1.83p+0 33") != 0
475 && strcmp (buf, "0x3.05p-1 33") != 0
476 && strcmp (buf, "0x6.0ap-2 33") != 0
477 && strcmp (buf, "0xc.14p-3 33") != 0))
479 /* This catches a FreeBSD 6.1 bug. See
480 <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
481 if (sprintf (buf, "%010a %d", 1.0 / 0.0, 33, 44, 55) < 0
484 /* This catches a MacOS X 10.3.9 (Darwin 7.9) bug. */
485 if (sprintf (buf, "%.1a", 1.999) < 0
486 || (strcmp (buf, "0x1.0p+1") != 0
487 && strcmp (buf, "0x2.0p+0") != 0
488 && strcmp (buf, "0x4.0p-1") != 0
489 && strcmp (buf, "0x8.0p-2") != 0))
491 /* This catches the same MacOS X 10.3.9 (Darwin 7.9) bug and also a
492 glibc 2.4 bug <http://sourceware.org/bugzilla/show_bug.cgi?id=2908>. */
493 if (sprintf (buf, "%.1La", 1.999L) < 0
494 || (strcmp (buf, "0x1.0p+1") != 0
495 && strcmp (buf, "0x2.0p+0") != 0
496 && strcmp (buf, "0x4.0p-1") != 0
497 && strcmp (buf, "0x8.0p-2") != 0))
500 }], [gl_cv_func_printf_directive_a=yes], [gl_cv_func_printf_directive_a=no],
503 # Guess yes on glibc >= 2.5 systems.
505 AC_EGREP_CPP([BZ2908], [
506 #include <features.h>
507 #ifdef __GNU_LIBRARY__
508 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 5) || (__GLIBC__ > 2)
513 [gl_cv_func_printf_directive_a="guessing yes"],
514 [gl_cv_func_printf_directive_a="guessing no"])
516 # If we don't know, assume the worst.
517 *) gl_cv_func_printf_directive_a="guessing no";;
523 dnl Test whether the *printf family of functions supports the %F format
524 dnl directive. (ISO C99, POSIX:2001)
525 dnl Result is gl_cv_func_printf_directive_f.
527 AC_DEFUN([gl_PRINTF_DIRECTIVE_F],
529 AC_REQUIRE([AC_PROG_CC])
530 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
531 AC_CACHE_CHECK([whether printf supports the 'F' directive],
532 [gl_cv_func_printf_directive_f],
537 static char buf[100];
540 if (sprintf (buf, "%F %d", 1234567.0, 33, 44, 55) < 0
541 || strcmp (buf, "1234567.000000 33") != 0)
543 if (sprintf (buf, "%F", 1.0 / 0.0) < 0
544 || (strcmp (buf, "INF") != 0 && strcmp (buf, "INFINITY") != 0))
546 /* This catches a Cygwin 2007 bug. */
547 if (sprintf (buf, "%.F", 1234.0) < 0
548 || strcmp (buf, "1234") != 0)
551 }], [gl_cv_func_printf_directive_f=yes], [gl_cv_func_printf_directive_f=no],
555 # Guess yes on glibc systems.
556 *-gnu*) gl_cv_func_printf_directive_f="guessing yes";;
557 # Guess yes on FreeBSD >= 6.
558 freebsd[1-5]*) gl_cv_func_printf_directive_f="guessing no";;
559 freebsd* | kfreebsd*) gl_cv_func_printf_directive_f="guessing yes";;
560 # Guess yes on MacOS X >= 10.3.
561 darwin[1-6].*) gl_cv_func_printf_directive_f="guessing no";;
562 darwin*) gl_cv_func_printf_directive_f="guessing yes";;
563 # Guess yes on Solaris >= 2.10.
564 solaris2.[0-9]*) gl_cv_func_printf_directive_f="guessing no";;
565 solaris*) gl_cv_func_printf_directive_f="guessing yes";;
566 # If we don't know, assume the worst.
567 *) gl_cv_func_printf_directive_f="guessing no";;
574 dnl Test whether the *printf family of functions supports the %n format
575 dnl directive. (ISO C99, POSIX:2001)
576 dnl Result is gl_cv_func_printf_directive_n.
578 AC_DEFUN([gl_PRINTF_DIRECTIVE_N],
580 AC_REQUIRE([AC_PROG_CC])
581 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
582 AC_CACHE_CHECK([whether printf supports the 'n' directive],
583 [gl_cv_func_printf_directive_n],
588 static char buf[100];
592 if (sprintf (buf, "%d %n", 123, &count, 33, 44, 55) < 0
593 || strcmp (buf, "123 ") != 0
597 }], [gl_cv_func_printf_directive_n=yes], [gl_cv_func_printf_directive_n=no],
601 *) gl_cv_func_printf_directive_n="guessing yes";;
608 dnl Test whether the *printf family of functions supports POSIX/XSI format
609 dnl strings with positions. (POSIX:2001)
610 dnl Result is gl_cv_func_printf_positions.
612 AC_DEFUN([gl_PRINTF_POSITIONS],
614 AC_REQUIRE([AC_PROG_CC])
615 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
616 AC_CACHE_CHECK([whether printf supports POSIX/XSI format strings with positions],
617 [gl_cv_func_printf_positions],
622 /* The string "%2$d %1$d", with dollar characters protected from the shell's
623 dollar expansion (possibly an autoconf bug). */
624 static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' };
625 static char buf[100];
628 sprintf (buf, format, 33, 55);
629 return (strcmp (buf, "55 33") != 0);
630 }], [gl_cv_func_printf_positions=yes], [gl_cv_func_printf_positions=no],
634 netbsd[1-3]* | netbsdelf[1-3]* | netbsdaout[1-3]* | netbsdcoff[1-3]*)
635 gl_cv_func_printf_positions="guessing no";;
636 beos*) gl_cv_func_printf_positions="guessing no";;
637 mingw* | pw*) gl_cv_func_printf_positions="guessing no";;
638 *) gl_cv_func_printf_positions="guessing yes";;
645 dnl Test whether the *printf family of functions supports POSIX/XSI format
646 dnl strings with the ' flag for grouping of decimal digits. (POSIX:2001)
647 dnl Result is gl_cv_func_printf_flag_grouping.
649 AC_DEFUN([gl_PRINTF_FLAG_GROUPING],
651 AC_REQUIRE([AC_PROG_CC])
652 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
653 AC_CACHE_CHECK([whether printf supports the grouping flag],
654 [gl_cv_func_printf_flag_grouping],
659 static char buf[100];
662 if (sprintf (buf, "%'d %d", 1234567, 99) < 0
663 || buf[strlen (buf) - 1] != '9')
666 }], [gl_cv_func_printf_flag_grouping=yes], [gl_cv_func_printf_flag_grouping=no],
670 cygwin*) gl_cv_func_printf_flag_grouping="guessing no";;
671 netbsd*) gl_cv_func_printf_flag_grouping="guessing no";;
672 mingw* | pw*) gl_cv_func_printf_flag_grouping="guessing no";;
673 *) gl_cv_func_printf_flag_grouping="guessing yes";;
680 dnl Test whether the *printf family of functions supports padding of non-finite
681 dnl values with the 0 flag correctly. (ISO C99 + TC1 + TC2.) See
682 dnl <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html>
683 dnl Result is gl_cv_func_printf_flag_zero.
685 AC_DEFUN([gl_PRINTF_FLAG_ZERO],
687 AC_REQUIRE([AC_PROG_CC])
688 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
689 AC_CACHE_CHECK([whether printf supports the zero flag correctly],
690 [gl_cv_func_printf_flag_zero],
695 static char buf[100];
698 if (sprintf (buf, "%010f", 1.0 / 0.0, 33, 44, 55) < 0
699 || (strcmp (buf, " inf") != 0
700 && strcmp (buf, " infinity") != 0))
703 }], [gl_cv_func_printf_flag_zero=yes], [gl_cv_func_printf_flag_zero=no],
707 # Guess yes on glibc systems.
708 *-gnu*) gl_cv_func_printf_flag_zero="guessing yes";;
710 beos*) gl_cv_func_printf_flag_zero="guessing yes";;
711 # If we don't know, assume the worst.
712 *) gl_cv_func_printf_flag_zero="guessing no";;
719 dnl Test whether the snprintf function exists. (ISO C99, POSIX:2001)
720 dnl Result is ac_cv_func_snprintf.
722 AC_DEFUN([gl_SNPRINTF_PRESENCE],
724 AC_CHECK_FUNCS_ONCE([snprintf])
727 dnl Test whether the string produced by the snprintf function is always NUL
728 dnl terminated. (ISO C99, POSIX:2001)
729 dnl Result is gl_cv_func_snprintf_truncation_c99.
731 AC_DEFUN([gl_SNPRINTF_TRUNCATION_C99],
733 AC_REQUIRE([AC_PROG_CC])
734 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
735 AC_CACHE_CHECK([whether snprintf truncates the result as in C99],
736 [gl_cv_func_snprintf_truncation_c99],
741 static char buf[100];
744 strcpy (buf, "ABCDEF");
745 snprintf (buf, 3, "%d %d", 4567, 89);
746 if (memcmp (buf, "45\0DEF", 6) != 0)
749 }], [gl_cv_func_snprintf_truncation_c99=yes], [gl_cv_func_snprintf_truncation_c99=no],
753 # Guess yes on glibc systems.
754 *-gnu*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
755 # Guess yes on FreeBSD >= 5.
756 freebsd[1-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
757 freebsd* | kfreebsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
758 # Guess yes on MacOS X >= 10.3.
759 darwin[1-6].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
760 darwin*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
761 # Guess yes on OpenBSD >= 3.9.
762 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
763 gl_cv_func_snprintf_truncation_c99="guessing no";;
764 openbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
765 # Guess yes on Solaris >= 2.6.
766 solaris2.[0-5]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
767 solaris*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
768 # Guess yes on AIX >= 4.
769 aix[1-3]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
770 aix*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
771 # Guess yes on HP-UX >= 11.
772 hpux[7-9]* | hpux10*) gl_cv_func_snprintf_truncation_c99="guessing no";;
773 hpux*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
774 # Guess yes on IRIX >= 6.5.
775 irix6.5) gl_cv_func_snprintf_truncation_c99="guessing yes";;
776 # Guess yes on OSF/1 >= 5.
777 osf[3-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
778 osf*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
779 # Guess yes on NetBSD >= 3.
780 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
781 gl_cv_func_snprintf_truncation_c99="guessing no";;
782 netbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
784 beos*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
785 # If we don't know, assume the worst.
786 *) gl_cv_func_snprintf_truncation_c99="guessing no";;
793 dnl Test whether the return value of the snprintf function is the number
794 dnl of bytes (excluding the terminating NUL) that would have been produced
795 dnl if the buffer had been large enough. (ISO C99, POSIX:2001)
796 dnl For example, this test program fails on IRIX 6.5:
797 dnl ---------------------------------------------------------------------
798 dnl #include <stdio.h>
801 dnl static char buf[8];
802 dnl int retval = snprintf (buf, 3, "%d", 12345);
803 dnl return retval >= 0 && retval < 3;
805 dnl ---------------------------------------------------------------------
806 dnl Result is gl_cv_func_snprintf_retval_c99.
808 AC_DEFUN([gl_SNPRINTF_RETVAL_C99],
810 AC_REQUIRE([AC_PROG_CC])
811 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
812 AC_CACHE_CHECK([whether snprintf returns a byte count as in C99],
813 [gl_cv_func_snprintf_retval_c99],
818 static char buf[100];
821 strcpy (buf, "ABCDEF");
822 if (snprintf (buf, 3, "%d %d", 4567, 89) != 7)
825 }], [gl_cv_func_snprintf_retval_c99=yes], [gl_cv_func_snprintf_retval_c99=no],
829 # Guess yes on glibc systems.
830 *-gnu*) gl_cv_func_snprintf_retval_c99="guessing yes";;
831 # Guess yes on FreeBSD >= 5.
832 freebsd[1-4]*) gl_cv_func_snprintf_retval_c99="guessing no";;
833 freebsd* | kfreebsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
834 # Guess yes on MacOS X >= 10.3.
835 darwin[1-6].*) gl_cv_func_snprintf_retval_c99="guessing no";;
836 darwin*) gl_cv_func_snprintf_retval_c99="guessing yes";;
837 # Guess yes on OpenBSD >= 3.9.
838 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
839 gl_cv_func_snprintf_retval_c99="guessing no";;
840 openbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
841 # Guess yes on Solaris >= 2.6.
842 solaris2.[0-5]*) gl_cv_func_snprintf_retval_c99="guessing no";;
843 solaris*) gl_cv_func_snprintf_retval_c99="guessing yes";;
844 # Guess yes on AIX >= 4.
845 aix[1-3]*) gl_cv_func_snprintf_retval_c99="guessing no";;
846 aix*) gl_cv_func_snprintf_retval_c99="guessing yes";;
847 # Guess yes on NetBSD >= 3.
848 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
849 gl_cv_func_snprintf_retval_c99="guessing no";;
850 netbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
852 beos*) gl_cv_func_snprintf_retval_c99="guessing yes";;
853 # If we don't know, assume the worst.
854 *) gl_cv_func_snprintf_retval_c99="guessing no";;
861 dnl Test whether the snprintf function supports the %n format directive
862 dnl also in truncated portions of the format string. (ISO C99, POSIX:2001)
863 dnl Result is gl_cv_func_snprintf_directive_n.
865 AC_DEFUN([gl_SNPRINTF_DIRECTIVE_N],
867 AC_REQUIRE([AC_PROG_CC])
868 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
869 AC_CACHE_CHECK([whether snprintf fully supports the 'n' directive],
870 [gl_cv_func_snprintf_directive_n],
875 static char buf[100];
879 snprintf (buf, 4, "%d %n", 12345, &count, 33, 44, 55);
883 }], [gl_cv_func_snprintf_directive_n=yes], [gl_cv_func_snprintf_directive_n=no],
887 # Guess yes on glibc systems.
888 *-gnu*) gl_cv_func_snprintf_directive_n="guessing yes";;
889 # Guess yes on FreeBSD >= 5.
890 freebsd[1-4]*) gl_cv_func_snprintf_directive_n="guessing no";;
891 freebsd* | kfreebsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
892 # Guess yes on MacOS X >= 10.3.
893 darwin[1-6].*) gl_cv_func_snprintf_directive_n="guessing no";;
894 darwin*) gl_cv_func_snprintf_directive_n="guessing yes";;
895 # Guess yes on Solaris >= 2.6.
896 solaris2.[0-5]*) gl_cv_func_snprintf_directive_n="guessing no";;
897 solaris*) gl_cv_func_snprintf_directive_n="guessing yes";;
898 # Guess yes on AIX >= 4.
899 aix[1-3]*) gl_cv_func_snprintf_directive_n="guessing no";;
900 aix*) gl_cv_func_snprintf_directive_n="guessing yes";;
901 # Guess yes on IRIX >= 6.5.
902 irix6.5) gl_cv_func_snprintf_directive_n="guessing yes";;
903 # Guess yes on OSF/1 >= 5.
904 osf[3-4]*) gl_cv_func_snprintf_directive_n="guessing no";;
905 osf*) gl_cv_func_snprintf_directive_n="guessing yes";;
906 # Guess yes on NetBSD >= 3.
907 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
908 gl_cv_func_snprintf_directive_n="guessing no";;
909 netbsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
911 beos*) gl_cv_func_snprintf_directive_n="guessing yes";;
912 # If we don't know, assume the worst.
913 *) gl_cv_func_snprintf_directive_n="guessing no";;
920 dnl Test whether the vsnprintf function, when passed a zero size, produces no
921 dnl output. (ISO C99, POSIX:2001)
922 dnl For example, snprintf nevertheless writes a NUL byte in this case
924 dnl ---------------------------------------------------------------------
925 dnl #include <stdio.h>
928 dnl static char buf[8] = "DEADBEEF";
929 dnl snprintf (buf, 0, "%d", 12345);
930 dnl return buf[0] != 'D';
932 dnl ---------------------------------------------------------------------
933 dnl And vsnprintf writes any output without bounds in this case, behaving like
934 dnl vsprintf, on HP-UX 11 and OSF/1 5.1:
935 dnl ---------------------------------------------------------------------
936 dnl #include <stdarg.h>
937 dnl #include <stdio.h>
938 dnl static int my_snprintf (char *buf, int size, const char *format, ...)
942 dnl va_start (args, format);
943 dnl ret = vsnprintf (buf, size, format, args);
949 dnl static char buf[8] = "DEADBEEF";
950 dnl my_snprintf (buf, 0, "%d", 12345);
951 dnl return buf[0] != 'D';
953 dnl ---------------------------------------------------------------------
954 dnl Result is gl_cv_func_vsnprintf_zerosize_c99.
956 AC_DEFUN([gl_VSNPRINTF_ZEROSIZE_C99],
958 AC_REQUIRE([AC_PROG_CC])
959 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
960 AC_CACHE_CHECK([whether vsnprintf respects a zero size as in C99],
961 [gl_cv_func_vsnprintf_zerosize_c99],
966 static int my_snprintf (char *buf, int size, const char *format, ...)
970 va_start (args, format);
971 ret = vsnprintf (buf, size, format, args);
977 static char buf[8] = "DEADBEEF";
978 my_snprintf (buf, 0, "%d", 12345);
979 return buf[0] != 'D';
981 [gl_cv_func_vsnprintf_zerosize_c99=yes],
982 [gl_cv_func_vsnprintf_zerosize_c99=no],
986 # Guess yes on glibc systems.
987 *-gnu*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
988 # Guess yes on FreeBSD >= 5.
989 freebsd[1-4]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
990 freebsd* | kfreebsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
991 # Guess yes on MacOS X >= 10.3.
992 darwin[1-6].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
993 darwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
994 # Guess yes on Cygwin.
995 cygwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
996 # Guess yes on Solaris >= 2.6.
997 solaris2.[0-5]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
998 solaris*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
999 # Guess yes on AIX >= 4.
1000 aix[1-3]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1001 aix*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1002 # Guess yes on IRIX >= 6.5.
1003 irix6.5) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1004 # Guess yes on NetBSD >= 3.
1005 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1006 gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1007 netbsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1008 # Guess yes on BeOS.
1009 beos*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1010 # Guess yes on mingw.
1011 mingw* | pw*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1012 # If we don't know, assume the worst.
1013 *) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1020 dnl The results of these tests on various platforms are:
1022 dnl 1 = gl_PRINTF_SIZES_C99
1023 dnl 2 = gl_PRINTF_LONG_DOUBLE
1024 dnl 3 = gl_PRINTF_INFINITE
1025 dnl 4 = gl_PRINTF_INFINITE_LONG_DOUBLE
1026 dnl 5 = gl_PRINTF_DIRECTIVE_A
1027 dnl 6 = gl_PRINTF_DIRECTIVE_F
1028 dnl 7 = gl_PRINTF_DIRECTIVE_N
1029 dnl 8 = gl_PRINTF_POSITIONS
1030 dnl 9 = gl_PRINTF_FLAG_GROUPING
1031 dnl 10 = gl_PRINTF_FLAG_ZERO
1032 dnl 11 = gl_SNPRINTF_PRESENCE
1033 dnl 12 = gl_SNPRINTF_TRUNCATION_C99
1034 dnl 13 = gl_SNPRINTF_RETVAL_C99
1035 dnl 14 = gl_SNPRINTF_DIRECTIVE_N
1036 dnl 15 = gl_VSNPRINTF_ZEROSIZE_C99
1038 dnl 1 = checking whether printf supports size specifiers as in C99...
1039 dnl 2 = checking whether printf supports 'long double' arguments...
1040 dnl 3 = checking whether printf supports infinite 'double' arguments...
1041 dnl 4 = checking whether printf supports infinite 'long double' arguments...
1042 dnl 5 = checking whether printf supports the 'a' and 'A' directives...
1043 dnl 6 = checking whether printf supports the 'F' directive...
1044 dnl 7 = checking whether printf supports the 'n' directive...
1045 dnl 8 = checking whether printf supports POSIX/XSI format strings with positions...
1046 dnl 9 = checking whether printf supports the grouping flag...
1047 dnl 10 = checking whether printf supports the zero flag correctly...
1048 dnl 11 = checking for snprintf...
1049 dnl 12 = checking whether snprintf truncates the result as in C99...
1050 dnl 13 = checking whether snprintf returns a byte count as in C99...
1051 dnl 14 = checking whether snprintf fully supports the 'n' directive...
1052 dnl 15 = checking whether vsnprintf respects a zero size as in C99...
1054 dnl . = yes, # = no.
1056 dnl 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
1057 dnl glibc 2.5 . . . . . . . . . . . . . . .
1058 dnl glibc 2.3.6 . . . . # . . . . . . . . . .
1059 dnl FreeBSD 5.4, 6.1 . . . . # . . . . # . . . . .
1060 dnl MacOS X 10.3.9 . . . . # . . . . # . . . . .
1061 dnl OpenBSD 3.9, 4.0 . ? ? ? # ? . . ? ? . . . ? ?
1062 dnl Cygwin 2007 (= Cygwin 1.5.24) . . . . # # . . . # . . . . .
1063 dnl Cygwin 2006 (= Cygwin 1.5.19) # . . . # # . . # # . . . . .
1064 dnl Solaris 10 . . # # # . . . . # . . . . .
1065 dnl Solaris 2.6 ... 9 # . # # # # . . . # . . . . .
1066 dnl Solaris 2.5.1 # . # # # # . . . # # # # # #
1067 dnl AIX 5.2 . . # # # . . . . # . . . . .
1068 dnl AIX 4.3.2, 5.1 # . # # # # . . . # . . . . .
1069 dnl HP-UX 11.31 . . . . # . . . . # . . # # .
1070 dnl HP-UX 10.20, 11.{00,11,23} # . . . # # . . . # . . # # #
1071 dnl IRIX 6.5 # . # # # # . . . # . . # . .
1072 dnl OSF/1 5.1 # . # # # # . . . # . . # . #
1073 dnl OSF/1 4.0d # . # # # # . . . # # # # # #
1074 dnl NetBSD 4.0 . ? ? ? ? ? . . ? ? . . . ? ?
1075 dnl NetBSD 3.0 . . . . # # . # # # . . . . .
1076 dnl BeOS # # . # # # . # . . . . . . .
1077 dnl mingw # # # # # # . # # # . # # # .