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]*) gl_cv_func_printf_sizes_c99="guessing no";;
77 netbsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
78 dnl If we don't know, assume the worst.
79 *) gl_cv_func_printf_sizes_c99="guessing no";;
86 dnl Test whether the *printf family of functions supports the 'a' and 'A'
87 dnl conversion specifier for hexadecimal output of floating-point numbers.
88 dnl (ISO C99, POSIX:2001)
89 dnl Result is gl_cv_func_printf_directive_a.
91 AC_DEFUN([gl_PRINTF_DIRECTIVE_A],
93 AC_REQUIRE([AC_PROG_CC])
94 AC_REQUIRE([gt_TYPE_LONGDOUBLE])
95 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
96 AC_CACHE_CHECK([whether printf supports the 'a' and 'A' directives],
97 [gl_cv_func_printf_directive_a],
102 static char buf[100];
105 if (sprintf (buf, "%a %d", 3.1416015625, 33, 44, 55) < 0
106 || (strcmp (buf, "0x1.922p+1 33") != 0
107 && strcmp (buf, "0x3.244p+0 33") != 0
108 && strcmp (buf, "0x6.488p-1 33") != 0
109 && strcmp (buf, "0xc.91p-2 33") != 0))
111 if (sprintf (buf, "%A %d", -3.1416015625, 33, 44, 55) < 0
112 || (strcmp (buf, "-0X1.922P+1 33") != 0
113 && strcmp (buf, "-0X3.244P+0 33") != 0
114 && strcmp (buf, "-0X6.488P-1 33") != 0
115 && strcmp (buf, "-0XC.91P-2 33") != 0))
117 /* This catches a MacOS X 10.3.9 (Darwin 7.9) bug. */
118 if (sprintf (buf, "%.1a", 1.999) < 0
119 || (strcmp (buf, "0x1.0p+1") != 0
120 && strcmp (buf, "0x2.0p+0") != 0
121 && strcmp (buf, "0x4.0p-1") != 0
122 && strcmp (buf, "0x8.0p-2") != 0))
125 /* This catches the same MacOS X 10.3.9 (Darwin 7.9) bug and also a
126 glibc 2.4 bug <http://sourceware.org/bugzilla/show_bug.cgi?id=2908>. */
127 if (sprintf (buf, "%.1La", 1.999L) < 0
128 || (strcmp (buf, "0x1.0p+1") != 0
129 && strcmp (buf, "0x2.0p+0") != 0
130 && strcmp (buf, "0x4.0p-1") != 0
131 && strcmp (buf, "0x8.0p-2") != 0))
135 }], [gl_cv_func_printf_directive_a=yes], [gl_cv_func_printf_directive_a=no],
138 dnl Guess yes on glibc >= 2.5 systems.
140 AC_EGREP_CPP([BZ2908], [
141 #include <features.h>
142 #ifdef __GNU_LIBRARY__
143 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 5) || (__GLIBC__ > 2)
148 [gl_cv_func_printf_directive_a="guessing yes"],
149 [gl_cv_func_printf_directive_a="guessing no"])
152 dnl Guess yes on FreeBSD >= 5.
153 freebsd[1-4]*) gl_cv_func_printf_directive_a="guessing no";;
154 freebsd* | kfreebsd*) gl_cv_func_printf_directive_a="guessing yes";;
155 dnl If we don't know, assume the worst.
156 *) gl_cv_func_printf_directive_a="guessing no";;
163 dnl Test whether the *printf family of functions supports the %n format
164 dnl directive. (ISO C99, POSIX:2001)
165 dnl Result is gl_cv_func_printf_directive_n.
167 AC_DEFUN([gl_PRINTF_DIRECTIVE_N],
169 AC_REQUIRE([AC_PROG_CC])
170 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
171 AC_CACHE_CHECK([whether printf supports the 'n' directive],
172 [gl_cv_func_printf_directive_n],
177 static char buf[100];
181 if (sprintf (buf, "%d %n", 123, &count, 33, 44, 55) < 0
182 || strcmp (buf, "123 ") != 0
186 }], [gl_cv_func_printf_directive_n=yes], [gl_cv_func_printf_directive_n=no],
190 hpux*) gl_cv_func_printf_directive_n="guessing no";;
191 *) gl_cv_func_printf_directive_n="guessing yes";;
198 dnl Test whether the *printf family of functions supports POSIX/XSI format
199 dnl strings with positions. (POSIX:2001)
200 dnl Result is gl_cv_func_printf_positions.
202 AC_DEFUN([gl_PRINTF_POSITIONS],
204 AC_REQUIRE([AC_PROG_CC])
205 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
206 AC_CACHE_CHECK([whether printf supports POSIX/XSI format strings with positions],
207 [gl_cv_func_printf_positions],
212 /* The string "%2$d %1$d", with dollar characters protected from the shell's
213 dollar expansion (possibly an autoconf bug). */
214 static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' };
215 static char buf[100];
218 sprintf (buf, format, 33, 55);
219 return (strcmp (buf, "55 33") != 0);
220 }], [gl_cv_func_printf_positions=yes], [gl_cv_func_printf_positions=no],
224 netbsd*) gl_cv_func_printf_positions="guessing no";;
225 beos*) gl_cv_func_printf_positions="guessing no";;
226 mingw* | pw*) gl_cv_func_printf_positions="guessing no";;
227 *) gl_cv_func_printf_positions="guessing yes";;
234 dnl Test whether the snprintf function exists. (ISO C99, POSIX:2001)
235 dnl Result is ac_cv_func_snprintf.
237 AC_DEFUN([gl_SNPRINTF_PRESENCE],
239 AC_CHECK_FUNCS_ONCE([snprintf])
242 dnl Test whether the string produced by the snprintf function is always NUL
243 dnl terminated. (ISO C99, POSIX:2001)
244 dnl Result is gl_cv_func_snprintf_truncation_c99.
246 AC_DEFUN([gl_SNPRINTF_TRUNCATION_C99],
248 AC_REQUIRE([AC_PROG_CC])
249 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
250 AC_CACHE_CHECK([whether snprintf truncates the result as in C99],
251 [gl_cv_func_snprintf_truncation_c99],
256 static char buf[100];
259 strcpy (buf, "ABCDEF");
260 snprintf (buf, 3, "%d %d", 4567, 89);
261 if (memcmp (buf, "45\0DEF", 6) != 0)
264 }], [gl_cv_func_snprintf_truncation_c99=yes], [gl_cv_func_snprintf_truncation_c99=no],
268 dnl Guess yes on glibc systems.
269 *-gnu*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
270 dnl Guess yes on FreeBSD >= 5.
271 freebsd[1-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
272 freebsd* | kfreebsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
273 dnl Guess yes on MacOS X >= 10.3.
274 darwin[1-6].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
275 darwin*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
276 dnl Guess yes on OpenBSD >= 3.9.
277 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
278 gl_cv_func_snprintf_truncation_c99="guessing no";;
279 openbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
280 dnl Guess yes on Solaris >= 2.6.
281 solaris2.[0-5]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
282 solaris*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
283 dnl Guess yes on AIX >= 4.
284 aix[1-3]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
285 aix*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
286 dnl Guess yes on HP-UX >= 11.
287 hpux[7-9]* | hpux10*) gl_cv_func_snprintf_truncation_c99="guessing no";;
288 hpux*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
289 dnl Guess yes on IRIX >= 6.5.
290 irix6.5) gl_cv_func_snprintf_truncation_c99="guessing yes";;
291 dnl Guess yes on OSF/1 >= 5.
292 osf[3-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
293 osf*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
294 dnl Guess yes on NetBSD >= 3.
295 netbsd[1-2]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
296 netbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
297 dnl Guess yes on BeOS.
298 beos*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
299 dnl If we don't know, assume the worst.
300 *) gl_cv_func_snprintf_truncation_c99="guessing no";;
307 dnl Test whether the return value of the snprintf function is the number
308 dnl of bytes (excluding the terminating NUL) that would have been produced
309 dnl if the buffer had been large enough. (ISO C99, POSIX:2001)
310 dnl Result is gl_cv_func_printf_retval_c99.
312 AC_DEFUN([gl_SNPRINTF_RETVAL_C99],
314 AC_REQUIRE([AC_PROG_CC])
315 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
316 AC_CACHE_CHECK([whether snprintf returns a byte count as in C99],
317 [gl_cv_func_printf_retval_c99],
322 static char buf[100];
325 strcpy (buf, "ABCDEF");
326 if (snprintf (buf, 3, "%d %d", 4567, 89) != 7)
329 }], [gl_cv_func_printf_retval_c99=yes], [gl_cv_func_printf_retval_c99=no],
333 dnl Guess yes on glibc systems.
334 *-gnu*) gl_cv_func_printf_retval_c99="guessing yes";;
335 dnl Guess yes on FreeBSD >= 5.
336 freebsd[1-4]*) gl_cv_func_printf_retval_c99="guessing no";;
337 freebsd* | kfreebsd*) gl_cv_func_printf_retval_c99="guessing yes";;
338 dnl Guess yes on MacOS X >= 10.3.
339 darwin[1-6].*) gl_cv_func_printf_retval_c99="guessing no";;
340 darwin*) gl_cv_func_printf_retval_c99="guessing yes";;
341 dnl Guess yes on OpenBSD >= 3.9.
342 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
343 gl_cv_func_printf_retval_c99="guessing no";;
344 openbsd*) gl_cv_func_printf_retval_c99="guessing yes";;
345 dnl Guess yes on Solaris >= 2.6.
346 solaris2.[0-5]*) gl_cv_func_printf_retval_c99="guessing no";;
347 solaris*) gl_cv_func_printf_retval_c99="guessing yes";;
348 dnl Guess yes on AIX >= 4.
349 aix[1-3]*) gl_cv_func_printf_retval_c99="guessing no";;
350 aix*) gl_cv_func_printf_retval_c99="guessing yes";;
351 dnl Guess yes on NetBSD >= 3.
352 netbsd[1-2]*) gl_cv_func_printf_retval_c99="guessing no";;
353 netbsd*) gl_cv_func_printf_retval_c99="guessing yes";;
354 dnl Guess yes on BeOS.
355 beos*) gl_cv_func_printf_retval_c99="guessing yes";;
356 dnl If we don't know, assume the worst.
357 *) gl_cv_func_printf_retval_c99="guessing no";;
364 dnl The results of these tests on various platforms are:
366 dnl 1 = gl_PRINTF_SIZES_C99
367 dnl 2 = gl_PRINTF_DIRECTIVE_A
368 dnl 3 = gl_PRINTF_DIRECTIVE_N
369 dnl 4 = gl_PRINTF_POSITIONS
370 dnl 5 = gl_SNPRINTF_PRESENCE
371 dnl 6 = gl_SNPRINTF_TRUNCATION_C99
372 dnl 7 = gl_SNPRINTF_RETVAL_C99
374 dnl 1 = checking whether printf supports size specifiers as in C99...
375 dnl 2 = checking whether printf supports the 'a' and 'A' directives...
376 dnl 3 = checking whether printf supports the 'n' directive...
377 dnl 4 = checking whether printf supports POSIX/XSI format strings with positions...
378 dnl 5 = checking for snprintf...
379 dnl 6 = checking whether snprintf truncates the result as in C99...
380 dnl 7 = checking whether snprintf returns a byte count as in C99...
385 dnl glibc 2.3.6 . # . . . . .
386 dnl FreeBSD 5.4, 6.1 . . . . . . .
387 dnl MacOS X 10.3.9 . # . . . . .
388 dnl OpenBSD 3.9 . # . . . . .
389 dnl Cygwin 2007 . # . . . . .
390 dnl Cygwin 2006 # # . . . . .
391 dnl Solaris 10 . # . . . . .
392 dnl Solaris 2.6 ... 9 # # . . . . .
393 dnl Solaris 2.5.1 # # . . # # #
394 dnl AIX 4.3.2, 5.1 # # . . . . .
395 dnl HP-UX 11.31 . # . . . . #
396 dnl HP-UX 11.00, 11.11, 11.23 # # . . . . #
397 dnl HP-UX 10.20 # # # ? . ? #
398 dnl IRIX 6.5 # # . . . . #
399 dnl OSF/1 5.1 # # . . . . #
400 dnl OSF/1 4.0d # # . . # # #
401 dnl NetBSD 3.0 . # . # . . .
402 dnl BeOS # # . # . . .
403 dnl mingw # # . # . # #