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([AC_CANONICAL_HOST]) dnl for cross-compiles
91 AC_CACHE_CHECK([whether printf supports the 'a' and 'A' directives],
92 [gl_cv_func_printf_directive_a],
100 if (sprintf (buf, "%a %d", 3.1416015625, 33, 44, 55) < 0
101 || strcmp (buf, "0x1.922p+1 33") != 0)
103 if (sprintf (buf, "%A %d", -3.1416015625, 33, 44, 55) < 0
104 || strcmp (buf, "-0X1.922P+1 33") != 0)
107 }], [gl_cv_func_printf_directive_a=yes], [gl_cv_func_printf_directive_a=no],
111 dnl Guess yes on glibc systems.
112 *-gnu*) gl_cv_func_printf_directive_a="guessing yes";;
113 dnl Guess yes on FreeBSD >= 5.
114 freebsd[1-4]*) gl_cv_func_printf_directive_a="guessing no";;
115 freebsd* | kfreebsd*) gl_cv_func_printf_directive_a="guessing yes";;
116 dnl Gusss yes on MacOS X >= 10.3.
117 darwin[1-6].*) gl_cv_func_printf_directive_a="guessing no";;
118 darwin*) gl_cv_func_printf_directive_a="guessing yes";;
119 dnl If we don't know, assume the worst.
120 *) gl_cv_func_printf_directive_a="guessing no";;
127 dnl Test whether the *printf family of functions supports the %n format
128 dnl directive. (ISO C99, POSIX:2001)
129 dnl Result is gl_cv_func_printf_directive_n.
131 AC_DEFUN([gl_PRINTF_DIRECTIVE_N],
133 AC_REQUIRE([AC_PROG_CC])
134 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
135 AC_CACHE_CHECK([whether printf supports the 'n' directive],
136 [gl_cv_func_printf_directive_n],
141 static char buf[100];
145 if (sprintf (buf, "%d %n", 123, &count, 33, 44, 55) < 0
146 || strcmp (buf, "123 ") != 0
150 }], [gl_cv_func_printf_directive_n=yes], [gl_cv_func_printf_directive_n=no],
154 hpux*) gl_cv_func_printf_directive_n="guessing no";;
155 *) gl_cv_func_printf_directive_n="guessing yes";;
162 dnl Test whether the *printf family of functions supports POSIX/XSI format
163 dnl strings with positions. (POSIX:2001)
164 dnl Result is gl_cv_func_printf_positions.
166 AC_DEFUN([gl_PRINTF_POSITIONS],
168 AC_REQUIRE([AC_PROG_CC])
169 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
170 AC_CACHE_CHECK([whether printf supports POSIX/XSI format strings with positions],
171 [gl_cv_func_printf_positions],
176 /* The string "%2$d %1$d", with dollar characters protected from the shell's
177 dollar expansion (possibly an autoconf bug). */
178 static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' };
179 static char buf[100];
182 sprintf (buf, format, 33, 55);
183 return (strcmp (buf, "55 33") != 0);
184 }], [gl_cv_func_printf_positions=yes], [gl_cv_func_printf_positions=no],
188 netbsd*) gl_cv_func_printf_positions="guessing no";;
189 beos*) gl_cv_func_printf_positions="guessing no";;
190 mingw* | pw*) gl_cv_func_printf_positions="guessing no";;
191 *) gl_cv_func_printf_positions="guessing yes";;
198 dnl Test whether the snprintf function exists. (ISO C99, POSIX:2001)
199 dnl Result is ac_cv_func_snprintf.
201 AC_DEFUN([gl_SNPRINTF_PRESENCE],
203 AC_CHECK_FUNCS_ONCE([snprintf])
206 dnl Test whether the string produced by the snprintf function is always NUL
207 dnl terminated. (ISO C99, POSIX:2001)
208 dnl Result is gl_cv_func_snprintf_truncation_c99.
210 AC_DEFUN([gl_SNPRINTF_TRUNCATION_C99],
212 AC_REQUIRE([AC_PROG_CC])
213 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
214 AC_CACHE_CHECK([whether snprintf truncates the result as in C99],
215 [gl_cv_func_snprintf_truncation_c99],
220 static char buf[100];
223 strcpy (buf, "ABCDEF");
224 snprintf (buf, 3, "%d %d", 4567, 89);
225 if (memcmp (buf, "45\0DEF", 6) != 0)
228 }], [gl_cv_func_snprintf_truncation_c99=yes], [gl_cv_func_snprintf_truncation_c99=no],
232 dnl Guess yes on glibc systems.
233 *-gnu*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
234 dnl Guess yes on FreeBSD >= 5.
235 freebsd[1-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
236 freebsd* | kfreebsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
237 dnl Gusss yes on MacOS X >= 10.3.
238 darwin[1-6].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
239 darwin*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
240 dnl Guess yes on Solaris >= 2.6.
241 solaris2.[0-5]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
242 solaris*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
243 dnl Guess yes on AIX >= 4.
244 aix[1-3]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
245 aix*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
246 dnl Guess yes on HP-UX >= 11.
247 hpux[7-9]* | hpux10*) gl_cv_func_snprintf_truncation_c99="guessing no";;
248 hpux*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
249 dnl Guess yes on IRIX >= 6.5.
250 irix6.5) gl_cv_func_snprintf_truncation_c99="guessing yes";;
251 dnl Guess yes on OSF/1 >= 5.
252 osf[3-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
253 osf*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
254 dnl Guess yes on NetBSD >= 3.
255 netbsd[1-2]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
256 netbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
257 dnl Guess yes on BeOS.
258 beos*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
259 dnl If we don't know, assume the worst.
260 *) gl_cv_func_snprintf_truncation_c99="guessing no";;
267 dnl Test whether the return value of the snprintf function is the number
268 dnl of bytes (excluding the terminating NUL) that would have been produced
269 dnl if the buffer had been large enough. (ISO C99, POSIX:2001)
270 dnl Result is gl_cv_func_printf_retval_c99.
272 AC_DEFUN([gl_SNPRINTF_RETVAL_C99],
274 AC_REQUIRE([AC_PROG_CC])
275 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
276 AC_CACHE_CHECK([whether snprintf returns a byte count as in C99],
277 [gl_cv_func_printf_retval_c99],
282 static char buf[100];
285 strcpy (buf, "ABCDEF");
286 if (snprintf (buf, 3, "%d %d", 4567, 89) != 7)
289 }], [gl_cv_func_printf_retval_c99=yes], [gl_cv_func_printf_retval_c99=no],
293 dnl Guess yes on glibc systems.
294 *-gnu*) gl_cv_func_printf_retval_c99="guessing yes";;
295 dnl Guess yes on FreeBSD >= 5.
296 freebsd[1-4]*) gl_cv_func_printf_retval_c99="guessing no";;
297 freebsd* | kfreebsd*) gl_cv_func_printf_retval_c99="guessing yes";;
298 dnl Gusss yes on MacOS X >= 10.3.
299 darwin[1-6].*) gl_cv_func_printf_retval_c99="guessing no";;
300 darwin*) gl_cv_func_printf_retval_c99="guessing yes";;
301 dnl Guess yes on Solaris >= 2.6.
302 solaris2.[0-5]*) gl_cv_func_printf_retval_c99="guessing no";;
303 solaris*) gl_cv_func_printf_retval_c99="guessing yes";;
304 dnl Guess yes on AIX >= 4.
305 aix[1-3]*) gl_cv_func_printf_retval_c99="guessing no";;
306 aix*) gl_cv_func_printf_retval_c99="guessing yes";;
307 dnl Guess yes on NetBSD >= 3.
308 netbsd[1-2]*) gl_cv_func_printf_retval_c99="guessing no";;
309 netbsd*) gl_cv_func_printf_retval_c99="guessing yes";;
310 dnl Guess yes on BeOS.
311 beos*) gl_cv_func_printf_retval_c99="guessing yes";;
312 dnl If we don't know, assume the worst.
313 *) gl_cv_func_printf_retval_c99="guessing no";;
320 dnl The results of these tests on various platforms are:
322 dnl 1 = gl_PRINTF_SIZES_C99
323 dnl 2 = gl_PRINTF_DIRECTIVE_A
324 dnl 3 = gl_PRINTF_DIRECTIVE_N
325 dnl 4 = gl_PRINTF_POSITIONS
326 dnl 5 = gl_SNPRINTF_PRESENCE
327 dnl 6 = gl_SNPRINTF_TRUNCATION_C99
328 dnl 7 = gl_SNPRINTF_RETVAL_C99
330 dnl 1 = checking whether printf supports size specifiers as in C99...
331 dnl 2 = checking whether printf supports the 'a' and 'A' directives...
332 dnl 3 = checking whether printf supports the 'n' directive...
333 dnl 4 = checking whether printf supports POSIX/XSI format strings with positions...
334 dnl 5 = checking for snprintf...
335 dnl 6 = checking whether snprintf truncates the result as in C99...
336 dnl 7 = checking whether snprintf returns a byte count as in C99...
341 dnl glibc 2.3.6 . . . . . . .
342 dnl FreeBSD 5.4, 6.1 . . . . . . .
343 dnl MacOS X 10.3.9 . . . . . . .
344 dnl Cygwin 2007 . # . . . . .
345 dnl Solaris 10 . # . . . . .
346 dnl Solaris 2.6 ... 9 # # . . . . .
347 dnl Solaris 2.5.1 # # . . # # #
348 dnl AIX 4.3.2, 5.1 # # . . . . .
349 dnl HP-UX 11.31 . # . . . . #
350 dnl HP-UX 11.00, 11.11, 11.23 # # . . . . #
351 dnl HP-UX 10.20 # # # ? . ? #
352 dnl IRIX 6.5 # # . . . . #
353 dnl OSF/1 5.1 # # . . . . #
354 dnl OSF/1 4.0d # # . . # # #
355 dnl NetBSD 3.0 . # . # . . .
356 dnl BeOS # # . # . . .
357 dnl mingw # # . # . # #