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 infinite 'double'
85 dnl arguments in the %f, %e, %g directives. (ISO C99, POSIX:2001)
86 dnl Result is gl_cv_func_printf_infinite.
88 AC_DEFUN([gl_PRINTF_INFINITE],
90 AC_REQUIRE([AC_PROG_CC])
91 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
92 AC_CACHE_CHECK([whether printf supports infinite 'double' arguments],
93 [gl_cv_func_printf_infinite],
101 if (sprintf (buf, "%f", 1.0 / 0.0) < 0
102 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
104 if (sprintf (buf, "%f", -1.0 / 0.0) < 0
105 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
107 if (sprintf (buf, "%e", 1.0 / 0.0) < 0
108 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
110 if (sprintf (buf, "%e", -1.0 / 0.0) < 0
111 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
113 if (sprintf (buf, "%g", 1.0 / 0.0) < 0
114 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
116 if (sprintf (buf, "%g", -1.0 / 0.0) < 0
117 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
120 }], [gl_cv_func_printf_infinite=yes], [gl_cv_func_printf_infinite=no],
124 mingw* | pw*) gl_cv_func_printf_infinite="guessing no";;
125 *) gl_cv_func_printf_infinite="guessing yes";;
132 dnl Test whether the *printf family of functions supports 'long double'
133 dnl arguments together with the 'L' size specifier. (ISO C99, POSIX:2001)
134 dnl Result is gl_cv_func_printf_long_double.
136 AC_DEFUN([gl_PRINTF_LONG_DOUBLE],
138 AC_REQUIRE([AC_PROG_CC])
139 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
140 AC_CACHE_CHECK([whether printf supports 'long double' arguments],
141 [gl_cv_func_printf_long_double],
146 static char buf[100];
150 if (sprintf (buf, "%Lf %d", 1.75L, 33, 44, 55) < 0
151 || strcmp (buf, "1.750000 33") != 0)
154 if (sprintf (buf, "%Le %d", 1.75L, 33, 44, 55) < 0
155 || strcmp (buf, "1.750000e+00 33") != 0)
158 if (sprintf (buf, "%Lg %d", 1.75L, 33, 44, 55) < 0
159 || strcmp (buf, "1.75 33") != 0)
162 }], [gl_cv_func_printf_long_double=yes], [gl_cv_func_printf_long_double=no],
166 beos*) gl_cv_func_printf_long_double="guessing no";;
167 mingw* | pw*) gl_cv_func_printf_long_double="guessing no";;
168 *) gl_cv_func_printf_long_double="guessing yes";;
175 dnl Test whether the *printf family of functions supports the 'a' and 'A'
176 dnl conversion specifier for hexadecimal output of floating-point numbers.
177 dnl (ISO C99, POSIX:2001)
178 dnl Result is gl_cv_func_printf_directive_a.
180 AC_DEFUN([gl_PRINTF_DIRECTIVE_A],
182 AC_REQUIRE([AC_PROG_CC])
183 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
184 AC_CACHE_CHECK([whether printf supports the 'a' and 'A' directives],
185 [gl_cv_func_printf_directive_a],
190 static char buf[100];
193 if (sprintf (buf, "%a %d", 3.1416015625, 33, 44, 55) < 0
194 || (strcmp (buf, "0x1.922p+1 33") != 0
195 && strcmp (buf, "0x3.244p+0 33") != 0
196 && strcmp (buf, "0x6.488p-1 33") != 0
197 && strcmp (buf, "0xc.91p-2 33") != 0))
199 if (sprintf (buf, "%A %d", -3.1416015625, 33, 44, 55) < 0
200 || (strcmp (buf, "-0X1.922P+1 33") != 0
201 && strcmp (buf, "-0X3.244P+0 33") != 0
202 && strcmp (buf, "-0X6.488P-1 33") != 0
203 && strcmp (buf, "-0XC.91P-2 33") != 0))
205 /* This catches a FreeBSD 6.1 bug: it doesn't round. */
206 if (sprintf (buf, "%.2a %d", 1.51, 33, 44, 55) < 0
207 || (strcmp (buf, "0x1.83p+0 33") != 0
208 && strcmp (buf, "0x3.05p-1 33") != 0
209 && strcmp (buf, "0x6.0ap-2 33") != 0
210 && strcmp (buf, "0xc.14p-3 33") != 0))
212 /* This catches a FreeBSD 6.1 bug. See
213 <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
214 if (sprintf (buf, "%010a %d", 1.0 / 0.0, 33, 44, 55) < 0
217 /* This catches a MacOS X 10.3.9 (Darwin 7.9) bug. */
218 if (sprintf (buf, "%.1a", 1.999) < 0
219 || (strcmp (buf, "0x1.0p+1") != 0
220 && strcmp (buf, "0x2.0p+0") != 0
221 && strcmp (buf, "0x4.0p-1") != 0
222 && strcmp (buf, "0x8.0p-2") != 0))
224 /* This catches the same MacOS X 10.3.9 (Darwin 7.9) bug and also a
225 glibc 2.4 bug <http://sourceware.org/bugzilla/show_bug.cgi?id=2908>. */
226 if (sprintf (buf, "%.1La", 1.999L) < 0
227 || (strcmp (buf, "0x1.0p+1") != 0
228 && strcmp (buf, "0x2.0p+0") != 0
229 && strcmp (buf, "0x4.0p-1") != 0
230 && strcmp (buf, "0x8.0p-2") != 0))
233 }], [gl_cv_func_printf_directive_a=yes], [gl_cv_func_printf_directive_a=no],
236 # Guess yes on glibc >= 2.5 systems.
238 AC_EGREP_CPP([BZ2908], [
239 #include <features.h>
240 #ifdef __GNU_LIBRARY__
241 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 5) || (__GLIBC__ > 2)
246 [gl_cv_func_printf_directive_a="guessing yes"],
247 [gl_cv_func_printf_directive_a="guessing no"])
249 # If we don't know, assume the worst.
250 *) gl_cv_func_printf_directive_a="guessing no";;
256 dnl Test whether the *printf family of functions supports the %F format
257 dnl directive. (ISO C99, POSIX:2001)
258 dnl Result is gl_cv_func_printf_directive_f.
260 AC_DEFUN([gl_PRINTF_DIRECTIVE_F],
262 AC_REQUIRE([AC_PROG_CC])
263 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
264 AC_CACHE_CHECK([whether printf supports the 'F' directive],
265 [gl_cv_func_printf_directive_f],
270 static char buf[100];
273 if (sprintf (buf, "%F %d", 1234567.0, 33, 44, 55) < 0
274 || strcmp (buf, "1234567.000000 33") != 0)
276 if (sprintf (buf, "%F", 1.0 / 0.0) < 0
277 || (strcmp (buf, "INF") != 0 && strcmp (buf, "INFINITY") != 0))
279 /* This catches a Cygwin 2007 bug. */
280 if (sprintf (buf, "%.F", 1234.0) < 0
281 || strcmp (buf, "1234") != 0)
284 }], [gl_cv_func_printf_directive_f=yes], [gl_cv_func_printf_directive_f=no],
288 # Guess yes on glibc systems.
289 *-gnu*) gl_cv_func_printf_directive_f="guessing yes";;
290 # Guess yes on FreeBSD >= 6.
291 freebsd[1-5]*) gl_cv_func_printf_directive_f="guessing no";;
292 freebsd* | kfreebsd*) gl_cv_func_printf_directive_f="guessing yes";;
293 # Guess yes on MacOS X >= 10.3.
294 darwin[1-6].*) gl_cv_func_printf_directive_f="guessing no";;
295 darwin*) gl_cv_func_printf_directive_f="guessing yes";;
296 # Guess yes on Solaris >= 2.10.
297 solaris2.[0-9]*) gl_cv_func_printf_directive_f="guessing no";;
298 solaris*) gl_cv_func_printf_directive_f="guessing yes";;
299 # If we don't know, assume the worst.
300 *) gl_cv_func_printf_directive_f="guessing no";;
307 dnl Test whether the *printf family of functions supports the %n format
308 dnl directive. (ISO C99, POSIX:2001)
309 dnl Result is gl_cv_func_printf_directive_n.
311 AC_DEFUN([gl_PRINTF_DIRECTIVE_N],
313 AC_REQUIRE([AC_PROG_CC])
314 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
315 AC_CACHE_CHECK([whether printf supports the 'n' directive],
316 [gl_cv_func_printf_directive_n],
321 static char buf[100];
325 if (sprintf (buf, "%d %n", 123, &count, 33, 44, 55) < 0
326 || strcmp (buf, "123 ") != 0
330 }], [gl_cv_func_printf_directive_n=yes], [gl_cv_func_printf_directive_n=no],
334 *) gl_cv_func_printf_directive_n="guessing yes";;
341 dnl Test whether the *printf family of functions supports POSIX/XSI format
342 dnl strings with positions. (POSIX:2001)
343 dnl Result is gl_cv_func_printf_positions.
345 AC_DEFUN([gl_PRINTF_POSITIONS],
347 AC_REQUIRE([AC_PROG_CC])
348 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
349 AC_CACHE_CHECK([whether printf supports POSIX/XSI format strings with positions],
350 [gl_cv_func_printf_positions],
355 /* The string "%2$d %1$d", with dollar characters protected from the shell's
356 dollar expansion (possibly an autoconf bug). */
357 static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' };
358 static char buf[100];
361 sprintf (buf, format, 33, 55);
362 return (strcmp (buf, "55 33") != 0);
363 }], [gl_cv_func_printf_positions=yes], [gl_cv_func_printf_positions=no],
367 netbsd[1-3]* | netbsdelf[1-3]* | netbsdaout[1-3]* | netbsdcoff[1-3]*)
368 gl_cv_func_printf_positions="guessing no";;
369 beos*) gl_cv_func_printf_positions="guessing no";;
370 mingw* | pw*) gl_cv_func_printf_positions="guessing no";;
371 *) gl_cv_func_printf_positions="guessing yes";;
378 dnl Test whether the *printf family of functions supports POSIX/XSI format
379 dnl strings with the ' flag for grouping of decimal digits. (POSIX:2001)
380 dnl Result is gl_cv_func_printf_flag_grouping.
382 AC_DEFUN([gl_PRINTF_FLAG_GROUPING],
384 AC_REQUIRE([AC_PROG_CC])
385 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
386 AC_CACHE_CHECK([whether printf supports the grouping flag],
387 [gl_cv_func_printf_flag_grouping],
392 static char buf[100];
395 if (sprintf (buf, "%'d %d", 1234567, 99) < 0
396 || buf[strlen (buf) - 1] != '9')
399 }], [gl_cv_func_printf_flag_grouping=yes], [gl_cv_func_printf_flag_grouping=no],
403 cygwin*) gl_cv_func_printf_flag_grouping="guessing no";;
404 netbsd*) gl_cv_func_printf_flag_grouping="guessing no";;
405 mingw* | pw*) gl_cv_func_printf_flag_grouping="guessing no";;
406 *) gl_cv_func_printf_flag_grouping="guessing yes";;
413 dnl Test whether the *printf family of functions supports padding of non-finite
414 dnl values with the 0 flag correctly. (ISO C99 + TC1 + TC2.) See
415 dnl <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html>
416 dnl Result is gl_cv_func_printf_flag_zero.
418 AC_DEFUN([gl_PRINTF_FLAG_ZERO],
420 AC_REQUIRE([AC_PROG_CC])
421 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
422 AC_CACHE_CHECK([whether printf supports the zero flag correctly],
423 [gl_cv_func_printf_flag_zero],
428 static char buf[100];
431 if (sprintf (buf, "%010f", 1.0 / 0.0, 33, 44, 55) < 0
432 || (strcmp (buf, " inf") != 0
433 && strcmp (buf, " infinity") != 0))
436 }], [gl_cv_func_printf_flag_zero=yes], [gl_cv_func_printf_flag_zero=no],
440 # Guess yes on glibc systems.
441 *-gnu*) gl_cv_func_printf_flag_zero="guessing yes";;
443 beos*) gl_cv_func_printf_flag_zero="guessing yes";;
444 # If we don't know, assume the worst.
445 *) gl_cv_func_printf_flag_zero="guessing no";;
452 dnl Test whether the snprintf function exists. (ISO C99, POSIX:2001)
453 dnl Result is ac_cv_func_snprintf.
455 AC_DEFUN([gl_SNPRINTF_PRESENCE],
457 AC_CHECK_FUNCS_ONCE([snprintf])
460 dnl Test whether the string produced by the snprintf function is always NUL
461 dnl terminated. (ISO C99, POSIX:2001)
462 dnl Result is gl_cv_func_snprintf_truncation_c99.
464 AC_DEFUN([gl_SNPRINTF_TRUNCATION_C99],
466 AC_REQUIRE([AC_PROG_CC])
467 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
468 AC_CACHE_CHECK([whether snprintf truncates the result as in C99],
469 [gl_cv_func_snprintf_truncation_c99],
474 static char buf[100];
477 strcpy (buf, "ABCDEF");
478 snprintf (buf, 3, "%d %d", 4567, 89);
479 if (memcmp (buf, "45\0DEF", 6) != 0)
482 }], [gl_cv_func_snprintf_truncation_c99=yes], [gl_cv_func_snprintf_truncation_c99=no],
486 # Guess yes on glibc systems.
487 *-gnu*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
488 # Guess yes on FreeBSD >= 5.
489 freebsd[1-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
490 freebsd* | kfreebsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
491 # Guess yes on MacOS X >= 10.3.
492 darwin[1-6].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
493 darwin*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
494 # Guess yes on OpenBSD >= 3.9.
495 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
496 gl_cv_func_snprintf_truncation_c99="guessing no";;
497 openbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
498 # Guess yes on Solaris >= 2.6.
499 solaris2.[0-5]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
500 solaris*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
501 # Guess yes on AIX >= 4.
502 aix[1-3]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
503 aix*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
504 # Guess yes on HP-UX >= 11.
505 hpux[7-9]* | hpux10*) gl_cv_func_snprintf_truncation_c99="guessing no";;
506 hpux*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
507 # Guess yes on IRIX >= 6.5.
508 irix6.5) gl_cv_func_snprintf_truncation_c99="guessing yes";;
509 # Guess yes on OSF/1 >= 5.
510 osf[3-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
511 osf*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
512 # Guess yes on NetBSD >= 3.
513 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
514 gl_cv_func_snprintf_truncation_c99="guessing no";;
515 netbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
517 beos*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
518 # If we don't know, assume the worst.
519 *) gl_cv_func_snprintf_truncation_c99="guessing no";;
526 dnl Test whether the return value of the snprintf function is the number
527 dnl of bytes (excluding the terminating NUL) that would have been produced
528 dnl if the buffer had been large enough. (ISO C99, POSIX:2001)
529 dnl For example, this test program fails on IRIX 6.5:
530 dnl ---------------------------------------------------------------------
531 dnl #include <stdio.h>
534 dnl static char buf[8];
535 dnl int retval = snprintf (buf, 3, "%d", 12345);
536 dnl return retval >= 0 && retval < 3;
538 dnl ---------------------------------------------------------------------
539 dnl Result is gl_cv_func_snprintf_retval_c99.
541 AC_DEFUN([gl_SNPRINTF_RETVAL_C99],
543 AC_REQUIRE([AC_PROG_CC])
544 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
545 AC_CACHE_CHECK([whether snprintf returns a byte count as in C99],
546 [gl_cv_func_snprintf_retval_c99],
551 static char buf[100];
554 strcpy (buf, "ABCDEF");
555 if (snprintf (buf, 3, "%d %d", 4567, 89) != 7)
558 }], [gl_cv_func_snprintf_retval_c99=yes], [gl_cv_func_snprintf_retval_c99=no],
562 # Guess yes on glibc systems.
563 *-gnu*) gl_cv_func_snprintf_retval_c99="guessing yes";;
564 # Guess yes on FreeBSD >= 5.
565 freebsd[1-4]*) gl_cv_func_snprintf_retval_c99="guessing no";;
566 freebsd* | kfreebsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
567 # Guess yes on MacOS X >= 10.3.
568 darwin[1-6].*) gl_cv_func_snprintf_retval_c99="guessing no";;
569 darwin*) gl_cv_func_snprintf_retval_c99="guessing yes";;
570 # Guess yes on OpenBSD >= 3.9.
571 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
572 gl_cv_func_snprintf_retval_c99="guessing no";;
573 openbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
574 # Guess yes on Solaris >= 2.6.
575 solaris2.[0-5]*) gl_cv_func_snprintf_retval_c99="guessing no";;
576 solaris*) gl_cv_func_snprintf_retval_c99="guessing yes";;
577 # Guess yes on AIX >= 4.
578 aix[1-3]*) gl_cv_func_snprintf_retval_c99="guessing no";;
579 aix*) gl_cv_func_snprintf_retval_c99="guessing yes";;
580 # Guess yes on NetBSD >= 3.
581 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
582 gl_cv_func_snprintf_retval_c99="guessing no";;
583 netbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
585 beos*) gl_cv_func_snprintf_retval_c99="guessing yes";;
586 # If we don't know, assume the worst.
587 *) gl_cv_func_snprintf_retval_c99="guessing no";;
594 dnl Test whether the snprintf function supports the %n format directive
595 dnl also in truncated portions of the format string. (ISO C99, POSIX:2001)
596 dnl Result is gl_cv_func_snprintf_directive_n.
598 AC_DEFUN([gl_SNPRINTF_DIRECTIVE_N],
600 AC_REQUIRE([AC_PROG_CC])
601 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
602 AC_CACHE_CHECK([whether snprintf fully supports the 'n' directive],
603 [gl_cv_func_snprintf_directive_n],
608 static char buf[100];
612 snprintf (buf, 4, "%d %n", 12345, &count, 33, 44, 55);
616 }], [gl_cv_func_snprintf_directive_n=yes], [gl_cv_func_snprintf_directive_n=no],
620 # Guess yes on glibc systems.
621 *-gnu*) gl_cv_func_snprintf_directive_n="guessing yes";;
622 # Guess yes on FreeBSD >= 5.
623 freebsd[1-4]*) gl_cv_func_snprintf_directive_n="guessing no";;
624 freebsd* | kfreebsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
625 # Guess yes on MacOS X >= 10.3.
626 darwin[1-6].*) gl_cv_func_snprintf_directive_n="guessing no";;
627 darwin*) gl_cv_func_snprintf_directive_n="guessing yes";;
628 # Guess yes on Solaris >= 2.6.
629 solaris2.[0-5]*) gl_cv_func_snprintf_directive_n="guessing no";;
630 solaris*) gl_cv_func_snprintf_directive_n="guessing yes";;
631 # Guess yes on AIX >= 4.
632 aix[1-3]*) gl_cv_func_snprintf_directive_n="guessing no";;
633 aix*) gl_cv_func_snprintf_directive_n="guessing yes";;
634 # Guess yes on IRIX >= 6.5.
635 irix6.5) gl_cv_func_snprintf_directive_n="guessing yes";;
636 # Guess yes on OSF/1 >= 5.
637 osf[3-4]*) gl_cv_func_snprintf_directive_n="guessing no";;
638 osf*) gl_cv_func_snprintf_directive_n="guessing yes";;
639 # Guess yes on NetBSD >= 3.
640 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
641 gl_cv_func_snprintf_directive_n="guessing no";;
642 netbsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
644 beos*) gl_cv_func_snprintf_directive_n="guessing yes";;
645 # If we don't know, assume the worst.
646 *) gl_cv_func_snprintf_directive_n="guessing no";;
653 dnl Test whether the vsnprintf function, when passed a zero size, produces no
654 dnl output. (ISO C99, POSIX:2001)
655 dnl For example, snprintf nevertheless writes a NUL byte in this case
657 dnl ---------------------------------------------------------------------
658 dnl #include <stdio.h>
661 dnl static char buf[8] = "DEADBEEF";
662 dnl snprintf (buf, 0, "%d", 12345);
663 dnl return buf[0] != 'D';
665 dnl ---------------------------------------------------------------------
666 dnl And vsnprintf writes any output without bounds in this case, behaving like
667 dnl vsprintf, on HP-UX 11 and OSF/1 5.1:
668 dnl ---------------------------------------------------------------------
669 dnl #include <stdarg.h>
670 dnl #include <stdio.h>
671 dnl static int my_snprintf (char *buf, int size, const char *format, ...)
675 dnl va_start (args, format);
676 dnl ret = vsnprintf (buf, size, format, args);
682 dnl static char buf[8] = "DEADBEEF";
683 dnl my_snprintf (buf, 0, "%d", 12345);
684 dnl return buf[0] != 'D';
686 dnl ---------------------------------------------------------------------
687 dnl Result is gl_cv_func_vsnprintf_zerosize_c99.
689 AC_DEFUN([gl_VSNPRINTF_ZEROSIZE_C99],
691 AC_REQUIRE([AC_PROG_CC])
692 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
693 AC_CACHE_CHECK([whether vsnprintf respects a zero size as in C99],
694 [gl_cv_func_vsnprintf_zerosize_c99],
699 static int my_snprintf (char *buf, int size, const char *format, ...)
703 va_start (args, format);
704 ret = vsnprintf (buf, size, format, args);
710 static char buf[8] = "DEADBEEF";
711 my_snprintf (buf, 0, "%d", 12345);
712 return buf[0] != 'D';
714 [gl_cv_func_vsnprintf_zerosize_c99=yes],
715 [gl_cv_func_vsnprintf_zerosize_c99=no],
719 # Guess yes on glibc systems.
720 *-gnu*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
721 # Guess yes on FreeBSD >= 5.
722 freebsd[1-4]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
723 freebsd* | kfreebsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
724 # Guess yes on MacOS X >= 10.3.
725 darwin[1-6].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
726 darwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
727 # Guess yes on Cygwin.
728 cygwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
729 # Guess yes on Solaris >= 2.6.
730 solaris2.[0-5]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
731 solaris*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
732 # Guess yes on AIX >= 4.
733 aix[1-3]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
734 aix*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
735 # Guess yes on IRIX >= 6.5.
736 irix6.5) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
737 # Guess yes on NetBSD >= 3.
738 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
739 gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
740 netbsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
742 beos*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
743 # Guess yes on mingw.
744 mingw* | pw*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
745 # If we don't know, assume the worst.
746 *) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
753 dnl The results of these tests on various platforms are:
755 dnl 1 = gl_PRINTF_SIZES_C99
756 dnl 2 = gl_PRINTF_INFINITE
757 dnl 3 = gl_PRINTF_LONG_DOUBLE
758 dnl 4 = gl_PRINTF_DIRECTIVE_A
759 dnl 5 = gl_PRINTF_DIRECTIVE_F
760 dnl 6 = gl_PRINTF_DIRECTIVE_N
761 dnl 7 = gl_PRINTF_POSITIONS
762 dnl 8 = gl_PRINTF_FLAG_GROUPING
763 dnl 9 = gl_PRINTF_FLAG_ZERO
764 dnl 10 = gl_SNPRINTF_PRESENCE
765 dnl 11 = gl_SNPRINTF_TRUNCATION_C99
766 dnl 12 = gl_SNPRINTF_RETVAL_C99
767 dnl 13 = gl_SNPRINTF_DIRECTIVE_N
768 dnl 14 = gl_VSNPRINTF_ZEROSIZE_C99
770 dnl 1 = checking whether printf supports size specifiers as in C99...
771 dnl 2 = checking whether printf supports infinite 'double' arguments...
772 dnl 3 = checking whether printf supports 'long double' arguments...
773 dnl 4 = checking whether printf supports the 'a' and 'A' directives...
774 dnl 5 = checking whether printf supports the 'F' directive...
775 dnl 6 = checking whether printf supports the 'n' directive...
776 dnl 7 = checking whether printf supports POSIX/XSI format strings with positions...
777 dnl 8 = checking whether printf supports the grouping flag...
778 dnl 9 = checking whether printf supports the zero flag correctly...
779 dnl 10 = checking for snprintf...
780 dnl 11 = checking whether snprintf truncates the result as in C99...
781 dnl 12 = checking whether snprintf returns a byte count as in C99...
782 dnl 13 = checking whether snprintf fully supports the 'n' directive...
783 dnl 14 = checking whether vsnprintf respects a zero size as in C99...
787 dnl 1 2 3 4 5 6 7 8 9 10 11 12 13 14
788 dnl glibc 2.5 . . . . . . . . . . . . . .
789 dnl glibc 2.3.6 . . . # . . . . . . . . . .
790 dnl FreeBSD 5.4, 6.1 . . ? ? . . . . # . . . . .
791 dnl MacOS X 10.3.9 . . . # . . . . # . . . . .
792 dnl OpenBSD 3.9, 4.0 . ? ? # ? . . ? ? . . . ? ?
793 dnl Cygwin 2007 (= Cygwin 1.5.24) . ? ? # # . . . # . . . . .
794 dnl Cygwin 2006 (= Cygwin 1.5.19) # ? ? # # . . # # . . . . .
795 dnl Solaris 10 . ? . # . . . . # . . . . .
796 dnl Solaris 2.6 ... 9 # ? . # # . . . # . . . . .
797 dnl Solaris 2.5.1 # ? . # # . . . # # # # # #
798 dnl AIX 5.2 . ? . # . . . . # . . . . .
799 dnl AIX 4.3.2, 5.1 # ? . # # . . . # . . . . .
800 dnl HP-UX 11.31 . . . # . . . . # . . # # .
801 dnl HP-UX 10.20, 11.{00,11,23} # . . # # . . . # . . # # #
802 dnl IRIX 6.5 # ? . # # . . . # . . # . .
803 dnl OSF/1 5.1 # ? . # # . . . # . . # . #
804 dnl OSF/1 4.0d # ? . # # . . . # # # # # #
805 dnl NetBSD 4.0 . ? ? ? ? . . ? ? . . . ? ?
806 dnl NetBSD 3.0 . ? ? # # . # # # . . . . .
807 dnl BeOS # ? # # # . # . . . . . . .
808 dnl mingw # # # # # . # # # . # # # .