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 the 'a' and 'A'
85 dnl conversion specifier for hexadecimal output of floating-point numbers.
86 dnl (ISO C99, POSIX:2001)
87 dnl Result is gl_cv_func_printf_directive_a.
89 AC_DEFUN([gl_PRINTF_DIRECTIVE_A],
91 AC_REQUIRE([AC_PROG_CC])
92 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
93 AC_CACHE_CHECK([whether printf supports the 'a' and 'A' directives],
94 [gl_cv_func_printf_directive_a],
102 if (sprintf (buf, "%a %d", 3.1416015625, 33, 44, 55) < 0
103 || (strcmp (buf, "0x1.922p+1 33") != 0
104 && strcmp (buf, "0x3.244p+0 33") != 0
105 && strcmp (buf, "0x6.488p-1 33") != 0
106 && strcmp (buf, "0xc.91p-2 33") != 0))
108 if (sprintf (buf, "%A %d", -3.1416015625, 33, 44, 55) < 0
109 || (strcmp (buf, "-0X1.922P+1 33") != 0
110 && strcmp (buf, "-0X3.244P+0 33") != 0
111 && strcmp (buf, "-0X6.488P-1 33") != 0
112 && strcmp (buf, "-0XC.91P-2 33") != 0))
114 /* This catches a FreeBSD 6.1 bug: it doesn't round. */
115 if (sprintf (buf, "%.2a %d", 1.51, 33, 44, 55) < 0
116 || (strcmp (result, "0x1.83p+0 33") != 0
117 && strcmp (result, "0x3.05p-1 33") != 0
118 && strcmp (result, "0x6.0ap-2 33") != 0
119 && strcmp (result, "0xc.14p-3 33") != 0))
121 /* This catches a MacOS X 10.3.9 (Darwin 7.9) bug. */
122 if (sprintf (buf, "%.1a", 1.999) < 0
123 || (strcmp (buf, "0x1.0p+1") != 0
124 && strcmp (buf, "0x2.0p+0") != 0
125 && strcmp (buf, "0x4.0p-1") != 0
126 && strcmp (buf, "0x8.0p-2") != 0))
128 /* This catches the same MacOS X 10.3.9 (Darwin 7.9) bug and also a
129 glibc 2.4 bug <http://sourceware.org/bugzilla/show_bug.cgi?id=2908>. */
130 if (sprintf (buf, "%.1La", 1.999L) < 0
131 || (strcmp (buf, "0x1.0p+1") != 0
132 && strcmp (buf, "0x2.0p+0") != 0
133 && strcmp (buf, "0x4.0p-1") != 0
134 && strcmp (buf, "0x8.0p-2") != 0))
137 }], [gl_cv_func_printf_directive_a=yes], [gl_cv_func_printf_directive_a=no],
140 # Guess yes on glibc >= 2.5 systems.
142 AC_EGREP_CPP([BZ2908], [
143 #include <features.h>
144 #ifdef __GNU_LIBRARY__
145 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 5) || (__GLIBC__ > 2)
150 [gl_cv_func_printf_directive_a="guessing yes"],
151 [gl_cv_func_printf_directive_a="guessing no"])
153 # If we don't know, assume the worst.
154 *) gl_cv_func_printf_directive_a="guessing no";;
160 dnl Test whether the *printf family of functions supports the %n format
161 dnl directive. (ISO C99, POSIX:2001)
162 dnl Result is gl_cv_func_printf_directive_n.
164 AC_DEFUN([gl_PRINTF_DIRECTIVE_N],
166 AC_REQUIRE([AC_PROG_CC])
167 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
168 AC_CACHE_CHECK([whether printf supports the 'n' directive],
169 [gl_cv_func_printf_directive_n],
174 static char buf[100];
178 if (sprintf (buf, "%d %n", 123, &count, 33, 44, 55) < 0
179 || strcmp (buf, "123 ") != 0
183 }], [gl_cv_func_printf_directive_n=yes], [gl_cv_func_printf_directive_n=no],
187 *) gl_cv_func_printf_directive_n="guessing yes";;
194 dnl Test whether the *printf family of functions supports POSIX/XSI format
195 dnl strings with positions. (POSIX:2001)
196 dnl Result is gl_cv_func_printf_positions.
198 AC_DEFUN([gl_PRINTF_POSITIONS],
200 AC_REQUIRE([AC_PROG_CC])
201 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
202 AC_CACHE_CHECK([whether printf supports POSIX/XSI format strings with positions],
203 [gl_cv_func_printf_positions],
208 /* The string "%2$d %1$d", with dollar characters protected from the shell's
209 dollar expansion (possibly an autoconf bug). */
210 static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' };
211 static char buf[100];
214 sprintf (buf, format, 33, 55);
215 return (strcmp (buf, "55 33") != 0);
216 }], [gl_cv_func_printf_positions=yes], [gl_cv_func_printf_positions=no],
220 netbsd[1-3]* | netbsdelf[1-3]* | netbsdaout[1-3]* | netbsdcoff[1-3]*)
221 gl_cv_func_printf_positions="guessing no";;
222 beos*) gl_cv_func_printf_positions="guessing no";;
223 mingw* | pw*) gl_cv_func_printf_positions="guessing no";;
224 *) gl_cv_func_printf_positions="guessing yes";;
231 dnl Test whether the snprintf function exists. (ISO C99, POSIX:2001)
232 dnl Result is ac_cv_func_snprintf.
234 AC_DEFUN([gl_SNPRINTF_PRESENCE],
236 AC_CHECK_FUNCS_ONCE([snprintf])
239 dnl Test whether the string produced by the snprintf function is always NUL
240 dnl terminated. (ISO C99, POSIX:2001)
241 dnl Result is gl_cv_func_snprintf_truncation_c99.
243 AC_DEFUN([gl_SNPRINTF_TRUNCATION_C99],
245 AC_REQUIRE([AC_PROG_CC])
246 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
247 AC_CACHE_CHECK([whether snprintf truncates the result as in C99],
248 [gl_cv_func_snprintf_truncation_c99],
253 static char buf[100];
256 strcpy (buf, "ABCDEF");
257 snprintf (buf, 3, "%d %d", 4567, 89);
258 if (memcmp (buf, "45\0DEF", 6) != 0)
261 }], [gl_cv_func_snprintf_truncation_c99=yes], [gl_cv_func_snprintf_truncation_c99=no],
265 # Guess yes on glibc systems.
266 *-gnu*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
267 # Guess yes on FreeBSD >= 5.
268 freebsd[1-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
269 freebsd* | kfreebsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
270 # Guess yes on MacOS X >= 10.3.
271 darwin[1-6].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
272 darwin*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
273 # Guess yes on OpenBSD >= 3.9.
274 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
275 gl_cv_func_snprintf_truncation_c99="guessing no";;
276 openbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
277 # Guess yes on Solaris >= 2.6.
278 solaris2.[0-5]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
279 solaris*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
280 # Guess yes on AIX >= 4.
281 aix[1-3]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
282 aix*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
283 # Guess yes on HP-UX >= 11.
284 hpux[7-9]* | hpux10*) gl_cv_func_snprintf_truncation_c99="guessing no";;
285 hpux*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
286 # Guess yes on IRIX >= 6.5.
287 irix6.5) gl_cv_func_snprintf_truncation_c99="guessing yes";;
288 # Guess yes on OSF/1 >= 5.
289 osf[3-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
290 osf*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
291 # Guess yes on NetBSD >= 3.
292 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
293 gl_cv_func_snprintf_truncation_c99="guessing no";;
294 netbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
296 beos*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
297 # If we don't know, assume the worst.
298 *) gl_cv_func_snprintf_truncation_c99="guessing no";;
305 dnl Test whether the return value of the snprintf function is the number
306 dnl of bytes (excluding the terminating NUL) that would have been produced
307 dnl if the buffer had been large enough. (ISO C99, POSIX:2001)
308 dnl Result is gl_cv_func_snprintf_retval_c99.
310 AC_DEFUN([gl_SNPRINTF_RETVAL_C99],
312 AC_REQUIRE([AC_PROG_CC])
313 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
314 AC_CACHE_CHECK([whether snprintf returns a byte count as in C99],
315 [gl_cv_func_snprintf_retval_c99],
320 static char buf[100];
323 strcpy (buf, "ABCDEF");
324 if (snprintf (buf, 3, "%d %d", 4567, 89) != 7)
327 }], [gl_cv_func_snprintf_retval_c99=yes], [gl_cv_func_snprintf_retval_c99=no],
331 # Guess yes on glibc systems.
332 *-gnu*) gl_cv_func_snprintf_retval_c99="guessing yes";;
333 # Guess yes on FreeBSD >= 5.
334 freebsd[1-4]*) gl_cv_func_snprintf_retval_c99="guessing no";;
335 freebsd* | kfreebsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
336 # Guess yes on MacOS X >= 10.3.
337 darwin[1-6].*) gl_cv_func_snprintf_retval_c99="guessing no";;
338 darwin*) gl_cv_func_snprintf_retval_c99="guessing yes";;
339 # Guess yes on OpenBSD >= 3.9.
340 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
341 gl_cv_func_snprintf_retval_c99="guessing no";;
342 openbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
343 # Guess yes on Solaris >= 2.6.
344 solaris2.[0-5]*) gl_cv_func_snprintf_retval_c99="guessing no";;
345 solaris*) gl_cv_func_snprintf_retval_c99="guessing yes";;
346 # Guess yes on AIX >= 4.
347 aix[1-3]*) gl_cv_func_snprintf_retval_c99="guessing no";;
348 aix*) gl_cv_func_snprintf_retval_c99="guessing yes";;
349 # Guess yes on NetBSD >= 3.
350 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
351 gl_cv_func_snprintf_retval_c99="guessing no";;
352 netbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
354 beos*) gl_cv_func_snprintf_retval_c99="guessing yes";;
355 # If we don't know, assume the worst.
356 *) gl_cv_func_snprintf_retval_c99="guessing no";;
363 dnl Test whether the snprintf function supports the %n format directive
364 dnl also in truncated portions of the format string. (ISO C99, POSIX:2001)
365 dnl Result is gl_cv_func_snprintf_directive_n.
367 AC_DEFUN([gl_SNPRINTF_DIRECTIVE_N],
369 AC_REQUIRE([AC_PROG_CC])
370 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
371 AC_CACHE_CHECK([whether snprintf fully supports the 'n' directive],
372 [gl_cv_func_snprintf_directive_n],
377 static char buf[100];
381 snprintf (buf, 4, "%d %n", 12345, &count, 33, 44, 55);
385 }], [gl_cv_func_snprintf_directive_n=yes], [gl_cv_func_snprintf_directive_n=no],
389 # Guess yes on glibc systems.
390 *-gnu*) gl_cv_func_snprintf_directive_n="guessing yes";;
391 # Guess yes on FreeBSD >= 5.
392 freebsd[1-4]*) gl_cv_func_snprintf_directive_n="guessing no";;
393 freebsd* | kfreebsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
394 # Guess yes on MacOS X >= 10.3.
395 darwin[1-6].*) gl_cv_func_snprintf_directive_n="guessing no";;
396 darwin*) gl_cv_func_snprintf_directive_n="guessing yes";;
397 # Guess yes on Solaris >= 2.6.
398 solaris2.[0-5]*) gl_cv_func_snprintf_directive_n="guessing no";;
399 solaris*) gl_cv_func_snprintf_directive_n="guessing yes";;
400 # Guess yes on AIX >= 4.
401 aix[1-3]*) gl_cv_func_snprintf_directive_n="guessing no";;
402 aix*) gl_cv_func_snprintf_directive_n="guessing yes";;
403 # Guess yes on IRIX >= 6.5.
404 irix6.5) gl_cv_func_snprintf_directive_n="guessing yes";;
405 # Guess yes on OSF/1 >= 5.
406 osf[3-4]*) gl_cv_func_snprintf_directive_n="guessing no";;
407 osf*) gl_cv_func_snprintf_directive_n="guessing yes";;
408 # Guess yes on NetBSD >= 3.
409 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
410 gl_cv_func_snprintf_directive_n="guessing no";;
411 netbsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
413 beos*) gl_cv_func_snprintf_directive_n="guessing yes";;
414 # If we don't know, assume the worst.
415 *) gl_cv_func_snprintf_directive_n="guessing no";;
422 dnl The results of these tests on various platforms are:
424 dnl 1 = gl_PRINTF_SIZES_C99
425 dnl 2 = gl_PRINTF_DIRECTIVE_A
426 dnl 3 = gl_PRINTF_DIRECTIVE_N
427 dnl 4 = gl_PRINTF_POSITIONS
428 dnl 5 = gl_SNPRINTF_PRESENCE
429 dnl 6 = gl_SNPRINTF_TRUNCATION_C99
430 dnl 7 = gl_SNPRINTF_RETVAL_C99
431 dnl 8 = gl_SNPRINTF_DIRECTIVE_N
433 dnl 1 = checking whether printf supports size specifiers as in C99...
434 dnl 2 = checking whether printf supports the 'a' and 'A' directives...
435 dnl 3 = checking whether printf supports the 'n' directive...
436 dnl 4 = checking whether printf supports POSIX/XSI format strings with positions...
437 dnl 5 = checking for snprintf...
438 dnl 6 = checking whether snprintf truncates the result as in C99...
439 dnl 7 = checking whether snprintf returns a byte count as in C99...
440 dnl 8 = checking whether snprintf fully supports the 'n' directive...
445 dnl glibc 2.5 . . . . . . . .
446 dnl glibc 2.3.6 . # . . . . . .
447 dnl FreeBSD 5.4, 6.1 . ? . . . . . .
448 dnl MacOS X 10.3.9 . # . . . . . .
449 dnl OpenBSD 3.9, 4.0 . # . . . . . ?
450 dnl Cygwin 2007 . # . . . . . ?
451 dnl Cygwin 2006 # # . . . . . ?
452 dnl Solaris 10 . # . . . . . .
453 dnl Solaris 2.6 ... 9 # # . . . . . .
454 dnl Solaris 2.5.1 # # . . # # # #
455 dnl AIX 4.3.2, 5.1 # # . . . . . .
456 dnl HP-UX 11.31 . # . . . . # #
457 dnl HP-UX 10.20, 11.00, 11.11, 11.23 # # . . . . # #
458 dnl IRIX 6.5 # # . . . . # .
459 dnl OSF/1 5.1 # # . . . . # .
460 dnl OSF/1 4.0d # # . . # # # #
461 dnl NetBSD 4.0 . ? . . . . . ?
462 dnl NetBSD 3.0 . # . # . . . .
463 dnl BeOS # # . # . . . .
464 dnl mingw # # . # . # # #