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],
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 'double'
128 dnl 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],
141 static char buf[100];
144 if (sprintf (buf, "%f", 1.0 / 0.0) < 0
145 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
147 if (sprintf (buf, "%f", -1.0 / 0.0) < 0
148 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
150 if (sprintf (buf, "%e", 1.0 / 0.0) < 0
151 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
153 if (sprintf (buf, "%e", -1.0 / 0.0) < 0
154 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
156 if (sprintf (buf, "%g", 1.0 / 0.0) < 0
157 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
159 if (sprintf (buf, "%g", -1.0 / 0.0) < 0
160 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
163 }], [gl_cv_func_printf_infinite=yes], [gl_cv_func_printf_infinite=no],
167 # Guess yes on glibc systems.
168 *-gnu*) gl_cv_func_printf_infinite="guessing yes";;
169 # Guess yes on FreeBSD >= 6.
170 freebsd[1-5]*) gl_cv_func_printf_infinite="guessing no";;
171 freebsd* | kfreebsd*) gl_cv_func_printf_infinite="guessing yes";;
172 # Guess yes on MacOS X >= 10.3.
173 darwin[1-6].*) gl_cv_func_printf_infinite="guessing no";;
174 darwin*) gl_cv_func_printf_infinite="guessing yes";;
175 # Guess yes on HP-UX >= 11.
176 hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite="guessing no";;
177 hpux*) gl_cv_func_printf_infinite="guessing yes";;
178 # Guess yes on IRIX >= 6.5.
179 irix6.5) gl_cv_func_printf_infinite="guessing yes";;
180 # Guess yes on NetBSD >= 3.
181 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
182 gl_cv_func_printf_infinite="guessing no";;
183 netbsd*) gl_cv_func_printf_infinite="guessing yes";;
185 beos*) gl_cv_func_printf_infinite="guessing yes";;
186 # If we don't know, assume the worst.
187 *) gl_cv_func_printf_infinite="guessing no";;
194 dnl Test whether the *printf family of functions supports infinite 'long double'
195 dnl arguments in the %f, %e, %g directives. (ISO C99, POSIX:2001)
196 dnl Result is gl_cv_func_printf_infinite_long_double.
198 AC_DEFUN([gl_PRINTF_INFINITE_LONG_DOUBLE],
200 AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
201 AC_REQUIRE([AC_PROG_CC])
202 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
203 case "$gl_cv_func_printf_long_double" in
205 AC_CACHE_CHECK([whether printf supports infinite 'long double' arguments],
206 [gl_cv_func_printf_infinite_long_double],
211 static char buf[100];
214 if (sprintf (buf, "%Lf", 1.0L / 0.0L) < 0
215 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
217 if (sprintf (buf, "%Lf", -1.0L / 0.0L) < 0
218 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
220 if (sprintf (buf, "%Le", 1.0L / 0.0L) < 0
221 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
223 if (sprintf (buf, "%Le", -1.0L / 0.0L) < 0
224 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
226 if (sprintf (buf, "%Lg", 1.0L / 0.0L) < 0
227 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
229 if (sprintf (buf, "%Lg", -1.0L / 0.0L) < 0
230 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
234 [gl_cv_func_printf_infinite_long_double=yes],
235 [gl_cv_func_printf_infinite_long_double=no],
239 # Guess yes on glibc systems.
240 *-gnu*) gl_cv_func_printf_infinite_long_double="guessing yes";;
241 # Guess yes on FreeBSD >= 6.
242 freebsd[1-5]*) gl_cv_func_printf_infinite_long_double="guessing no";;
243 freebsd* | kfreebsd*) gl_cv_func_printf_infinite_long_double="guessing yes";;
244 # Guess yes on MacOS X >= 10.3.
245 darwin[1-6].*) gl_cv_func_printf_infinite_long_double="guessing no";;
246 darwin*) gl_cv_func_printf_infinite_long_double="guessing yes";;
247 # Guess yes on HP-UX >= 11.
248 hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite_long_double="guessing no";;
249 hpux*) gl_cv_func_printf_infinite_long_double="guessing yes";;
250 # Guess yes on IRIX >= 6.5.
251 irix6.5) gl_cv_func_printf_infinite_long_double="guessing yes";;
252 # Guess yes on NetBSD >= 3.
253 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
254 gl_cv_func_printf_infinite_long_double="guessing no";;
255 netbsd*) gl_cv_func_printf_infinite_long_double="guessing yes";;
256 # If we don't know, assume the worst.
257 *) gl_cv_func_printf_infinite_long_double="guessing no";;
264 gl_cv_func_printf_infinite_long_double="irrelevant"
269 dnl Test whether the *printf family of functions supports the 'a' and 'A'
270 dnl conversion specifier for hexadecimal output of floating-point numbers.
271 dnl (ISO C99, POSIX:2001)
272 dnl Result is gl_cv_func_printf_directive_a.
274 AC_DEFUN([gl_PRINTF_DIRECTIVE_A],
276 AC_REQUIRE([AC_PROG_CC])
277 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
278 AC_CACHE_CHECK([whether printf supports the 'a' and 'A' directives],
279 [gl_cv_func_printf_directive_a],
284 static char buf[100];
287 if (sprintf (buf, "%a %d", 3.1416015625, 33, 44, 55) < 0
288 || (strcmp (buf, "0x1.922p+1 33") != 0
289 && strcmp (buf, "0x3.244p+0 33") != 0
290 && strcmp (buf, "0x6.488p-1 33") != 0
291 && strcmp (buf, "0xc.91p-2 33") != 0))
293 if (sprintf (buf, "%A %d", -3.1416015625, 33, 44, 55) < 0
294 || (strcmp (buf, "-0X1.922P+1 33") != 0
295 && strcmp (buf, "-0X3.244P+0 33") != 0
296 && strcmp (buf, "-0X6.488P-1 33") != 0
297 && strcmp (buf, "-0XC.91P-2 33") != 0))
299 /* This catches a FreeBSD 6.1 bug: it doesn't round. */
300 if (sprintf (buf, "%.2a %d", 1.51, 33, 44, 55) < 0
301 || (strcmp (buf, "0x1.83p+0 33") != 0
302 && strcmp (buf, "0x3.05p-1 33") != 0
303 && strcmp (buf, "0x6.0ap-2 33") != 0
304 && strcmp (buf, "0xc.14p-3 33") != 0))
306 /* This catches a FreeBSD 6.1 bug. See
307 <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
308 if (sprintf (buf, "%010a %d", 1.0 / 0.0, 33, 44, 55) < 0
311 /* This catches a MacOS X 10.3.9 (Darwin 7.9) bug. */
312 if (sprintf (buf, "%.1a", 1.999) < 0
313 || (strcmp (buf, "0x1.0p+1") != 0
314 && strcmp (buf, "0x2.0p+0") != 0
315 && strcmp (buf, "0x4.0p-1") != 0
316 && strcmp (buf, "0x8.0p-2") != 0))
318 /* This catches the same MacOS X 10.3.9 (Darwin 7.9) bug and also a
319 glibc 2.4 bug <http://sourceware.org/bugzilla/show_bug.cgi?id=2908>. */
320 if (sprintf (buf, "%.1La", 1.999L) < 0
321 || (strcmp (buf, "0x1.0p+1") != 0
322 && strcmp (buf, "0x2.0p+0") != 0
323 && strcmp (buf, "0x4.0p-1") != 0
324 && strcmp (buf, "0x8.0p-2") != 0))
327 }], [gl_cv_func_printf_directive_a=yes], [gl_cv_func_printf_directive_a=no],
330 # Guess yes on glibc >= 2.5 systems.
332 AC_EGREP_CPP([BZ2908], [
333 #include <features.h>
334 #ifdef __GNU_LIBRARY__
335 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 5) || (__GLIBC__ > 2)
340 [gl_cv_func_printf_directive_a="guessing yes"],
341 [gl_cv_func_printf_directive_a="guessing no"])
343 # If we don't know, assume the worst.
344 *) gl_cv_func_printf_directive_a="guessing no";;
350 dnl Test whether the *printf family of functions supports the %F format
351 dnl directive. (ISO C99, POSIX:2001)
352 dnl Result is gl_cv_func_printf_directive_f.
354 AC_DEFUN([gl_PRINTF_DIRECTIVE_F],
356 AC_REQUIRE([AC_PROG_CC])
357 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
358 AC_CACHE_CHECK([whether printf supports the 'F' directive],
359 [gl_cv_func_printf_directive_f],
364 static char buf[100];
367 if (sprintf (buf, "%F %d", 1234567.0, 33, 44, 55) < 0
368 || strcmp (buf, "1234567.000000 33") != 0)
370 if (sprintf (buf, "%F", 1.0 / 0.0) < 0
371 || (strcmp (buf, "INF") != 0 && strcmp (buf, "INFINITY") != 0))
373 /* This catches a Cygwin 2007 bug. */
374 if (sprintf (buf, "%.F", 1234.0) < 0
375 || strcmp (buf, "1234") != 0)
378 }], [gl_cv_func_printf_directive_f=yes], [gl_cv_func_printf_directive_f=no],
382 # Guess yes on glibc systems.
383 *-gnu*) gl_cv_func_printf_directive_f="guessing yes";;
384 # Guess yes on FreeBSD >= 6.
385 freebsd[1-5]*) gl_cv_func_printf_directive_f="guessing no";;
386 freebsd* | kfreebsd*) gl_cv_func_printf_directive_f="guessing yes";;
387 # Guess yes on MacOS X >= 10.3.
388 darwin[1-6].*) gl_cv_func_printf_directive_f="guessing no";;
389 darwin*) gl_cv_func_printf_directive_f="guessing yes";;
390 # Guess yes on Solaris >= 2.10.
391 solaris2.[0-9]*) gl_cv_func_printf_directive_f="guessing no";;
392 solaris*) gl_cv_func_printf_directive_f="guessing yes";;
393 # If we don't know, assume the worst.
394 *) gl_cv_func_printf_directive_f="guessing no";;
401 dnl Test whether the *printf family of functions supports the %n format
402 dnl directive. (ISO C99, POSIX:2001)
403 dnl Result is gl_cv_func_printf_directive_n.
405 AC_DEFUN([gl_PRINTF_DIRECTIVE_N],
407 AC_REQUIRE([AC_PROG_CC])
408 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
409 AC_CACHE_CHECK([whether printf supports the 'n' directive],
410 [gl_cv_func_printf_directive_n],
415 static char buf[100];
419 if (sprintf (buf, "%d %n", 123, &count, 33, 44, 55) < 0
420 || strcmp (buf, "123 ") != 0
424 }], [gl_cv_func_printf_directive_n=yes], [gl_cv_func_printf_directive_n=no],
428 *) gl_cv_func_printf_directive_n="guessing yes";;
435 dnl Test whether the *printf family of functions supports POSIX/XSI format
436 dnl strings with positions. (POSIX:2001)
437 dnl Result is gl_cv_func_printf_positions.
439 AC_DEFUN([gl_PRINTF_POSITIONS],
441 AC_REQUIRE([AC_PROG_CC])
442 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
443 AC_CACHE_CHECK([whether printf supports POSIX/XSI format strings with positions],
444 [gl_cv_func_printf_positions],
449 /* The string "%2$d %1$d", with dollar characters protected from the shell's
450 dollar expansion (possibly an autoconf bug). */
451 static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' };
452 static char buf[100];
455 sprintf (buf, format, 33, 55);
456 return (strcmp (buf, "55 33") != 0);
457 }], [gl_cv_func_printf_positions=yes], [gl_cv_func_printf_positions=no],
461 netbsd[1-3]* | netbsdelf[1-3]* | netbsdaout[1-3]* | netbsdcoff[1-3]*)
462 gl_cv_func_printf_positions="guessing no";;
463 beos*) gl_cv_func_printf_positions="guessing no";;
464 mingw* | pw*) gl_cv_func_printf_positions="guessing no";;
465 *) gl_cv_func_printf_positions="guessing yes";;
472 dnl Test whether the *printf family of functions supports POSIX/XSI format
473 dnl strings with the ' flag for grouping of decimal digits. (POSIX:2001)
474 dnl Result is gl_cv_func_printf_flag_grouping.
476 AC_DEFUN([gl_PRINTF_FLAG_GROUPING],
478 AC_REQUIRE([AC_PROG_CC])
479 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
480 AC_CACHE_CHECK([whether printf supports the grouping flag],
481 [gl_cv_func_printf_flag_grouping],
486 static char buf[100];
489 if (sprintf (buf, "%'d %d", 1234567, 99) < 0
490 || buf[strlen (buf) - 1] != '9')
493 }], [gl_cv_func_printf_flag_grouping=yes], [gl_cv_func_printf_flag_grouping=no],
497 cygwin*) gl_cv_func_printf_flag_grouping="guessing no";;
498 netbsd*) gl_cv_func_printf_flag_grouping="guessing no";;
499 mingw* | pw*) gl_cv_func_printf_flag_grouping="guessing no";;
500 *) gl_cv_func_printf_flag_grouping="guessing yes";;
507 dnl Test whether the *printf family of functions supports padding of non-finite
508 dnl values with the 0 flag correctly. (ISO C99 + TC1 + TC2.) See
509 dnl <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html>
510 dnl Result is gl_cv_func_printf_flag_zero.
512 AC_DEFUN([gl_PRINTF_FLAG_ZERO],
514 AC_REQUIRE([AC_PROG_CC])
515 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
516 AC_CACHE_CHECK([whether printf supports the zero flag correctly],
517 [gl_cv_func_printf_flag_zero],
522 static char buf[100];
525 if (sprintf (buf, "%010f", 1.0 / 0.0, 33, 44, 55) < 0
526 || (strcmp (buf, " inf") != 0
527 && strcmp (buf, " infinity") != 0))
530 }], [gl_cv_func_printf_flag_zero=yes], [gl_cv_func_printf_flag_zero=no],
534 # Guess yes on glibc systems.
535 *-gnu*) gl_cv_func_printf_flag_zero="guessing yes";;
537 beos*) gl_cv_func_printf_flag_zero="guessing yes";;
538 # If we don't know, assume the worst.
539 *) gl_cv_func_printf_flag_zero="guessing no";;
546 dnl Test whether the snprintf function exists. (ISO C99, POSIX:2001)
547 dnl Result is ac_cv_func_snprintf.
549 AC_DEFUN([gl_SNPRINTF_PRESENCE],
551 AC_CHECK_FUNCS_ONCE([snprintf])
554 dnl Test whether the string produced by the snprintf function is always NUL
555 dnl terminated. (ISO C99, POSIX:2001)
556 dnl Result is gl_cv_func_snprintf_truncation_c99.
558 AC_DEFUN([gl_SNPRINTF_TRUNCATION_C99],
560 AC_REQUIRE([AC_PROG_CC])
561 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
562 AC_CACHE_CHECK([whether snprintf truncates the result as in C99],
563 [gl_cv_func_snprintf_truncation_c99],
568 static char buf[100];
571 strcpy (buf, "ABCDEF");
572 snprintf (buf, 3, "%d %d", 4567, 89);
573 if (memcmp (buf, "45\0DEF", 6) != 0)
576 }], [gl_cv_func_snprintf_truncation_c99=yes], [gl_cv_func_snprintf_truncation_c99=no],
580 # Guess yes on glibc systems.
581 *-gnu*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
582 # Guess yes on FreeBSD >= 5.
583 freebsd[1-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
584 freebsd* | kfreebsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
585 # Guess yes on MacOS X >= 10.3.
586 darwin[1-6].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
587 darwin*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
588 # Guess yes on OpenBSD >= 3.9.
589 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
590 gl_cv_func_snprintf_truncation_c99="guessing no";;
591 openbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
592 # Guess yes on Solaris >= 2.6.
593 solaris2.[0-5]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
594 solaris*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
595 # Guess yes on AIX >= 4.
596 aix[1-3]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
597 aix*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
598 # Guess yes on HP-UX >= 11.
599 hpux[7-9]* | hpux10*) gl_cv_func_snprintf_truncation_c99="guessing no";;
600 hpux*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
601 # Guess yes on IRIX >= 6.5.
602 irix6.5) gl_cv_func_snprintf_truncation_c99="guessing yes";;
603 # Guess yes on OSF/1 >= 5.
604 osf[3-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
605 osf*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
606 # Guess yes on NetBSD >= 3.
607 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
608 gl_cv_func_snprintf_truncation_c99="guessing no";;
609 netbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
611 beos*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
612 # If we don't know, assume the worst.
613 *) gl_cv_func_snprintf_truncation_c99="guessing no";;
620 dnl Test whether the return value of the snprintf function is the number
621 dnl of bytes (excluding the terminating NUL) that would have been produced
622 dnl if the buffer had been large enough. (ISO C99, POSIX:2001)
623 dnl For example, this test program fails on IRIX 6.5:
624 dnl ---------------------------------------------------------------------
625 dnl #include <stdio.h>
628 dnl static char buf[8];
629 dnl int retval = snprintf (buf, 3, "%d", 12345);
630 dnl return retval >= 0 && retval < 3;
632 dnl ---------------------------------------------------------------------
633 dnl Result is gl_cv_func_snprintf_retval_c99.
635 AC_DEFUN([gl_SNPRINTF_RETVAL_C99],
637 AC_REQUIRE([AC_PROG_CC])
638 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
639 AC_CACHE_CHECK([whether snprintf returns a byte count as in C99],
640 [gl_cv_func_snprintf_retval_c99],
645 static char buf[100];
648 strcpy (buf, "ABCDEF");
649 if (snprintf (buf, 3, "%d %d", 4567, 89) != 7)
652 }], [gl_cv_func_snprintf_retval_c99=yes], [gl_cv_func_snprintf_retval_c99=no],
656 # Guess yes on glibc systems.
657 *-gnu*) gl_cv_func_snprintf_retval_c99="guessing yes";;
658 # Guess yes on FreeBSD >= 5.
659 freebsd[1-4]*) gl_cv_func_snprintf_retval_c99="guessing no";;
660 freebsd* | kfreebsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
661 # Guess yes on MacOS X >= 10.3.
662 darwin[1-6].*) gl_cv_func_snprintf_retval_c99="guessing no";;
663 darwin*) gl_cv_func_snprintf_retval_c99="guessing yes";;
664 # Guess yes on OpenBSD >= 3.9.
665 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
666 gl_cv_func_snprintf_retval_c99="guessing no";;
667 openbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
668 # Guess yes on Solaris >= 2.6.
669 solaris2.[0-5]*) gl_cv_func_snprintf_retval_c99="guessing no";;
670 solaris*) gl_cv_func_snprintf_retval_c99="guessing yes";;
671 # Guess yes on AIX >= 4.
672 aix[1-3]*) gl_cv_func_snprintf_retval_c99="guessing no";;
673 aix*) gl_cv_func_snprintf_retval_c99="guessing yes";;
674 # Guess yes on NetBSD >= 3.
675 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
676 gl_cv_func_snprintf_retval_c99="guessing no";;
677 netbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
679 beos*) gl_cv_func_snprintf_retval_c99="guessing yes";;
680 # If we don't know, assume the worst.
681 *) gl_cv_func_snprintf_retval_c99="guessing no";;
688 dnl Test whether the snprintf function supports the %n format directive
689 dnl also in truncated portions of the format string. (ISO C99, POSIX:2001)
690 dnl Result is gl_cv_func_snprintf_directive_n.
692 AC_DEFUN([gl_SNPRINTF_DIRECTIVE_N],
694 AC_REQUIRE([AC_PROG_CC])
695 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
696 AC_CACHE_CHECK([whether snprintf fully supports the 'n' directive],
697 [gl_cv_func_snprintf_directive_n],
702 static char buf[100];
706 snprintf (buf, 4, "%d %n", 12345, &count, 33, 44, 55);
710 }], [gl_cv_func_snprintf_directive_n=yes], [gl_cv_func_snprintf_directive_n=no],
714 # Guess yes on glibc systems.
715 *-gnu*) gl_cv_func_snprintf_directive_n="guessing yes";;
716 # Guess yes on FreeBSD >= 5.
717 freebsd[1-4]*) gl_cv_func_snprintf_directive_n="guessing no";;
718 freebsd* | kfreebsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
719 # Guess yes on MacOS X >= 10.3.
720 darwin[1-6].*) gl_cv_func_snprintf_directive_n="guessing no";;
721 darwin*) gl_cv_func_snprintf_directive_n="guessing yes";;
722 # Guess yes on Solaris >= 2.6.
723 solaris2.[0-5]*) gl_cv_func_snprintf_directive_n="guessing no";;
724 solaris*) gl_cv_func_snprintf_directive_n="guessing yes";;
725 # Guess yes on AIX >= 4.
726 aix[1-3]*) gl_cv_func_snprintf_directive_n="guessing no";;
727 aix*) gl_cv_func_snprintf_directive_n="guessing yes";;
728 # Guess yes on IRIX >= 6.5.
729 irix6.5) gl_cv_func_snprintf_directive_n="guessing yes";;
730 # Guess yes on OSF/1 >= 5.
731 osf[3-4]*) gl_cv_func_snprintf_directive_n="guessing no";;
732 osf*) gl_cv_func_snprintf_directive_n="guessing yes";;
733 # Guess yes on NetBSD >= 3.
734 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
735 gl_cv_func_snprintf_directive_n="guessing no";;
736 netbsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
738 beos*) gl_cv_func_snprintf_directive_n="guessing yes";;
739 # If we don't know, assume the worst.
740 *) gl_cv_func_snprintf_directive_n="guessing no";;
747 dnl Test whether the vsnprintf function, when passed a zero size, produces no
748 dnl output. (ISO C99, POSIX:2001)
749 dnl For example, snprintf nevertheless writes a NUL byte in this case
751 dnl ---------------------------------------------------------------------
752 dnl #include <stdio.h>
755 dnl static char buf[8] = "DEADBEEF";
756 dnl snprintf (buf, 0, "%d", 12345);
757 dnl return buf[0] != 'D';
759 dnl ---------------------------------------------------------------------
760 dnl And vsnprintf writes any output without bounds in this case, behaving like
761 dnl vsprintf, on HP-UX 11 and OSF/1 5.1:
762 dnl ---------------------------------------------------------------------
763 dnl #include <stdarg.h>
764 dnl #include <stdio.h>
765 dnl static int my_snprintf (char *buf, int size, const char *format, ...)
769 dnl va_start (args, format);
770 dnl ret = vsnprintf (buf, size, format, args);
776 dnl static char buf[8] = "DEADBEEF";
777 dnl my_snprintf (buf, 0, "%d", 12345);
778 dnl return buf[0] != 'D';
780 dnl ---------------------------------------------------------------------
781 dnl Result is gl_cv_func_vsnprintf_zerosize_c99.
783 AC_DEFUN([gl_VSNPRINTF_ZEROSIZE_C99],
785 AC_REQUIRE([AC_PROG_CC])
786 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
787 AC_CACHE_CHECK([whether vsnprintf respects a zero size as in C99],
788 [gl_cv_func_vsnprintf_zerosize_c99],
793 static int my_snprintf (char *buf, int size, const char *format, ...)
797 va_start (args, format);
798 ret = vsnprintf (buf, size, format, args);
804 static char buf[8] = "DEADBEEF";
805 my_snprintf (buf, 0, "%d", 12345);
806 return buf[0] != 'D';
808 [gl_cv_func_vsnprintf_zerosize_c99=yes],
809 [gl_cv_func_vsnprintf_zerosize_c99=no],
813 # Guess yes on glibc systems.
814 *-gnu*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
815 # Guess yes on FreeBSD >= 5.
816 freebsd[1-4]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
817 freebsd* | kfreebsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
818 # Guess yes on MacOS X >= 10.3.
819 darwin[1-6].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
820 darwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
821 # Guess yes on Cygwin.
822 cygwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
823 # Guess yes on Solaris >= 2.6.
824 solaris2.[0-5]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
825 solaris*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
826 # Guess yes on AIX >= 4.
827 aix[1-3]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
828 aix*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
829 # Guess yes on IRIX >= 6.5.
830 irix6.5) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
831 # Guess yes on NetBSD >= 3.
832 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
833 gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
834 netbsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
836 beos*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
837 # Guess yes on mingw.
838 mingw* | pw*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
839 # If we don't know, assume the worst.
840 *) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
847 dnl The results of these tests on various platforms are:
849 dnl 1 = gl_PRINTF_SIZES_C99
850 dnl 2 = gl_PRINTF_LONG_DOUBLE
851 dnl 3 = gl_PRINTF_INFINITE
852 dnl 4 = gl_PRINTF_INFINITE_LONG_DOUBLE
853 dnl 5 = gl_PRINTF_DIRECTIVE_A
854 dnl 6 = gl_PRINTF_DIRECTIVE_F
855 dnl 7 = gl_PRINTF_DIRECTIVE_N
856 dnl 8 = gl_PRINTF_POSITIONS
857 dnl 9 = gl_PRINTF_FLAG_GROUPING
858 dnl 10 = gl_PRINTF_FLAG_ZERO
859 dnl 11 = gl_SNPRINTF_PRESENCE
860 dnl 12 = gl_SNPRINTF_TRUNCATION_C99
861 dnl 13 = gl_SNPRINTF_RETVAL_C99
862 dnl 14 = gl_SNPRINTF_DIRECTIVE_N
863 dnl 15 = gl_VSNPRINTF_ZEROSIZE_C99
865 dnl 1 = checking whether printf supports size specifiers as in C99...
866 dnl 2 = checking whether printf supports 'long double' arguments...
867 dnl 3 = checking whether printf supports infinite 'double' arguments...
868 dnl 4 = checking whether printf supports infinite 'long double' arguments...
869 dnl 5 = checking whether printf supports the 'a' and 'A' directives...
870 dnl 6 = checking whether printf supports the 'F' directive...
871 dnl 7 = checking whether printf supports the 'n' directive...
872 dnl 8 = checking whether printf supports POSIX/XSI format strings with positions...
873 dnl 9 = checking whether printf supports the grouping flag...
874 dnl 10 = checking whether printf supports the zero flag correctly...
875 dnl 11 = checking for snprintf...
876 dnl 12 = checking whether snprintf truncates the result as in C99...
877 dnl 13 = checking whether snprintf returns a byte count as in C99...
878 dnl 14 = checking whether snprintf fully supports the 'n' directive...
879 dnl 15 = checking whether vsnprintf respects a zero size as in C99...
883 dnl 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
884 dnl glibc 2.5 . . . . . . . . . . . . . . .
885 dnl glibc 2.3.6 . . . . # . . . . . . . . . .
886 dnl FreeBSD 5.4, 6.1 . . . . # . . . . # . . . . .
887 dnl MacOS X 10.3.9 . . . . # . . . . # . . . . .
888 dnl OpenBSD 3.9, 4.0 . ? ? ? # ? . . ? ? . . . ? ?
889 dnl Cygwin 2007 (= Cygwin 1.5.24) . ? ? ? # # . . . # . . . . .
890 dnl Cygwin 2006 (= Cygwin 1.5.19) # ? ? ? # # . . # # . . . . .
891 dnl Solaris 10 . . # # # . . . . # . . . . .
892 dnl Solaris 2.6 ... 9 # . # # # # . . . # . . . . .
893 dnl Solaris 2.5.1 # . # # # # . . . # # # # # #
894 dnl AIX 5.2 . . # # # . . . . # . . . . .
895 dnl AIX 4.3.2, 5.1 # . # # # # . . . # . . . . .
896 dnl HP-UX 11.31 . . . . # . . . . # . . # # .
897 dnl HP-UX 10.20, 11.{00,11,23} # . . . # # . . . # . . # # #
898 dnl IRIX 6.5 # . . . # # . . . # . . # . .
899 dnl OSF/1 5.1 # . # # # # . . . # . . # . #
900 dnl OSF/1 4.0d # . # # # # . . . # # # # # #
901 dnl NetBSD 4.0 . ? ? ? ? ? . . ? ? . . . ? ?
902 dnl NetBSD 3.0 . . . . # # . # # # . . . . .
903 dnl BeOS # # . # # # . # . . . . . . .
904 dnl mingw # # # # # # . # # # . # # # .