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([gt_TYPE_LONGDOUBLE])
17 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
18 AC_CACHE_CHECK([whether printf supports size specifiers as in C99],
19 [gl_cv_func_printf_sizes_c99],
25 #include <sys/types.h>
26 #if HAVE_STDINT_H_WITH_UINTMAX
29 #if HAVE_INTTYPES_H_WITH_UINTMAX
30 # include <inttypes.h>
35 #if HAVE_STDINT_H_WITH_UINTMAX || HAVE_INTTYPES_H_WITH_UINTMAX
37 if (sprintf (buf, "%ju %d", (uintmax_t) 12345671, 33, 44, 55) < 0
38 || strcmp (buf, "12345671 33") != 0)
42 if (sprintf (buf, "%zu %d", (size_t) 12345672, 33, 44, 55) < 0
43 || strcmp (buf, "12345672 33") != 0)
46 if (sprintf (buf, "%tu %d", (ptrdiff_t) 12345673, 33, 44, 55) < 0
47 || strcmp (buf, "12345673 33") != 0)
51 if (sprintf (buf, "%Lg %d", (long double) 1.5, 33, 44, 55) < 0
52 || strcmp (buf, "1.5 33") != 0)
56 }], [gl_cv_func_printf_sizes_c99=yes], [gl_cv_func_printf_sizes_c99=no],
60 dnl Guess yes on glibc systems.
61 *-gnu*) gl_cv_func_printf_sizes_c99="guessing yes";;
62 dnl Guess yes on FreeBSD >= 5.
63 freebsd[1-4]*) gl_cv_func_printf_sizes_c99="guessing no";;
64 freebsd* | kfreebsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
65 dnl Guess yes on MacOS X >= 10.3.
66 darwin[1-6].*) gl_cv_func_printf_sizes_c99="guessing no";;
67 darwin*) gl_cv_func_printf_sizes_c99="guessing yes";;
68 dnl Guess yes on OpenBSD >= 3.9.
69 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
70 gl_cv_func_printf_sizes_c99="guessing no";;
71 openbsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
72 dnl Guess yes on Solaris >= 2.10.
73 solaris2.[0-9]*) gl_cv_func_printf_sizes_c99="guessing no";;
74 solaris*) gl_cv_func_printf_sizes_c99="guessing yes";;
75 dnl Guess yes on NetBSD >= 3.
76 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
77 gl_cv_func_printf_sizes_c99="guessing no";;
78 netbsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
79 dnl If we don't know, assume the worst.
80 *) gl_cv_func_printf_sizes_c99="guessing no";;
87 dnl Test whether the *printf family of functions supports the 'a' and 'A'
88 dnl conversion specifier for hexadecimal output of floating-point numbers.
89 dnl (ISO C99, POSIX:2001)
90 dnl Result is gl_cv_func_printf_directive_a.
92 AC_DEFUN([gl_PRINTF_DIRECTIVE_A],
94 AC_REQUIRE([AC_PROG_CC])
95 AC_REQUIRE([gt_TYPE_LONGDOUBLE])
96 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
97 AC_CACHE_CHECK([whether printf supports the 'a' and 'A' directives],
98 [gl_cv_func_printf_directive_a],
103 static char buf[100];
106 if (sprintf (buf, "%a %d", 3.1416015625, 33, 44, 55) < 0
107 || (strcmp (buf, "0x1.922p+1 33") != 0
108 && strcmp (buf, "0x3.244p+0 33") != 0
109 && strcmp (buf, "0x6.488p-1 33") != 0
110 && strcmp (buf, "0xc.91p-2 33") != 0))
112 if (sprintf (buf, "%A %d", -3.1416015625, 33, 44, 55) < 0
113 || (strcmp (buf, "-0X1.922P+1 33") != 0
114 && strcmp (buf, "-0X3.244P+0 33") != 0
115 && strcmp (buf, "-0X6.488P-1 33") != 0
116 && strcmp (buf, "-0XC.91P-2 33") != 0))
118 /* This catches a MacOS X 10.3.9 (Darwin 7.9) bug. */
119 if (sprintf (buf, "%.1a", 1.999) < 0
120 || (strcmp (buf, "0x1.0p+1") != 0
121 && strcmp (buf, "0x2.0p+0") != 0
122 && strcmp (buf, "0x4.0p-1") != 0
123 && strcmp (buf, "0x8.0p-2") != 0))
126 /* This catches the same MacOS X 10.3.9 (Darwin 7.9) bug and also a
127 glibc 2.4 bug <http://sourceware.org/bugzilla/show_bug.cgi?id=2908>. */
128 if (sprintf (buf, "%.1La", 1.999L) < 0
129 || (strcmp (buf, "0x1.0p+1") != 0
130 && strcmp (buf, "0x2.0p+0") != 0
131 && strcmp (buf, "0x4.0p-1") != 0
132 && strcmp (buf, "0x8.0p-2") != 0))
136 }], [gl_cv_func_printf_directive_a=yes], [gl_cv_func_printf_directive_a=no],
139 dnl Guess yes on glibc >= 2.5 systems.
141 AC_EGREP_CPP([BZ2908], [
142 #include <features.h>
143 #ifdef __GNU_LIBRARY__
144 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 5) || (__GLIBC__ > 2)
149 [gl_cv_func_printf_directive_a="guessing yes"],
150 [gl_cv_func_printf_directive_a="guessing no"])
153 dnl Guess yes on FreeBSD >= 5.
154 freebsd[1-4]*) gl_cv_func_printf_directive_a="guessing no";;
155 freebsd* | kfreebsd*) gl_cv_func_printf_directive_a="guessing yes";;
156 dnl Guess yes on NetBSD >= 4.
157 netbsd[1-3]* | netbsdelf[1-3]* | netbsdaout[1-3]* | netbsdcoff[1-3]*)
158 gl_cv_func_printf_directive_a="guessing no";;
159 netbsd*) gl_cv_func_printf_directive_a="guessing yes";;
160 dnl If we don't know, assume the worst.
161 *) gl_cv_func_printf_directive_a="guessing no";;
168 dnl Test whether the *printf family of functions supports the %n format
169 dnl directive. (ISO C99, POSIX:2001)
170 dnl Result is gl_cv_func_printf_directive_n.
172 AC_DEFUN([gl_PRINTF_DIRECTIVE_N],
174 AC_REQUIRE([AC_PROG_CC])
175 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
176 AC_CACHE_CHECK([whether printf supports the 'n' directive],
177 [gl_cv_func_printf_directive_n],
182 static char buf[100];
186 if (sprintf (buf, "%d %n", 123, &count, 33, 44, 55) < 0
187 || strcmp (buf, "123 ") != 0
191 }], [gl_cv_func_printf_directive_n=yes], [gl_cv_func_printf_directive_n=no],
195 *) gl_cv_func_printf_directive_n="guessing yes";;
202 dnl Test whether the *printf family of functions supports POSIX/XSI format
203 dnl strings with positions. (POSIX:2001)
204 dnl Result is gl_cv_func_printf_positions.
206 AC_DEFUN([gl_PRINTF_POSITIONS],
208 AC_REQUIRE([AC_PROG_CC])
209 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
210 AC_CACHE_CHECK([whether printf supports POSIX/XSI format strings with positions],
211 [gl_cv_func_printf_positions],
216 /* The string "%2$d %1$d", with dollar characters protected from the shell's
217 dollar expansion (possibly an autoconf bug). */
218 static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' };
219 static char buf[100];
222 sprintf (buf, format, 33, 55);
223 return (strcmp (buf, "55 33") != 0);
224 }], [gl_cv_func_printf_positions=yes], [gl_cv_func_printf_positions=no],
228 netbsd[1-3]* | netbsdelf[1-3]* | netbsdaout[1-3]* | netbsdcoff[1-3]*)
229 gl_cv_func_printf_positions="guessing no";;
230 beos*) gl_cv_func_printf_positions="guessing no";;
231 mingw* | pw*) gl_cv_func_printf_positions="guessing no";;
232 *) gl_cv_func_printf_positions="guessing yes";;
239 dnl Test whether the snprintf function exists. (ISO C99, POSIX:2001)
240 dnl Result is ac_cv_func_snprintf.
242 AC_DEFUN([gl_SNPRINTF_PRESENCE],
244 AC_CHECK_FUNCS_ONCE([snprintf])
247 dnl Test whether the string produced by the snprintf function is always NUL
248 dnl terminated. (ISO C99, POSIX:2001)
249 dnl Result is gl_cv_func_snprintf_truncation_c99.
251 AC_DEFUN([gl_SNPRINTF_TRUNCATION_C99],
253 AC_REQUIRE([AC_PROG_CC])
254 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
255 AC_CACHE_CHECK([whether snprintf truncates the result as in C99],
256 [gl_cv_func_snprintf_truncation_c99],
261 static char buf[100];
264 strcpy (buf, "ABCDEF");
265 snprintf (buf, 3, "%d %d", 4567, 89);
266 if (memcmp (buf, "45\0DEF", 6) != 0)
269 }], [gl_cv_func_snprintf_truncation_c99=yes], [gl_cv_func_snprintf_truncation_c99=no],
273 dnl Guess yes on glibc systems.
274 *-gnu*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
275 dnl Guess yes on FreeBSD >= 5.
276 freebsd[1-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
277 freebsd* | kfreebsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
278 dnl Guess yes on MacOS X >= 10.3.
279 darwin[1-6].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
280 darwin*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
281 dnl Guess yes on OpenBSD >= 3.9.
282 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
283 gl_cv_func_snprintf_truncation_c99="guessing no";;
284 openbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
285 dnl Guess yes on Solaris >= 2.6.
286 solaris2.[0-5]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
287 solaris*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
288 dnl Guess yes on AIX >= 4.
289 aix[1-3]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
290 aix*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
291 dnl Guess yes on HP-UX >= 11.
292 hpux[7-9]* | hpux10*) gl_cv_func_snprintf_truncation_c99="guessing no";;
293 hpux*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
294 dnl Guess yes on IRIX >= 6.5.
295 irix6.5) gl_cv_func_snprintf_truncation_c99="guessing yes";;
296 dnl Guess yes on OSF/1 >= 5.
297 osf[3-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
298 osf*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
299 dnl Guess yes on NetBSD >= 3.
300 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
301 gl_cv_func_snprintf_truncation_c99="guessing no";;
302 netbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
303 dnl Guess yes on BeOS.
304 beos*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
305 dnl If we don't know, assume the worst.
306 *) gl_cv_func_snprintf_truncation_c99="guessing no";;
313 dnl Test whether the return value of the snprintf function is the number
314 dnl of bytes (excluding the terminating NUL) that would have been produced
315 dnl if the buffer had been large enough. (ISO C99, POSIX:2001)
316 dnl Result is gl_cv_func_snprintf_retval_c99.
318 AC_DEFUN([gl_SNPRINTF_RETVAL_C99],
320 AC_REQUIRE([AC_PROG_CC])
321 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
322 AC_CACHE_CHECK([whether snprintf returns a byte count as in C99],
323 [gl_cv_func_snprintf_retval_c99],
328 static char buf[100];
331 strcpy (buf, "ABCDEF");
332 if (snprintf (buf, 3, "%d %d", 4567, 89) != 7)
335 }], [gl_cv_func_snprintf_retval_c99=yes], [gl_cv_func_snprintf_retval_c99=no],
339 dnl Guess yes on glibc systems.
340 *-gnu*) gl_cv_func_snprintf_retval_c99="guessing yes";;
341 dnl Guess yes on FreeBSD >= 5.
342 freebsd[1-4]*) gl_cv_func_snprintf_retval_c99="guessing no";;
343 freebsd* | kfreebsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
344 dnl Guess yes on MacOS X >= 10.3.
345 darwin[1-6].*) gl_cv_func_snprintf_retval_c99="guessing no";;
346 darwin*) gl_cv_func_snprintf_retval_c99="guessing yes";;
347 dnl Guess yes on OpenBSD >= 3.9.
348 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
349 gl_cv_func_snprintf_retval_c99="guessing no";;
350 openbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
351 dnl Guess yes on Solaris >= 2.6.
352 solaris2.[0-5]*) gl_cv_func_snprintf_retval_c99="guessing no";;
353 solaris*) gl_cv_func_snprintf_retval_c99="guessing yes";;
354 dnl Guess yes on AIX >= 4.
355 aix[1-3]*) gl_cv_func_snprintf_retval_c99="guessing no";;
356 aix*) gl_cv_func_snprintf_retval_c99="guessing yes";;
357 dnl Guess yes on NetBSD >= 3.
358 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
359 gl_cv_func_snprintf_retval_c99="guessing no";;
360 netbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
361 dnl Guess yes on BeOS.
362 beos*) gl_cv_func_snprintf_retval_c99="guessing yes";;
363 dnl If we don't know, assume the worst.
364 *) gl_cv_func_snprintf_retval_c99="guessing no";;
371 dnl Test whether the snprintf function supports the %n format directive
372 dnl also in truncated portions of the format string. (ISO C99, POSIX:2001)
373 dnl Result is gl_cv_func_snprintf_directive_n.
375 AC_DEFUN([gl_SNPRINTF_DIRECTIVE_N],
377 AC_REQUIRE([AC_PROG_CC])
378 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
379 AC_CACHE_CHECK([whether snprintf fully supports the 'n' directive],
380 [gl_cv_func_snprintf_directive_n],
385 static char buf[100];
389 snprintf (buf, 4, "%d %n", 12345, &count, 33, 44, 55);
393 }], [gl_cv_func_snprintf_directive_n=yes], [gl_cv_func_snprintf_directive_n=no],
397 dnl Guess yes on glibc systems.
398 *-gnu*) gl_cv_func_snprintf_directive_n="guessing yes";;
399 dnl Guess yes on FreeBSD >= 5.
400 freebsd[1-4]*) gl_cv_func_snprintf_directive_n="guessing no";;
401 freebsd* | kfreebsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
402 dnl Guess yes on MacOS X >= 10.3.
403 darwin[1-6].*) gl_cv_func_snprintf_directive_n="guessing no";;
404 darwin*) gl_cv_func_snprintf_directive_n="guessing yes";;
405 dnl Guess yes on Solaris >= 2.6.
406 solaris2.[0-5]*) gl_cv_func_snprintf_directive_n="guessing no";;
407 solaris*) gl_cv_func_snprintf_directive_n="guessing yes";;
408 dnl Guess yes on AIX >= 4.
409 aix[1-3]*) gl_cv_func_snprintf_directive_n="guessing no";;
410 aix*) gl_cv_func_snprintf_directive_n="guessing yes";;
411 dnl Guess yes on IRIX >= 6.5.
412 irix6.5) gl_cv_func_snprintf_directive_n="guessing yes";;
413 dnl Guess yes on OSF/1 >= 5.
414 osf[3-4]*) gl_cv_func_snprintf_directive_n="guessing no";;
415 osf*) gl_cv_func_snprintf_directive_n="guessing yes";;
416 dnl Guess yes on NetBSD >= 3.
417 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
418 gl_cv_func_snprintf_directive_n="guessing no";;
419 netbsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
420 dnl Guess yes on BeOS.
421 beos*) gl_cv_func_snprintf_directive_n="guessing yes";;
422 dnl If we don't know, assume the worst.
423 *) gl_cv_func_snprintf_directive_n="guessing no";;
430 dnl The results of these tests on various platforms are:
432 dnl 1 = gl_PRINTF_SIZES_C99
433 dnl 2 = gl_PRINTF_DIRECTIVE_A
434 dnl 3 = gl_PRINTF_DIRECTIVE_N
435 dnl 4 = gl_PRINTF_POSITIONS
436 dnl 5 = gl_SNPRINTF_PRESENCE
437 dnl 6 = gl_SNPRINTF_TRUNCATION_C99
438 dnl 7 = gl_SNPRINTF_RETVAL_C99
439 dnl 8 = gl_SNPRINTF_DIRECTIVE_N
441 dnl 1 = checking whether printf supports size specifiers as in C99...
442 dnl 2 = checking whether printf supports the 'a' and 'A' directives...
443 dnl 3 = checking whether printf supports the 'n' directive...
444 dnl 4 = checking whether printf supports POSIX/XSI format strings with positions...
445 dnl 5 = checking for snprintf...
446 dnl 6 = checking whether snprintf truncates the result as in C99...
447 dnl 7 = checking whether snprintf returns a byte count as in C99...
448 dnl 8 = checking whether snprintf fully supports the 'n' directive...
453 dnl glibc 2.5 . . . . . . . .
454 dnl glibc 2.3.6 . # . . . . . .
455 dnl FreeBSD 5.4, 6.1 . . . . . . . .
456 dnl MacOS X 10.3.9 . # . . . . . .
457 dnl OpenBSD 3.9 . # . . . . . ?
458 dnl Cygwin 2007 . # . . . . . ?
459 dnl Cygwin 2006 # # . . . . . ?
460 dnl Solaris 10 . # . . . . . .
461 dnl Solaris 2.6 ... 9 # # . . . . . .
462 dnl Solaris 2.5.1 # # . . # # # #
463 dnl AIX 4.3.2, 5.1 # # . . . . . .
464 dnl HP-UX 11.31 . # . . . . # #
465 dnl HP-UX 10.20, 11.00, 11.11, 11.23 # # . . . . # #
466 dnl IRIX 6.5 # # . . . . # .
467 dnl OSF/1 5.1 # # . . . . # .
468 dnl OSF/1 4.0d # # . . # # # #
469 dnl NetBSD 4.0 . . . . . . . ?
470 dnl NetBSD 3.0 . # . # . . . .
471 dnl BeOS # # . # . . . .
472 dnl mingw # # . # . # # #