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 Gusss 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 Solaris >= 2.10.
69 solaris2.[0-9]*) gl_cv_func_printf_sizes_c99="guessing no";;
70 solaris*) gl_cv_func_printf_sizes_c99="guessing yes";;
71 dnl Guess yes on NetBSD >= 3.
72 netbsd[1-2]*) gl_cv_func_printf_sizes_c99="guessing no";;
73 netbsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
74 dnl If we don't know, assume the worst.
75 *) gl_cv_func_printf_sizes_c99="guessing no";;
82 dnl Test whether the *printf family of functions supports the 'a' and 'A'
83 dnl conversion specifier for hexadecimal output of floating-point numbers.
84 dnl (ISO C99, POSIX:2001)
85 dnl Result is gl_cv_func_printf_directive_a.
87 AC_DEFUN([gl_PRINTF_DIRECTIVE_A],
89 AC_REQUIRE([AC_PROG_CC])
90 AC_REQUIRE([gt_TYPE_LONGDOUBLE])
91 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
92 AC_CACHE_CHECK([whether printf supports the 'a' and 'A' directives],
93 [gl_cv_func_printf_directive_a],
101 if (sprintf (buf, "%a %d", 3.1416015625, 33, 44, 55) < 0
102 || (strcmp (buf, "0x1.922p+1 33") != 0
103 && strcmp (buf, "0x3.244p+0 33") != 0
104 && strcmp (buf, "0x6.488p-1 33") != 0
105 && strcmp (buf, "0xc.91p-2 33") != 0))
107 if (sprintf (buf, "%A %d", -3.1416015625, 33, 44, 55) < 0
108 || (strcmp (buf, "-0X1.922P+1 33") != 0
109 && strcmp (buf, "-0X3.244P+0 33") != 0
110 && strcmp (buf, "-0X6.488P-1 33") != 0
111 && strcmp (buf, "-0XC.91P-2 33") != 0))
113 /* This catches a MacOS X 10.3.9 (Darwin 7.9) bug. */
114 if (sprintf (buf, "%.1a", 1.999) < 0
115 || (strcmp (buf, "0x1.0p+1") != 0
116 && strcmp (buf, "0x2.0p+0") != 0
117 && strcmp (buf, "0x4.0p-1") != 0
118 && strcmp (buf, "0x8.0p-2") != 0))
121 /* This catches the same MacOS X 10.3.9 (Darwin 7.9) bug and also a
122 glibc 2.4 bug <http://sourceware.org/bugzilla/show_bug.cgi?id=2908>. */
123 if (sprintf (buf, "%.1La", 1.999L) < 0
124 || (strcmp (buf, "0x1.0p+1") != 0
125 && strcmp (buf, "0x2.0p+0") != 0
126 && strcmp (buf, "0x4.0p-1") != 0
127 && strcmp (buf, "0x8.0p-2") != 0))
131 }], [gl_cv_func_printf_directive_a=yes], [gl_cv_func_printf_directive_a=no],
134 dnl Guess yes on glibc >= 2.5 systems.
136 AC_EGREP_CPP([BZ2908], [
137 #include <features.h>
138 #ifdef __GNU_LIBRARY__
139 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 5) || (__GLIBC__ > 2)
144 [gl_cv_func_printf_directive_a="guessing yes"],
145 [gl_cv_func_printf_directive_a="guessing no"])
148 dnl Guess yes on FreeBSD >= 5.
149 freebsd[1-4]*) gl_cv_func_printf_directive_a="guessing no";;
150 freebsd* | kfreebsd*) gl_cv_func_printf_directive_a="guessing yes";;
151 dnl If we don't know, assume the worst.
152 *) gl_cv_func_printf_directive_a="guessing no";;
159 dnl Test whether the *printf family of functions supports the %n format
160 dnl directive. (ISO C99, POSIX:2001)
161 dnl Result is gl_cv_func_printf_directive_n.
163 AC_DEFUN([gl_PRINTF_DIRECTIVE_N],
165 AC_REQUIRE([AC_PROG_CC])
166 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
167 AC_CACHE_CHECK([whether printf supports the 'n' directive],
168 [gl_cv_func_printf_directive_n],
173 static char buf[100];
177 if (sprintf (buf, "%d %n", 123, &count, 33, 44, 55) < 0
178 || strcmp (buf, "123 ") != 0
182 }], [gl_cv_func_printf_directive_n=yes], [gl_cv_func_printf_directive_n=no],
186 hpux*) gl_cv_func_printf_directive_n="guessing 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*) gl_cv_func_printf_positions="guessing no";;
221 beos*) gl_cv_func_printf_positions="guessing no";;
222 mingw* | pw*) gl_cv_func_printf_positions="guessing no";;
223 *) gl_cv_func_printf_positions="guessing yes";;
230 dnl Test whether the snprintf function exists. (ISO C99, POSIX:2001)
231 dnl Result is ac_cv_func_snprintf.
233 AC_DEFUN([gl_SNPRINTF_PRESENCE],
235 AC_CHECK_FUNCS_ONCE([snprintf])
238 dnl Test whether the string produced by the snprintf function is always NUL
239 dnl terminated. (ISO C99, POSIX:2001)
240 dnl Result is gl_cv_func_snprintf_truncation_c99.
242 AC_DEFUN([gl_SNPRINTF_TRUNCATION_C99],
244 AC_REQUIRE([AC_PROG_CC])
245 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
246 AC_CACHE_CHECK([whether snprintf truncates the result as in C99],
247 [gl_cv_func_snprintf_truncation_c99],
252 static char buf[100];
255 strcpy (buf, "ABCDEF");
256 snprintf (buf, 3, "%d %d", 4567, 89);
257 if (memcmp (buf, "45\0DEF", 6) != 0)
260 }], [gl_cv_func_snprintf_truncation_c99=yes], [gl_cv_func_snprintf_truncation_c99=no],
264 dnl Guess yes on glibc systems.
265 *-gnu*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
266 dnl Guess yes on FreeBSD >= 5.
267 freebsd[1-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
268 freebsd* | kfreebsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
269 dnl Gusss yes on MacOS X >= 10.3.
270 darwin[1-6].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
271 darwin*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
272 dnl Guess yes on Solaris >= 2.6.
273 solaris2.[0-5]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
274 solaris*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
275 dnl Guess yes on AIX >= 4.
276 aix[1-3]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
277 aix*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
278 dnl Guess yes on HP-UX >= 11.
279 hpux[7-9]* | hpux10*) gl_cv_func_snprintf_truncation_c99="guessing no";;
280 hpux*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
281 dnl Guess yes on IRIX >= 6.5.
282 irix6.5) gl_cv_func_snprintf_truncation_c99="guessing yes";;
283 dnl Guess yes on OSF/1 >= 5.
284 osf[3-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
285 osf*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
286 dnl Guess yes on NetBSD >= 3.
287 netbsd[1-2]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
288 netbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
289 dnl Guess yes on BeOS.
290 beos*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
291 dnl If we don't know, assume the worst.
292 *) gl_cv_func_snprintf_truncation_c99="guessing no";;
299 dnl Test whether the return value of the snprintf function is the number
300 dnl of bytes (excluding the terminating NUL) that would have been produced
301 dnl if the buffer had been large enough. (ISO C99, POSIX:2001)
302 dnl Result is gl_cv_func_printf_retval_c99.
304 AC_DEFUN([gl_SNPRINTF_RETVAL_C99],
306 AC_REQUIRE([AC_PROG_CC])
307 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
308 AC_CACHE_CHECK([whether snprintf returns a byte count as in C99],
309 [gl_cv_func_printf_retval_c99],
314 static char buf[100];
317 strcpy (buf, "ABCDEF");
318 if (snprintf (buf, 3, "%d %d", 4567, 89) != 7)
321 }], [gl_cv_func_printf_retval_c99=yes], [gl_cv_func_printf_retval_c99=no],
325 dnl Guess yes on glibc systems.
326 *-gnu*) gl_cv_func_printf_retval_c99="guessing yes";;
327 dnl Guess yes on FreeBSD >= 5.
328 freebsd[1-4]*) gl_cv_func_printf_retval_c99="guessing no";;
329 freebsd* | kfreebsd*) gl_cv_func_printf_retval_c99="guessing yes";;
330 dnl Gusss yes on MacOS X >= 10.3.
331 darwin[1-6].*) gl_cv_func_printf_retval_c99="guessing no";;
332 darwin*) gl_cv_func_printf_retval_c99="guessing yes";;
333 dnl Guess yes on Solaris >= 2.6.
334 solaris2.[0-5]*) gl_cv_func_printf_retval_c99="guessing no";;
335 solaris*) gl_cv_func_printf_retval_c99="guessing yes";;
336 dnl Guess yes on AIX >= 4.
337 aix[1-3]*) gl_cv_func_printf_retval_c99="guessing no";;
338 aix*) gl_cv_func_printf_retval_c99="guessing yes";;
339 dnl Guess yes on NetBSD >= 3.
340 netbsd[1-2]*) gl_cv_func_printf_retval_c99="guessing no";;
341 netbsd*) gl_cv_func_printf_retval_c99="guessing yes";;
342 dnl Guess yes on BeOS.
343 beos*) gl_cv_func_printf_retval_c99="guessing yes";;
344 dnl If we don't know, assume the worst.
345 *) gl_cv_func_printf_retval_c99="guessing no";;
352 dnl The results of these tests on various platforms are:
354 dnl 1 = gl_PRINTF_SIZES_C99
355 dnl 2 = gl_PRINTF_DIRECTIVE_A
356 dnl 3 = gl_PRINTF_DIRECTIVE_N
357 dnl 4 = gl_PRINTF_POSITIONS
358 dnl 5 = gl_SNPRINTF_PRESENCE
359 dnl 6 = gl_SNPRINTF_TRUNCATION_C99
360 dnl 7 = gl_SNPRINTF_RETVAL_C99
362 dnl 1 = checking whether printf supports size specifiers as in C99...
363 dnl 2 = checking whether printf supports the 'a' and 'A' directives...
364 dnl 3 = checking whether printf supports the 'n' directive...
365 dnl 4 = checking whether printf supports POSIX/XSI format strings with positions...
366 dnl 5 = checking for snprintf...
367 dnl 6 = checking whether snprintf truncates the result as in C99...
368 dnl 7 = checking whether snprintf returns a byte count as in C99...
373 dnl glibc 2.3.6 . # . . . . .
374 dnl FreeBSD 5.4, 6.1 . . . . . . .
375 dnl MacOS X 10.3.9 . # . . . . .
376 dnl Cygwin 2007 . # . . . . .
377 dnl Cygwin 2006 # # . . . . .
378 dnl Solaris 10 . # . . . . .
379 dnl Solaris 2.6 ... 9 # # . . . . .
380 dnl Solaris 2.5.1 # # . . # # #
381 dnl AIX 4.3.2, 5.1 # # . . . . .
382 dnl HP-UX 11.31 . # . . . . #
383 dnl HP-UX 11.00, 11.11, 11.23 # # . . . . #
384 dnl HP-UX 10.20 # # # ? . ? #
385 dnl IRIX 6.5 # # . . . . #
386 dnl OSF/1 5.1 # # . . . . #
387 dnl OSF/1 4.0d # # . . # # #
388 dnl NetBSD 3.0 . # . # . . .
389 dnl BeOS # # . # . . .
390 dnl mingw # # . # . # #