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 # Guess yes on glibc systems.
61 *-gnu*) gl_cv_func_printf_sizes_c99="guessing yes";;
62 # 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 # 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 # 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 # 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 # 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 # 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 FreeBSD 6.1 bug: it doesn't round. */
119 if (sprintf (buf, "%.2a %d", 1.51, 33, 44, 55) < 0
120 || (strcmp (result, "0x1.83p+0 33") != 0
121 && strcmp (result, "0x3.05p-1 33") != 0
122 && strcmp (result, "0x6.0ap-2 33") != 0
123 && strcmp (result, "0xc.14p-3 33") != 0))
125 /* This catches a MacOS X 10.3.9 (Darwin 7.9) bug. */
126 if (sprintf (buf, "%.1a", 1.999) < 0
127 || (strcmp (buf, "0x1.0p+1") != 0
128 && strcmp (buf, "0x2.0p+0") != 0
129 && strcmp (buf, "0x4.0p-1") != 0
130 && strcmp (buf, "0x8.0p-2") != 0))
133 /* This catches the same MacOS X 10.3.9 (Darwin 7.9) bug and also a
134 glibc 2.4 bug <http://sourceware.org/bugzilla/show_bug.cgi?id=2908>. */
135 if (sprintf (buf, "%.1La", 1.999L) < 0
136 || (strcmp (buf, "0x1.0p+1") != 0
137 && strcmp (buf, "0x2.0p+0") != 0
138 && strcmp (buf, "0x4.0p-1") != 0
139 && strcmp (buf, "0x8.0p-2") != 0))
143 }], [gl_cv_func_printf_directive_a=yes], [gl_cv_func_printf_directive_a=no],
146 # Guess yes on glibc >= 2.5 systems.
148 AC_EGREP_CPP([BZ2908], [
149 #include <features.h>
150 #ifdef __GNU_LIBRARY__
151 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 5) || (__GLIBC__ > 2)
156 [gl_cv_func_printf_directive_a="guessing yes"],
157 [gl_cv_func_printf_directive_a="guessing no"])
159 # If we don't know, assume the worst.
160 *) gl_cv_func_printf_directive_a="guessing no";;
166 dnl Test whether the *printf family of functions supports the %n format
167 dnl directive. (ISO C99, POSIX:2001)
168 dnl Result is gl_cv_func_printf_directive_n.
170 AC_DEFUN([gl_PRINTF_DIRECTIVE_N],
172 AC_REQUIRE([AC_PROG_CC])
173 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
174 AC_CACHE_CHECK([whether printf supports the 'n' directive],
175 [gl_cv_func_printf_directive_n],
180 static char buf[100];
184 if (sprintf (buf, "%d %n", 123, &count, 33, 44, 55) < 0
185 || strcmp (buf, "123 ") != 0
189 }], [gl_cv_func_printf_directive_n=yes], [gl_cv_func_printf_directive_n=no],
193 *) gl_cv_func_printf_directive_n="guessing yes";;
200 dnl Test whether the *printf family of functions supports POSIX/XSI format
201 dnl strings with positions. (POSIX:2001)
202 dnl Result is gl_cv_func_printf_positions.
204 AC_DEFUN([gl_PRINTF_POSITIONS],
206 AC_REQUIRE([AC_PROG_CC])
207 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
208 AC_CACHE_CHECK([whether printf supports POSIX/XSI format strings with positions],
209 [gl_cv_func_printf_positions],
214 /* The string "%2$d %1$d", with dollar characters protected from the shell's
215 dollar expansion (possibly an autoconf bug). */
216 static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' };
217 static char buf[100];
220 sprintf (buf, format, 33, 55);
221 return (strcmp (buf, "55 33") != 0);
222 }], [gl_cv_func_printf_positions=yes], [gl_cv_func_printf_positions=no],
226 netbsd[1-3]* | netbsdelf[1-3]* | netbsdaout[1-3]* | netbsdcoff[1-3]*)
227 gl_cv_func_printf_positions="guessing no";;
228 beos*) gl_cv_func_printf_positions="guessing no";;
229 mingw* | pw*) gl_cv_func_printf_positions="guessing no";;
230 *) gl_cv_func_printf_positions="guessing yes";;
237 dnl Test whether the snprintf function exists. (ISO C99, POSIX:2001)
238 dnl Result is ac_cv_func_snprintf.
240 AC_DEFUN([gl_SNPRINTF_PRESENCE],
242 AC_CHECK_FUNCS_ONCE([snprintf])
245 dnl Test whether the string produced by the snprintf function is always NUL
246 dnl terminated. (ISO C99, POSIX:2001)
247 dnl Result is gl_cv_func_snprintf_truncation_c99.
249 AC_DEFUN([gl_SNPRINTF_TRUNCATION_C99],
251 AC_REQUIRE([AC_PROG_CC])
252 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
253 AC_CACHE_CHECK([whether snprintf truncates the result as in C99],
254 [gl_cv_func_snprintf_truncation_c99],
259 static char buf[100];
262 strcpy (buf, "ABCDEF");
263 snprintf (buf, 3, "%d %d", 4567, 89);
264 if (memcmp (buf, "45\0DEF", 6) != 0)
267 }], [gl_cv_func_snprintf_truncation_c99=yes], [gl_cv_func_snprintf_truncation_c99=no],
271 # Guess yes on glibc systems.
272 *-gnu*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
273 # Guess yes on FreeBSD >= 5.
274 freebsd[1-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
275 freebsd* | kfreebsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
276 # Guess yes on MacOS X >= 10.3.
277 darwin[1-6].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
278 darwin*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
279 # Guess yes on OpenBSD >= 3.9.
280 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
281 gl_cv_func_snprintf_truncation_c99="guessing no";;
282 openbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
283 # Guess yes on Solaris >= 2.6.
284 solaris2.[0-5]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
285 solaris*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
286 # Guess yes on AIX >= 4.
287 aix[1-3]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
288 aix*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
289 # Guess yes on HP-UX >= 11.
290 hpux[7-9]* | hpux10*) gl_cv_func_snprintf_truncation_c99="guessing no";;
291 hpux*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
292 # Guess yes on IRIX >= 6.5.
293 irix6.5) gl_cv_func_snprintf_truncation_c99="guessing yes";;
294 # Guess yes on OSF/1 >= 5.
295 osf[3-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
296 osf*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
297 # Guess yes on NetBSD >= 3.
298 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
299 gl_cv_func_snprintf_truncation_c99="guessing no";;
300 netbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
302 beos*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
303 # If we don't know, assume the worst.
304 *) gl_cv_func_snprintf_truncation_c99="guessing no";;
311 dnl Test whether the return value of the snprintf function is the number
312 dnl of bytes (excluding the terminating NUL) that would have been produced
313 dnl if the buffer had been large enough. (ISO C99, POSIX:2001)
314 dnl Result is gl_cv_func_snprintf_retval_c99.
316 AC_DEFUN([gl_SNPRINTF_RETVAL_C99],
318 AC_REQUIRE([AC_PROG_CC])
319 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
320 AC_CACHE_CHECK([whether snprintf returns a byte count as in C99],
321 [gl_cv_func_snprintf_retval_c99],
326 static char buf[100];
329 strcpy (buf, "ABCDEF");
330 if (snprintf (buf, 3, "%d %d", 4567, 89) != 7)
333 }], [gl_cv_func_snprintf_retval_c99=yes], [gl_cv_func_snprintf_retval_c99=no],
337 # Guess yes on glibc systems.
338 *-gnu*) gl_cv_func_snprintf_retval_c99="guessing yes";;
339 # Guess yes on FreeBSD >= 5.
340 freebsd[1-4]*) gl_cv_func_snprintf_retval_c99="guessing no";;
341 freebsd* | kfreebsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
342 # Guess yes on MacOS X >= 10.3.
343 darwin[1-6].*) gl_cv_func_snprintf_retval_c99="guessing no";;
344 darwin*) gl_cv_func_snprintf_retval_c99="guessing yes";;
345 # Guess yes on OpenBSD >= 3.9.
346 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
347 gl_cv_func_snprintf_retval_c99="guessing no";;
348 openbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
349 # Guess yes on Solaris >= 2.6.
350 solaris2.[0-5]*) gl_cv_func_snprintf_retval_c99="guessing no";;
351 solaris*) gl_cv_func_snprintf_retval_c99="guessing yes";;
352 # Guess yes on AIX >= 4.
353 aix[1-3]*) gl_cv_func_snprintf_retval_c99="guessing no";;
354 aix*) gl_cv_func_snprintf_retval_c99="guessing yes";;
355 # Guess yes on NetBSD >= 3.
356 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
357 gl_cv_func_snprintf_retval_c99="guessing no";;
358 netbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
360 beos*) gl_cv_func_snprintf_retval_c99="guessing yes";;
361 # If we don't know, assume the worst.
362 *) gl_cv_func_snprintf_retval_c99="guessing no";;
369 dnl Test whether the snprintf function supports the %n format directive
370 dnl also in truncated portions of the format string. (ISO C99, POSIX:2001)
371 dnl Result is gl_cv_func_snprintf_directive_n.
373 AC_DEFUN([gl_SNPRINTF_DIRECTIVE_N],
375 AC_REQUIRE([AC_PROG_CC])
376 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
377 AC_CACHE_CHECK([whether snprintf fully supports the 'n' directive],
378 [gl_cv_func_snprintf_directive_n],
383 static char buf[100];
387 snprintf (buf, 4, "%d %n", 12345, &count, 33, 44, 55);
391 }], [gl_cv_func_snprintf_directive_n=yes], [gl_cv_func_snprintf_directive_n=no],
395 # Guess yes on glibc systems.
396 *-gnu*) gl_cv_func_snprintf_directive_n="guessing yes";;
397 # Guess yes on FreeBSD >= 5.
398 freebsd[1-4]*) gl_cv_func_snprintf_directive_n="guessing no";;
399 freebsd* | kfreebsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
400 # Guess yes on MacOS X >= 10.3.
401 darwin[1-6].*) gl_cv_func_snprintf_directive_n="guessing no";;
402 darwin*) gl_cv_func_snprintf_directive_n="guessing yes";;
403 # Guess yes on Solaris >= 2.6.
404 solaris2.[0-5]*) gl_cv_func_snprintf_directive_n="guessing no";;
405 solaris*) gl_cv_func_snprintf_directive_n="guessing yes";;
406 # Guess yes on AIX >= 4.
407 aix[1-3]*) gl_cv_func_snprintf_directive_n="guessing no";;
408 aix*) gl_cv_func_snprintf_directive_n="guessing yes";;
409 # Guess yes on IRIX >= 6.5.
410 irix6.5) gl_cv_func_snprintf_directive_n="guessing yes";;
411 # Guess yes on OSF/1 >= 5.
412 osf[3-4]*) gl_cv_func_snprintf_directive_n="guessing no";;
413 osf*) gl_cv_func_snprintf_directive_n="guessing yes";;
414 # Guess yes on NetBSD >= 3.
415 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
416 gl_cv_func_snprintf_directive_n="guessing no";;
417 netbsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
419 beos*) gl_cv_func_snprintf_directive_n="guessing yes";;
420 # If we don't know, assume the worst.
421 *) gl_cv_func_snprintf_directive_n="guessing no";;
428 dnl The results of these tests on various platforms are:
430 dnl 1 = gl_PRINTF_SIZES_C99
431 dnl 2 = gl_PRINTF_DIRECTIVE_A
432 dnl 3 = gl_PRINTF_DIRECTIVE_N
433 dnl 4 = gl_PRINTF_POSITIONS
434 dnl 5 = gl_SNPRINTF_PRESENCE
435 dnl 6 = gl_SNPRINTF_TRUNCATION_C99
436 dnl 7 = gl_SNPRINTF_RETVAL_C99
437 dnl 8 = gl_SNPRINTF_DIRECTIVE_N
439 dnl 1 = checking whether printf supports size specifiers as in C99...
440 dnl 2 = checking whether printf supports the 'a' and 'A' directives...
441 dnl 3 = checking whether printf supports the 'n' directive...
442 dnl 4 = checking whether printf supports POSIX/XSI format strings with positions...
443 dnl 5 = checking for snprintf...
444 dnl 6 = checking whether snprintf truncates the result as in C99...
445 dnl 7 = checking whether snprintf returns a byte count as in C99...
446 dnl 8 = checking whether snprintf fully supports the 'n' directive...
451 dnl glibc 2.5 . . . . . . . .
452 dnl glibc 2.3.6 . # . . . . . .
453 dnl FreeBSD 5.4, 6.1 . ? . . . . . .
454 dnl MacOS X 10.3.9 . # . . . . . .
455 dnl OpenBSD 3.9, 4.0 . # . . . . . ?
456 dnl Cygwin 2007 . # . . . . . ?
457 dnl Cygwin 2006 # # . . . . . ?
458 dnl Solaris 10 . # . . . . . .
459 dnl Solaris 2.6 ... 9 # # . . . . . .
460 dnl Solaris 2.5.1 # # . . # # # #
461 dnl AIX 4.3.2, 5.1 # # . . . . . .
462 dnl HP-UX 11.31 . # . . . . # #
463 dnl HP-UX 10.20, 11.00, 11.11, 11.23 # # . . . . # #
464 dnl IRIX 6.5 # # . . . . # .
465 dnl OSF/1 5.1 # # . . . . # .
466 dnl OSF/1 4.0d # # . . # # # #
467 dnl NetBSD 4.0 . ? . . . . . ?
468 dnl NetBSD 3.0 . # . # . . . .
469 dnl BeOS # # . # . . . .
470 dnl mingw # # . # . # # #