Debian Codegraph @

m4/printf.m4

raw
1 # printf.m4 serial 64
2 dnl Copyright (C) 2003, 2007-2020 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.
6
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.
10
11 AC_DEFUN([gl_PRINTF_SIZES_C99],
12 [
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],
19 [
20 AC_RUN_IFELSE(
21 [AC_LANG_SOURCE([[
22 #include <stddef.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include <sys/types.h>
26 #if HAVE_STDINT_H_WITH_UINTMAX
27 # include <stdint.h>
28 #endif
29 #if HAVE_INTTYPES_H_WITH_UINTMAX
30 # include <inttypes.h>
31 #endif
32 static char buf[100];
33 int main ()
34 {
35 int result = 0;
36 #if HAVE_STDINT_H_WITH_UINTMAX || HAVE_INTTYPES_H_WITH_UINTMAX
37 buf[0] = '\0';
38 if (sprintf (buf, "%ju %d", (uintmax_t) 12345671, 33, 44, 55) < 0
39 || strcmp (buf, "12345671 33") != 0)
40 result |= 1;
41 #else
42 result |= 1;
43 #endif
44 buf[0] = '\0';
45 if (sprintf (buf, "%zu %d", (size_t) 12345672, 33, 44, 55) < 0
46 || strcmp (buf, "12345672 33") != 0)
47 result |= 2;
48 buf[0] = '\0';
49 if (sprintf (buf, "%tu %d", (ptrdiff_t) 12345673, 33, 44, 55) < 0
50 || strcmp (buf, "12345673 33") != 0)
51 result |= 4;
52 buf[0] = '\0';
53 if (sprintf (buf, "%Lg %d", (long double) 1.5, 33, 44, 55) < 0
54 || strcmp (buf, "1.5 33") != 0)
55 result |= 8;
56 return result;
57 }]])],
58 [gl_cv_func_printf_sizes_c99=yes],
59 [gl_cv_func_printf_sizes_c99=no],
60 [
61 case "$host_os" in
62 changequote(,)dnl
63 # Guess yes on glibc systems.
64 *-gnu* | gnu*) gl_cv_func_printf_sizes_c99="guessing yes";;
65 # Guess yes on musl systems.
66 *-musl*) gl_cv_func_printf_sizes_c99="guessing yes";;
67 # Guess yes on FreeBSD >= 5.
68 freebsd[1-4].*) gl_cv_func_printf_sizes_c99="guessing no";;
69 freebsd* | kfreebsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
70 # Guess yes on Mac OS X >= 10.3.
71 darwin[1-6].*) gl_cv_func_printf_sizes_c99="guessing no";;
72 darwin*) gl_cv_func_printf_sizes_c99="guessing yes";;
73 # Guess yes on OpenBSD >= 3.9.
74 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
75 gl_cv_func_printf_sizes_c99="guessing no";;
76 openbsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
77 # Guess yes on Solaris >= 2.10.
78 solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";;
79 solaris*) gl_cv_func_printf_sizes_c99="guessing no";;
80 # Guess yes on NetBSD >= 3.
81 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
82 gl_cv_func_printf_sizes_c99="guessing no";;
83 netbsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
84 # Guess yes on Android.
85 linux*-android*) gl_cv_func_printf_sizes_c99="guessing yes";;
86 changequote([,])dnl
87 # Guess yes on MSVC, no on mingw.
88 mingw*) AC_EGREP_CPP([Known], [
89 #ifdef _MSC_VER
90 Known
91 #endif
92 ],
93 [gl_cv_func_printf_sizes_c99="guessing yes"],
94 [gl_cv_func_printf_sizes_c99="guessing no"])
95 ;;
96 # If we don't know, obey --enable-cross-guesses.
97 *) gl_cv_func_printf_sizes_c99="$gl_cross_guess_normal";;
98 esac
99 ])
100 ])
101 ])
102
103 dnl Test whether the *printf family of functions supports 'long double'
104 dnl arguments together with the 'L' size specifier. (ISO C99, POSIX:2001)
105 dnl Result is gl_cv_func_printf_long_double.
106
107 AC_DEFUN([gl_PRINTF_LONG_DOUBLE],
108 [
109 AC_REQUIRE([AC_PROG_CC])
110 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
111 AC_CACHE_CHECK([whether printf supports 'long double' arguments],
112 [gl_cv_func_printf_long_double],
113 [
114 AC_RUN_IFELSE(
115 [AC_LANG_SOURCE([[
116 #include <stdio.h>
117 #include <string.h>
118 static char buf[10000];
119 int main ()
120 {
121 int result = 0;
122 buf[0] = '\0';
123 if (sprintf (buf, "%Lf %d", 1.75L, 33, 44, 55) < 0
124 || strcmp (buf, "1.750000 33") != 0)
125 result |= 1;
126 buf[0] = '\0';
127 if (sprintf (buf, "%Le %d", 1.75L, 33, 44, 55) < 0
128 || strcmp (buf, "1.750000e+00 33") != 0)
129 result |= 2;
130 buf[0] = '\0';
131 if (sprintf (buf, "%Lg %d", 1.75L, 33, 44, 55) < 0
132 || strcmp (buf, "1.75 33") != 0)
133 result |= 4;
134 return result;
135 }]])],
136 [gl_cv_func_printf_long_double=yes],
137 [gl_cv_func_printf_long_double=no],
138 [case "$host_os" in
139 # Guess no on BeOS.
140 beos*) gl_cv_func_printf_long_double="guessing no";;
141 # Guess yes on Android.
142 linux*-android*) gl_cv_func_printf_long_double="guessing yes";;
143 # Guess yes on MSVC, no on mingw.
144 mingw*) AC_EGREP_CPP([Known], [
145 #ifdef _MSC_VER
146 Known
147 #endif
148 ],
149 [gl_cv_func_printf_long_double="guessing yes"],
150 [gl_cv_func_printf_long_double="guessing no"])
151 ;;
152 *) gl_cv_func_printf_long_double="guessing yes";;
153 esac
154 ])
155 ])
156 ])
157
158 dnl Test whether the *printf family of functions supports infinite and NaN
159 dnl 'double' arguments and negative zero arguments in the %f, %e, %g
160 dnl directives. (ISO C99, POSIX:2001)
161 dnl Result is gl_cv_func_printf_infinite.
162
163 AC_DEFUN([gl_PRINTF_INFINITE],
164 [
165 AC_REQUIRE([AC_PROG_CC])
166 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
167 AC_CACHE_CHECK([whether printf supports infinite 'double' arguments],
168 [gl_cv_func_printf_infinite],
169 [
170 AC_RUN_IFELSE(
171 [AC_LANG_SOURCE([[
172 #include <stdio.h>
173 #include <string.h>
174 static int
175 strisnan (const char *string, size_t start_index, size_t end_index)
176 {
177 if (start_index < end_index)
178 {
179 if (string[start_index] == '-')
180 start_index++;
181 if (start_index + 3 <= end_index
182 && memcmp (string + start_index, "nan", 3) == 0)
183 {
184 start_index += 3;
185 if (start_index == end_index
186 || (string[start_index] == '(' && string[end_index - 1] == ')'))
187 return 1;
188 }
189 }
190 return 0;
191 }
192 static int
193 have_minus_zero ()
194 {
195 static double plus_zero = 0.0;
196 double minus_zero = - plus_zero;
197 return memcmp (&plus_zero, &minus_zero, sizeof (double)) != 0;
198 }
199 static char buf[10000];
200 static double zero = 0.0;
201 int main ()
202 {
203 int result = 0;
204 if (sprintf (buf, "%f", 1.0 / zero) < 0
205 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
206 result |= 1;
207 if (sprintf (buf, "%f", -1.0 / zero) < 0
208 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
209 result |= 1;
210 if (sprintf (buf, "%f", zero / zero) < 0
211 || !strisnan (buf, 0, strlen (buf)))
212 result |= 2;
213 if (sprintf (buf, "%e", 1.0 / zero) < 0
214 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
215 result |= 4;
216 if (sprintf (buf, "%e", -1.0 / zero) < 0
217 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
218 result |= 4;
219 if (sprintf (buf, "%e", zero / zero) < 0
220 || !strisnan (buf, 0, strlen (buf)))
221 result |= 8;
222 if (sprintf (buf, "%g", 1.0 / zero) < 0
223 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
224 result |= 16;
225 if (sprintf (buf, "%g", -1.0 / zero) < 0
226 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
227 result |= 16;
228 if (sprintf (buf, "%g", zero / zero) < 0
229 || !strisnan (buf, 0, strlen (buf)))
230 result |= 32;
231 /* This test fails on HP-UX 10.20. */
232 if (have_minus_zero ())
233 if (sprintf (buf, "%g", - zero) < 0
234 || strcmp (buf, "-0") != 0)
235 result |= 64;
236 return result;
237 }]])],
238 [gl_cv_func_printf_infinite=yes],
239 [gl_cv_func_printf_infinite=no],
240 [
241 case "$host_os" in
242 changequote(,)dnl
243 # Guess yes on glibc systems.
244 *-gnu* | gnu*) gl_cv_func_printf_infinite="guessing yes";;
245 # Guess yes on musl systems.
246 *-musl*) gl_cv_func_printf_infinite="guessing yes";;
247 # Guess yes on FreeBSD >= 6.
248 freebsd[1-5].*) gl_cv_func_printf_infinite="guessing no";;
249 freebsd* | kfreebsd*) gl_cv_func_printf_infinite="guessing yes";;
250 # Guess yes on Mac OS X >= 10.3.
251 darwin[1-6].*) gl_cv_func_printf_infinite="guessing no";;
252 darwin*) gl_cv_func_printf_infinite="guessing yes";;
253 # Guess yes on HP-UX >= 11.
254 hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite="guessing no";;
255 hpux*) gl_cv_func_printf_infinite="guessing yes";;
256 # Guess yes on NetBSD >= 3.
257 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
258 gl_cv_func_printf_infinite="guessing no";;
259 netbsd*) gl_cv_func_printf_infinite="guessing yes";;
260 # Guess yes on BeOS.
261 beos*) gl_cv_func_printf_infinite="guessing yes";;
262 # Guess no on Android.
263 linux*-android*) gl_cv_func_printf_infinite="guessing no";;
264 changequote([,])dnl
265 # Guess yes on MSVC, no on mingw.
266 mingw*) AC_EGREP_CPP([Known], [
267 #ifdef _MSC_VER
268 Known
269 #endif
270 ],
271 [gl_cv_func_printf_infinite="guessing yes"],
272 [gl_cv_func_printf_infinite="guessing no"])
273 ;;
274 # If we don't know, obey --enable-cross-guesses.
275 *) gl_cv_func_printf_infinite="$gl_cross_guess_normal";;
276 esac
277 ])
278 ])
279 ])
280
281 dnl Test whether the *printf family of functions supports infinite and NaN
282 dnl 'long double' arguments in the %f, %e, %g directives. (ISO C99, POSIX:2001)
283 dnl Result is gl_cv_func_printf_infinite_long_double.
284
285 AC_DEFUN([gl_PRINTF_INFINITE_LONG_DOUBLE],
286 [
287 AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
288 AC_REQUIRE([AC_PROG_CC])
289 AC_REQUIRE([gl_BIGENDIAN])
290 AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
291 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
292 dnl The user can set or unset the variable gl_printf_safe to indicate
293 dnl that he wishes a safe handling of non-IEEE-754 'long double' values.
294 if test -n "$gl_printf_safe"; then
295 AC_DEFINE([CHECK_PRINTF_SAFE], [1],
296 [Define if you wish *printf() functions that have a safe handling of
297 non-IEEE-754 'long double' values.])
298 fi
299 case "$gl_cv_func_printf_long_double" in
300 *yes)
301 AC_CACHE_CHECK([whether printf supports infinite 'long double' arguments],
302 [gl_cv_func_printf_infinite_long_double],
303 [
304 AC_RUN_IFELSE(
305 [AC_LANG_SOURCE([[
306 ]GL_NOCRASH[
307 #include <float.h>
308 #include <stdio.h>
309 #include <string.h>
310 static int
311 strisnan (const char *string, size_t start_index, size_t end_index)
312 {
313 if (start_index < end_index)
314 {
315 if (string[start_index] == '-')
316 start_index++;
317 if (start_index + 3 <= end_index
318 && memcmp (string + start_index, "nan", 3) == 0)
319 {
320 start_index += 3;
321 if (start_index == end_index
322 || (string[start_index] == '(' && string[end_index - 1] == ')'))
323 return 1;
324 }
325 }
326 return 0;
327 }
328 static char buf[10000];
329 static long double zeroL = 0.0L;
330 int main ()
331 {
332 int result = 0;
333 nocrash_init();
334 if (sprintf (buf, "%Lf", 1.0L / zeroL) < 0
335 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
336 result |= 1;
337 if (sprintf (buf, "%Lf", -1.0L / zeroL) < 0
338 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
339 result |= 1;
340 if (sprintf (buf, "%Lf", zeroL / zeroL) < 0
341 || !strisnan (buf, 0, strlen (buf)))
342 result |= 1;
343 if (sprintf (buf, "%Le", 1.0L / zeroL) < 0
344 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
345 result |= 1;
346 if (sprintf (buf, "%Le", -1.0L / zeroL) < 0
347 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
348 result |= 1;
349 if (sprintf (buf, "%Le", zeroL / zeroL) < 0
350 || !strisnan (buf, 0, strlen (buf)))
351 result |= 1;
352 if (sprintf (buf, "%Lg", 1.0L / zeroL) < 0
353 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
354 result |= 1;
355 if (sprintf (buf, "%Lg", -1.0L / zeroL) < 0
356 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
357 result |= 1;
358 if (sprintf (buf, "%Lg", zeroL / zeroL) < 0
359 || !strisnan (buf, 0, strlen (buf)))
360 result |= 1;
361 #if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
362 /* Representation of an 80-bit 'long double' as an initializer for a sequence
363 of 'unsigned int' words. */
364 # ifdef WORDS_BIGENDIAN
365 # define LDBL80_WORDS(exponent,manthi,mantlo) \
366 { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
367 ((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16), \
368 (unsigned int) (mantlo) << 16 \
369 }
370 # else
371 # define LDBL80_WORDS(exponent,manthi,mantlo) \
372 { mantlo, manthi, exponent }
373 # endif
374 { /* Quiet NaN. */
375 static union { unsigned int word[4]; long double value; } x =
376 { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
377 if (sprintf (buf, "%Lf", x.value) < 0
378 || !strisnan (buf, 0, strlen (buf)))
379 result |= 2;
380 if (sprintf (buf, "%Le", x.value) < 0
381 || !strisnan (buf, 0, strlen (buf)))
382 result |= 2;
383 if (sprintf (buf, "%Lg", x.value) < 0
384 || !strisnan (buf, 0, strlen (buf)))
385 result |= 2;
386 }
387 {
388 /* Signalling NaN. */
389 static union { unsigned int word[4]; long double value; } x =
390 { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
391 if (sprintf (buf, "%Lf", x.value) < 0
392 || !strisnan (buf, 0, strlen (buf)))
393 result |= 2;
394 if (sprintf (buf, "%Le", x.value) < 0
395 || !strisnan (buf, 0, strlen (buf)))
396 result |= 2;
397 if (sprintf (buf, "%Lg", x.value) < 0
398 || !strisnan (buf, 0, strlen (buf)))
399 result |= 2;
400 }
401 { /* Pseudo-NaN. */
402 static union { unsigned int word[4]; long double value; } x =
403 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
404 if (sprintf (buf, "%Lf", x.value) <= 0)
405 result |= 4;
406 if (sprintf (buf, "%Le", x.value) <= 0)
407 result |= 4;
408 if (sprintf (buf, "%Lg", x.value) <= 0)
409 result |= 4;
410 }
411 { /* Pseudo-Infinity. */
412 static union { unsigned int word[4]; long double value; } x =
413 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
414 if (sprintf (buf, "%Lf", x.value) <= 0)
415 result |= 8;
416 if (sprintf (buf, "%Le", x.value) <= 0)
417 result |= 8;
418 if (sprintf (buf, "%Lg", x.value) <= 0)
419 result |= 8;
420 }
421 { /* Pseudo-Zero. */
422 static union { unsigned int word[4]; long double value; } x =
423 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
424 if (sprintf (buf, "%Lf", x.value) <= 0)
425 result |= 16;
426 if (sprintf (buf, "%Le", x.value) <= 0)
427 result |= 16;
428 if (sprintf (buf, "%Lg", x.value) <= 0)
429 result |= 16;
430 }
431 { /* Unnormalized number. */
432 static union { unsigned int word[4]; long double value; } x =
433 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
434 if (sprintf (buf, "%Lf", x.value) <= 0)
435 result |= 32;
436 if (sprintf (buf, "%Le", x.value) <= 0)
437 result |= 32;
438 if (sprintf (buf, "%Lg", x.value) <= 0)
439 result |= 32;
440 }
441 { /* Pseudo-Denormal. */
442 static union { unsigned int word[4]; long double value; } x =
443 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
444 if (sprintf (buf, "%Lf", x.value) <= 0)
445 result |= 64;
446 if (sprintf (buf, "%Le", x.value) <= 0)
447 result |= 64;
448 if (sprintf (buf, "%Lg", x.value) <= 0)
449 result |= 64;
450 }
451 #endif
452 return result;
453 }]])],
454 [gl_cv_func_printf_infinite_long_double=yes],
455 [gl_cv_func_printf_infinite_long_double=no],
456 [case "$host_cpu" in
457 # Guess no on ia64, x86_64, i386.
458 ia64 | x86_64 | i*86) gl_cv_func_printf_infinite_long_double="guessing no";;
459 *)
460 case "$host_os" in
461 changequote(,)dnl
462 # Guess yes on glibc systems.
463 *-gnu* | gnu*) gl_cv_func_printf_infinite_long_double="guessing yes";;
464 # Guess yes on musl systems.
465 *-musl*) gl_cv_func_printf_infinite_long_double="guessing yes";;
466 # Guess yes on FreeBSD >= 6.
467 freebsd[1-5].*) gl_cv_func_printf_infinite_long_double="guessing no";;
468 freebsd* | kfreebsd*) gl_cv_func_printf_infinite_long_double="guessing yes";;
469 # Guess yes on HP-UX >= 11.
470 hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite_long_double="guessing no";;
471 hpux*) gl_cv_func_printf_infinite_long_double="guessing yes";;
472 # Guess no on Android.
473 linux*-android*) gl_cv_func_printf_infinite_long_double="guessing no";;
474 changequote([,])dnl
475 # Guess yes on MSVC, no on mingw.
476 mingw*) AC_EGREP_CPP([Known], [
477 #ifdef _MSC_VER
478 Known
479 #endif
480 ],
481 [gl_cv_func_printf_infinite_long_double="guessing yes"],
482 [gl_cv_func_printf_infinite_long_double="guessing no"])
483 ;;
484 # If we don't know, obey --enable-cross-guesses.
485 *) gl_cv_func_printf_infinite_long_double="$gl_cross_guess_normal";;
486 esac
487 ;;
488 esac
489 ])
490 ])
491 ;;
492 *)
493 gl_cv_func_printf_infinite_long_double="irrelevant"
494 ;;
495 esac
496 ])
497
498 dnl Test whether the *printf family of functions supports the 'a' and 'A'
499 dnl conversion specifier for hexadecimal output of floating-point numbers.
500 dnl (ISO C99, POSIX:2001)
501 dnl Result is gl_cv_func_printf_directive_a.
502
503 AC_DEFUN([gl_PRINTF_DIRECTIVE_A],
504 [
505 AC_REQUIRE([AC_PROG_CC])
506 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
507 AC_CACHE_CHECK([whether printf supports the 'a' and 'A' directives],
508 [gl_cv_func_printf_directive_a],
509 [
510 AC_RUN_IFELSE(
511 [AC_LANG_SOURCE([[
512 #include <stdio.h>
513 #include <string.h>
514 static char buf[100];
515 static double zero = 0.0;
516 int main ()
517 {
518 int result = 0;
519 if (sprintf (buf, "%a %d", 3.1416015625, 33, 44, 55) < 0
520 || (strcmp (buf, "0x1.922p+1 33") != 0
521 && strcmp (buf, "0x3.244p+0 33") != 0
522 && strcmp (buf, "0x6.488p-1 33") != 0
523 && strcmp (buf, "0xc.91p-2 33") != 0))
524 result |= 1;
525 if (sprintf (buf, "%A %d", -3.1416015625, 33, 44, 55) < 0
526 || (strcmp (buf, "-0X1.922P+1 33") != 0
527 && strcmp (buf, "-0X3.244P+0 33") != 0
528 && strcmp (buf, "-0X6.488P-1 33") != 0
529 && strcmp (buf, "-0XC.91P-2 33") != 0))
530 result |= 2;
531 /* This catches a FreeBSD 6.1 bug: it doesn't round. */
532 if (sprintf (buf, "%.2a %d", 1.51, 33, 44, 55) < 0
533 || (strcmp (buf, "0x1.83p+0 33") != 0
534 && strcmp (buf, "0x3.05p-1 33") != 0
535 && strcmp (buf, "0x6.0ap-2 33") != 0
536 && strcmp (buf, "0xc.14p-3 33") != 0))
537 result |= 4;
538 /* This catches a Mac OS X 10.12.4 (Darwin 16.5) bug: it doesn't round. */
539 if (sprintf (buf, "%.0a %d", 1.51, 33, 44, 55) < 0
540 || (strcmp (buf, "0x2p+0 33") != 0
541 && strcmp (buf, "0x3p-1 33") != 0
542 && strcmp (buf, "0x6p-2 33") != 0
543 && strcmp (buf, "0xcp-3 33") != 0))
544 result |= 4;
545 /* This catches a FreeBSD 6.1 bug. See
546 <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */
547 if (sprintf (buf, "%010a %d", 1.0 / zero, 33, 44, 55) < 0
548 || buf[0] == '0')
549 result |= 8;
550 /* This catches a Mac OS X 10.3.9 (Darwin 7.9) bug. */
551 if (sprintf (buf, "%.1a", 1.999) < 0
552 || (strcmp (buf, "0x1.0p+1") != 0
553 && strcmp (buf, "0x2.0p+0") != 0
554 && strcmp (buf, "0x4.0p-1") != 0
555 && strcmp (buf, "0x8.0p-2") != 0))
556 result |= 16;
557 /* This catches the same Mac OS X 10.3.9 (Darwin 7.9) bug and also a
558 glibc 2.4 bug <https://sourceware.org/bugzilla/show_bug.cgi?id=2908>. */
559 if (sprintf (buf, "%.1La", 1.999L) < 0
560 || (strcmp (buf, "0x1.0p+1") != 0
561 && strcmp (buf, "0x2.0p+0") != 0
562 && strcmp (buf, "0x4.0p-1") != 0
563 && strcmp (buf, "0x8.0p-2") != 0))
564 result |= 32;
565 return result;
566 }]])],
567 [gl_cv_func_printf_directive_a=yes],
568 [gl_cv_func_printf_directive_a=no],
569 [
570 case "$host_os" in
571 # Guess yes on glibc >= 2.5 systems.
572 *-gnu* | gnu*)
573 AC_EGREP_CPP([BZ2908], [
574 #include <features.h>
575 #ifdef __GNU_LIBRARY__
576 #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 5) || (__GLIBC__ > 2)) && !defined __UCLIBC__
577 BZ2908
578 #endif
579 #endif
580 ],
581 [gl_cv_func_printf_directive_a="guessing yes"],
582 [gl_cv_func_printf_directive_a="guessing no"])
583 ;;
584 # Guess yes on musl systems.
585 *-musl*) gl_cv_func_printf_directive_a="guessing yes";;
586 # Guess no on Android.
587 linux*-android*) gl_cv_func_printf_directive_a="guessing no";;
588 # Guess no on native Windows.
589 mingw*) gl_cv_func_printf_directive_a="guessing no";;
590 # If we don't know, obey --enable-cross-guesses.
591 *) gl_cv_func_printf_directive_a="$gl_cross_guess_normal";;
592 esac
593 ])
594 ])
595 ])
596
597 dnl Test whether the *printf family of functions supports the %F format
598 dnl directive. (ISO C99, POSIX:2001)
599 dnl Result is gl_cv_func_printf_directive_f.
600
601 AC_DEFUN([gl_PRINTF_DIRECTIVE_F],
602 [
603 AC_REQUIRE([AC_PROG_CC])
604 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
605 AC_CACHE_CHECK([whether printf supports the 'F' directive],
606 [gl_cv_func_printf_directive_f],
607 [
608 AC_RUN_IFELSE(
609 [AC_LANG_SOURCE([[
610 #include <stdio.h>
611 #include <string.h>
612 static char buf[100];
613 static double zero = 0.0;
614 int main ()
615 {
616 int result = 0;
617 if (sprintf (buf, "%F %d", 1234567.0, 33, 44, 55) < 0
618 || strcmp (buf, "1234567.000000 33") != 0)
619 result |= 1;
620 if (sprintf (buf, "%F", 1.0 / zero) < 0
621 || (strcmp (buf, "INF") != 0 && strcmp (buf, "INFINITY") != 0))
622 result |= 2;
623 /* This catches a Cygwin 1.5.x bug. */
624 if (sprintf (buf, "%.F", 1234.0) < 0
625 || strcmp (buf, "1234") != 0)
626 result |= 4;
627 return result;
628 }]])],
629 [gl_cv_func_printf_directive_f=yes],
630 [gl_cv_func_printf_directive_f=no],
631 [
632 case "$host_os" in
633 changequote(,)dnl
634 # Guess yes on glibc systems.
635 *-gnu* | gnu*) gl_cv_func_printf_directive_f="guessing yes";;
636 # Guess yes on musl systems.
637 *-musl*) gl_cv_func_printf_directive_f="guessing yes";;
638 # Guess yes on FreeBSD >= 6.
639 freebsd[1-5].*) gl_cv_func_printf_directive_f="guessing no";;
640 freebsd* | kfreebsd*) gl_cv_func_printf_directive_f="guessing yes";;
641 # Guess yes on Mac OS X >= 10.3.
642 darwin[1-6].*) gl_cv_func_printf_directive_f="guessing no";;
643 darwin*) gl_cv_func_printf_directive_f="guessing yes";;
644 # Guess yes on Solaris >= 2.10.
645 solaris2.[1-9][0-9]*) gl_cv_func_printf_directive_f="guessing yes";;
646 solaris*) gl_cv_func_printf_directive_f="guessing no";;
647 # Guess no on Android.
648 linux*-android*) gl_cv_func_printf_directive_f="guessing no";;
649 changequote([,])dnl
650 # Guess yes on MSVC, no on mingw.
651 mingw*) AC_EGREP_CPP([Known], [
652 #ifdef _MSC_VER
653 Known
654 #endif
655 ],
656 [gl_cv_func_printf_directive_f="guessing yes"],
657 [gl_cv_func_printf_directive_f="guessing no"])
658 ;;
659 # If we don't know, obey --enable-cross-guesses.
660 *) gl_cv_func_printf_directive_f="$gl_cross_guess_normal";;
661 esac
662 ])
663 ])
664 ])
665
666 dnl Test whether the *printf family of functions supports the %n format
667 dnl directive. (ISO C99, POSIX:2001)
668 dnl Result is gl_cv_func_printf_directive_n.
669
670 AC_DEFUN([gl_PRINTF_DIRECTIVE_N],
671 [
672 AC_REQUIRE([AC_PROG_CC])
673 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
674 AC_CACHE_CHECK([whether printf supports the 'n' directive],
675 [gl_cv_func_printf_directive_n],
676 [
677 AC_RUN_IFELSE(
678 [AC_LANG_SOURCE([[
679 #include <stdio.h>
680 #include <stdlib.h>
681 #include <string.h>
682 #ifdef _MSC_VER
683 /* See page about "Parameter Validation" on msdn.microsoft.com. */
684 static void cdecl
685 invalid_parameter_handler (const wchar_t *expression,
686 const wchar_t *function,
687 const wchar_t *file, unsigned int line,
688 uintptr_t dummy)
689 {
690 exit (1);
691 }
692 #endif
693 static char fmtstring[10];
694 static char buf[100];
695 int main ()
696 {
697 int count = -1;
698 #ifdef _MSC_VER
699 _set_invalid_parameter_handler (invalid_parameter_handler);
700 #endif
701 /* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2)
702 support %n in format strings in read-only memory but not in writable
703 memory. */
704 strcpy (fmtstring, "%d %n");
705 if (sprintf (buf, fmtstring, 123, &count, 33, 44, 55) < 0
706 || strcmp (buf, "123 ") != 0
707 || count != 4)
708 return 1;
709 return 0;
710 }]])],
711 [gl_cv_func_printf_directive_n=yes],
712 [gl_cv_func_printf_directive_n=no],
713 [case "$host_os" in
714 # Guess no on glibc when _FORTIFY_SOURCE >= 2.
715 *-gnu* | gnu*) AC_COMPILE_IFELSE(
716 [AC_LANG_SOURCE(
717 [[#if _FORTIFY_SOURCE >= 2
718 error fail
719 #endif
720 ]])],
721 [gl_cv_func_printf_directive_n="guessing yes"],
722 [gl_cv_func_printf_directive_n="guessing no"])
723 ;;
724 # Guess no on Android.
725 linux*-android*) gl_cv_func_printf_directive_n="guessing no";;
726 # Guess no on native Windows.
727 mingw*) gl_cv_func_printf_directive_n="guessing no";;
728 *) gl_cv_func_printf_directive_n="guessing yes";;
729 esac
730 ])
731 ])
732 ])
733
734 dnl Test whether the *printf family of functions supports the %ls format
735 dnl directive and in particular, when a precision is specified, whether
736 dnl the functions stop converting the wide string argument when the number
737 dnl of bytes that have been produced by this conversion equals or exceeds
738 dnl the precision.
739 dnl Result is gl_cv_func_printf_directive_ls.
740
741 AC_DEFUN([gl_PRINTF_DIRECTIVE_LS],
742 [
743 AC_REQUIRE([AC_PROG_CC])
744 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
745 AC_CACHE_CHECK([whether printf supports the 'ls' directive],
746 [gl_cv_func_printf_directive_ls],
747 [
748 AC_RUN_IFELSE(
749 [AC_LANG_SOURCE([[
750 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
751 <wchar.h>.
752 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
753 included before <wchar.h>. */
754 #include <stddef.h>
755 #include <stdio.h>
756 #include <time.h>
757 #include <wchar.h>
758 #include <string.h>
759 int main ()
760 {
761 int result = 0;
762 char buf[100];
763 /* Test whether %ls works at all.
764 This test fails on OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku, but not on
765 Cygwin 1.5. */
766 {
767 static const wchar_t wstring[] = { 'a', 'b', 'c', 0 };
768 buf[0] = '\0';
769 if (sprintf (buf, "%ls", wstring) < 0
770 || strcmp (buf, "abc") != 0)
771 result |= 1;
772 }
773 /* This test fails on IRIX 6.5, Solaris 2.6, Cygwin 1.5, Haiku (with an
774 assertion failure inside libc), but not on OpenBSD 4.0. */
775 {
776 static const wchar_t wstring[] = { 'a', 0 };
777 buf[0] = '\0';
778 if (sprintf (buf, "%ls", wstring) < 0
779 || strcmp (buf, "a") != 0)
780 result |= 2;
781 }
782 /* Test whether precisions in %ls are supported as specified in ISO C 99
783 section 7.19.6.1:
784 "If a precision is specified, no more than that many bytes are written
785 (including shift sequences, if any), and the array shall contain a
786 null wide character if, to equal the multibyte character sequence
787 length given by the precision, the function would need to access a
788 wide character one past the end of the array."
789 This test fails on Solaris 10. */
790 {
791 static const wchar_t wstring[] = { 'a', 'b', (wchar_t) 0xfdfdfdfd, 0 };
792 buf[0] = '\0';
793 if (sprintf (buf, "%.2ls", wstring) < 0
794 || strcmp (buf, "ab") != 0)
795 result |= 8;
796 }
797 return result;
798 }]])],
799 [gl_cv_func_printf_directive_ls=yes],
800 [gl_cv_func_printf_directive_ls=no],
801 [
802 changequote(,)dnl
803 case "$host_os" in
804 openbsd*) gl_cv_func_printf_directive_ls="guessing no";;
805 irix*) gl_cv_func_printf_directive_ls="guessing no";;
806 solaris*) gl_cv_func_printf_directive_ls="guessing no";;
807 cygwin*) gl_cv_func_printf_directive_ls="guessing no";;
808 beos* | haiku*) gl_cv_func_printf_directive_ls="guessing no";;
809 # Guess no on Android.
810 linux*-android*) gl_cv_func_printf_directive_ls="guessing no";;
811 # Guess yes on native Windows.
812 mingw*) gl_cv_func_printf_directive_ls="guessing yes";;
813 *) gl_cv_func_printf_directive_ls="guessing yes";;
814 esac
815 changequote([,])dnl
816 ])
817 ])
818 ])
819
820 dnl Test whether the *printf family of functions supports POSIX/XSI format
821 dnl strings with positions. (POSIX:2001)
822 dnl Result is gl_cv_func_printf_positions.
823
824 AC_DEFUN([gl_PRINTF_POSITIONS],
825 [
826 AC_REQUIRE([AC_PROG_CC])
827 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
828 AC_CACHE_CHECK([whether printf supports POSIX/XSI format strings with positions],
829 [gl_cv_func_printf_positions],
830 [
831 AC_RUN_IFELSE(
832 [AC_LANG_SOURCE([[
833 #include <stdio.h>
834 #include <string.h>
835 /* The string "%2$d %1$d", with dollar characters protected from the shell's
836 dollar expansion (possibly an autoconf bug). */
837 static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' };
838 static char buf[100];
839 int main ()
840 {
841 sprintf (buf, format, 33, 55);
842 return (strcmp (buf, "55 33") != 0);
843 }]])],
844 [gl_cv_func_printf_positions=yes],
845 [gl_cv_func_printf_positions=no],
846 [
847 changequote(,)dnl
848 case "$host_os" in
849 netbsd[1-3]* | netbsdelf[1-3]* | netbsdaout[1-3]* | netbsdcoff[1-3]*)
850 gl_cv_func_printf_positions="guessing no";;
851 beos*) gl_cv_func_printf_positions="guessing no";;
852 # Guess yes on Android.
853 linux*-android*) gl_cv_func_printf_positions="guessing yes";;
854 # Guess no on native Windows.
855 mingw* | pw*) gl_cv_func_printf_positions="guessing no";;
856 *) gl_cv_func_printf_positions="guessing yes";;
857 esac
858 changequote([,])dnl
859 ])
860 ])
861 ])
862
863 dnl Test whether the *printf family of functions supports POSIX/XSI format
864 dnl strings with the ' flag for grouping of decimal digits. (POSIX:2001)
865 dnl Result is gl_cv_func_printf_flag_grouping.
866
867 AC_DEFUN([gl_PRINTF_FLAG_GROUPING],
868 [
869 AC_REQUIRE([AC_PROG_CC])
870 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
871 AC_CACHE_CHECK([whether printf supports the grouping flag],
872 [gl_cv_func_printf_flag_grouping],
873 [
874 AC_RUN_IFELSE(
875 [AC_LANG_SOURCE([[
876 #include <stdio.h>
877 #include <string.h>
878 static char buf[100];
879 int main ()
880 {
881 if (sprintf (buf, "%'d %d", 1234567, 99) < 0
882 || buf[strlen (buf) - 1] != '9')
883 return 1;
884 return 0;
885 }]])],
886 [gl_cv_func_printf_flag_grouping=yes],
887 [gl_cv_func_printf_flag_grouping=no],
888 [
889 changequote(,)dnl
890 case "$host_os" in
891 cygwin*) gl_cv_func_printf_flag_grouping="guessing no";;
892 netbsd*) gl_cv_func_printf_flag_grouping="guessing no";;
893 # Guess no on Android.
894 linux*-android*) gl_cv_func_printf_flag_grouping="guessing no";;
895 # Guess no on native Windows.
896 mingw* | pw*) gl_cv_func_printf_flag_grouping="guessing no";;
897 *) gl_cv_func_printf_flag_grouping="guessing yes";;
898 esac
899 changequote([,])dnl
900 ])
901 ])
902 ])
903
904 dnl Test whether the *printf family of functions supports the - flag correctly.
905 dnl (ISO C99.) See
906 dnl <https://lists.gnu.org/r/bug-coreutils/2008-02/msg00035.html>
907 dnl Result is gl_cv_func_printf_flag_leftadjust.
908
909 AC_DEFUN([gl_PRINTF_FLAG_LEFTADJUST],
910 [
911 AC_REQUIRE([AC_PROG_CC])
912 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
913 AC_CACHE_CHECK([whether printf supports the left-adjust flag correctly],
914 [gl_cv_func_printf_flag_leftadjust],
915 [
916 AC_RUN_IFELSE(
917 [AC_LANG_SOURCE([[
918 #include <stdio.h>
919 #include <string.h>
920 static char buf[100];
921 int main ()
922 {
923 /* Check that a '-' flag is not annihilated by a negative width. */
924 if (sprintf (buf, "a%-*sc", -3, "b") < 0
925 || strcmp (buf, "ab c") != 0)
926 return 1;
927 return 0;
928 }]])],
929 [gl_cv_func_printf_flag_leftadjust=yes],
930 [gl_cv_func_printf_flag_leftadjust=no],
931 [
932 changequote(,)dnl
933 case "$host_os" in
934 # Guess yes on HP-UX 11.
935 hpux11*) gl_cv_func_printf_flag_leftadjust="guessing yes";;
936 # Guess no on HP-UX 10 and older.
937 hpux*) gl_cv_func_printf_flag_leftadjust="guessing no";;
938 # Guess yes on Android.
939 linux*-android*) gl_cv_func_printf_flag_leftadjust="guessing yes";;
940 # Guess yes on native Windows.
941 mingw*) gl_cv_func_printf_flag_leftadjust="guessing yes";;
942 # Guess yes otherwise.
943 *) gl_cv_func_printf_flag_leftadjust="guessing yes";;
944 esac
945 changequote([,])dnl
946 ])
947 ])
948 ])
949
950 dnl Test whether the *printf family of functions supports padding of non-finite
951 dnl values with the 0 flag correctly. (ISO C99 + TC1 + TC2.) See
952 dnl <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html>
953 dnl Result is gl_cv_func_printf_flag_zero.
954
955 AC_DEFUN([gl_PRINTF_FLAG_ZERO],
956 [
957 AC_REQUIRE([AC_PROG_CC])
958 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
959 AC_CACHE_CHECK([whether printf supports the zero flag correctly],
960 [gl_cv_func_printf_flag_zero],
961 [
962 AC_RUN_IFELSE(
963 [AC_LANG_SOURCE([[
964 #include <stdio.h>
965 #include <string.h>
966 static char buf[100];
967 static double zero = 0.0;
968 int main ()
969 {
970 if (sprintf (buf, "%010f", 1.0 / zero, 33, 44, 55) < 0
971 || (strcmp (buf, " inf") != 0
972 && strcmp (buf, " infinity") != 0))
973 return 1;
974 return 0;
975 }]])],
976 [gl_cv_func_printf_flag_zero=yes],
977 [gl_cv_func_printf_flag_zero=no],
978 [
979 changequote(,)dnl
980 case "$host_os" in
981 # Guess yes on glibc systems.
982 *-gnu* | gnu*) gl_cv_func_printf_flag_zero="guessing yes";;
983 # Guess yes on musl systems.
984 *-musl*) gl_cv_func_printf_flag_zero="guessing yes";;
985 # Guess yes on BeOS.
986 beos*) gl_cv_func_printf_flag_zero="guessing yes";;
987 # Guess no on Android.
988 linux*-android*) gl_cv_func_printf_flag_zero="guessing no";;
989 # Guess no on native Windows.
990 mingw*) gl_cv_func_printf_flag_zero="guessing no";;
991 # If we don't know, obey --enable-cross-guesses.
992 *) gl_cv_func_printf_flag_zero="$gl_cross_guess_normal";;
993 esac
994 changequote([,])dnl
995 ])
996 ])
997 ])
998
999 dnl Test whether the *printf family of functions supports large precisions.
1000 dnl On mingw, precisions larger than 512 are treated like 512, in integer,
1001 dnl floating-point or pointer output. On Solaris 10/x86, precisions larger
1002 dnl than 510 in floating-point output crash the program. On Solaris 10/SPARC,
1003 dnl precisions larger than 510 in floating-point output yield wrong results.
1004 dnl On AIX 7.1, precisions larger than 998 in floating-point output yield
1005 dnl wrong results. On BeOS, precisions larger than 1044 crash the program.
1006 dnl Result is gl_cv_func_printf_precision.
1007
1008 AC_DEFUN([gl_PRINTF_PRECISION],
1009 [
1010 AC_REQUIRE([AC_PROG_CC])
1011 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1012 AC_CACHE_CHECK([whether printf supports large precisions],
1013 [gl_cv_func_printf_precision],
1014 [
1015 AC_RUN_IFELSE(
1016 [AC_LANG_SOURCE([[
1017 #include <stdio.h>
1018 #include <string.h>
1019 static char buf[5000];
1020 int main ()
1021 {
1022 int result = 0;
1023 #ifdef __BEOS__
1024 /* On BeOS, this would crash and show a dialog box. Avoid the crash. */
1025 return 1;
1026 #endif
1027 if (sprintf (buf, "%.4000d %d", 1, 33, 44) < 4000 + 3)
1028 result |= 1;
1029 if (sprintf (buf, "%.4000f %d", 1.0, 33, 44) < 4000 + 5)
1030 result |= 2;
1031 if (sprintf (buf, "%.511f %d", 1.0, 33, 44) < 511 + 5
1032 || buf[0] != '1')
1033 result |= 4;
1034 if (sprintf (buf, "%.999f %d", 1.0, 33, 44) < 999 + 5
1035 || buf[0] != '1')
1036 result |= 4;
1037 return result;
1038 }]])],
1039 [gl_cv_func_printf_precision=yes],
1040 [gl_cv_func_printf_precision=no],
1041 [
1042 changequote(,)dnl
1043 case "$host_os" in
1044 # Guess no only on Solaris, native Windows, and BeOS systems.
1045 solaris*) gl_cv_func_printf_precision="guessing no" ;;
1046 mingw* | pw*) gl_cv_func_printf_precision="guessing no" ;;
1047 beos*) gl_cv_func_printf_precision="guessing no" ;;
1048 # Guess yes on Android.
1049 linux*-android*) gl_cv_func_printf_precision="guessing yes" ;;
1050 *) gl_cv_func_printf_precision="guessing yes" ;;
1051 esac
1052 changequote([,])dnl
1053 ])
1054 ])
1055 ])
1056
1057 dnl Test whether the *printf family of functions recovers gracefully in case
1058 dnl of an out-of-memory condition, or whether it crashes the entire program.
1059 dnl Result is gl_cv_func_printf_enomem.
1060
1061 AC_DEFUN([gl_PRINTF_ENOMEM],
1062 [
1063 AC_REQUIRE([AC_PROG_CC])
1064 AC_REQUIRE([gl_MULTIARCH])
1065 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1066 AC_CACHE_CHECK([whether printf survives out-of-memory conditions],
1067 [gl_cv_func_printf_enomem],
1068 [
1069 gl_cv_func_printf_enomem="guessing no"
1070 if test "$cross_compiling" = no; then
1071 if test $APPLE_UNIVERSAL_BUILD = 0; then
1072 AC_LANG_CONFTEST([AC_LANG_SOURCE([
1073 ]GL_NOCRASH[
1074 changequote(,)dnl
1075 #include <stdio.h>
1076 #include <sys/types.h>
1077 #include <sys/time.h>
1078 #include <sys/resource.h>
1079 #include <errno.h>
1080 int main()
1081 {
1082 struct rlimit limit;
1083 int ret;
1084 nocrash_init ();
1085 /* Some printf implementations allocate temporary space with malloc. */
1086 /* On BSD systems, malloc() is limited by RLIMIT_DATA. */
1087 #ifdef RLIMIT_DATA
1088 if (getrlimit (RLIMIT_DATA, &limit) < 0)
1089 return 77;
1090 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
1091 limit.rlim_max = 5000000;
1092 limit.rlim_cur = limit.rlim_max;
1093 if (setrlimit (RLIMIT_DATA, &limit) < 0)
1094 return 77;
1095 #endif
1096 /* On Linux systems, malloc() is limited by RLIMIT_AS. */
1097 #ifdef RLIMIT_AS
1098 if (getrlimit (RLIMIT_AS, &limit) < 0)
1099 return 77;
1100 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
1101 limit.rlim_max = 5000000;
1102 limit.rlim_cur = limit.rlim_max;
1103 if (setrlimit (RLIMIT_AS, &limit) < 0)
1104 return 77;
1105 #endif
1106 /* Some printf implementations allocate temporary space on the stack. */
1107 #ifdef RLIMIT_STACK
1108 if (getrlimit (RLIMIT_STACK, &limit) < 0)
1109 return 77;
1110 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
1111 limit.rlim_max = 5000000;
1112 limit.rlim_cur = limit.rlim_max;
1113 if (setrlimit (RLIMIT_STACK, &limit) < 0)
1114 return 77;
1115 #endif
1116 ret = printf ("%.5000000f", 1.0);
1117 return !(ret == 5000002 || (ret < 0 && errno == ENOMEM));
1118 }
1119 changequote([,])dnl
1120 ])])
1121 if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
1122 (./conftest 2>&AS_MESSAGE_LOG_FD
1123 result=$?
1124 _AS_ECHO_LOG([\$? = $result])
1125 if test $result != 0 && test $result != 77; then result=1; fi
1126 exit $result
1127 ) >/dev/null 2>/dev/null
1128 case $? in
1129 0) gl_cv_func_printf_enomem="yes" ;;
1130 77) gl_cv_func_printf_enomem="guessing no" ;;
1131 *) gl_cv_func_printf_enomem="no" ;;
1132 esac
1133 else
1134 gl_cv_func_printf_enomem="guessing no"
1135 fi
1136 rm -fr conftest*
1137 else
1138 dnl A universal build on Apple Mac OS X platforms.
1139 dnl The result would be 'no' in 32-bit mode and 'yes' in 64-bit mode.
1140 dnl But we need a configuration result that is valid in both modes.
1141 gl_cv_func_printf_enomem="guessing no"
1142 fi
1143 fi
1144 if test "$gl_cv_func_printf_enomem" = "guessing no"; then
1145 changequote(,)dnl
1146 case "$host_os" in
1147 # Guess yes on glibc systems.
1148 *-gnu* | gnu*) gl_cv_func_printf_enomem="guessing yes";;
1149 # Guess yes on Solaris.
1150 solaris*) gl_cv_func_printf_enomem="guessing yes";;
1151 # Guess yes on AIX.
1152 aix*) gl_cv_func_printf_enomem="guessing yes";;
1153 # Guess yes on HP-UX/hppa.
1154 hpux*) case "$host_cpu" in
1155 hppa*) gl_cv_func_printf_enomem="guessing yes";;
1156 *) gl_cv_func_printf_enomem="guessing no";;
1157 esac
1158 ;;
1159 # Guess yes on IRIX.
1160 irix*) gl_cv_func_printf_enomem="guessing yes";;
1161 # Guess yes on OSF/1.
1162 osf*) gl_cv_func_printf_enomem="guessing yes";;
1163 # Guess yes on BeOS.
1164 beos*) gl_cv_func_printf_enomem="guessing yes";;
1165 # Guess yes on Haiku.
1166 haiku*) gl_cv_func_printf_enomem="guessing yes";;
1167 # Guess no on Android.
1168 linux*-android*) gl_cv_func_printf_enomem="guessing no";;
1169 # If we don't know, obey --enable-cross-guesses.
1170 *) gl_cv_func_printf_enomem="$gl_cross_guess_normal";;
1171 esac
1172 changequote([,])dnl
1173 fi
1174 ])
1175 ])
1176
1177 dnl Test whether the snprintf function exists. (ISO C99, POSIX:2001)
1178 dnl Result is ac_cv_func_snprintf.
1179
1180 AC_DEFUN([gl_SNPRINTF_PRESENCE],
1181 [
1182 AC_CHECK_FUNCS_ONCE([snprintf])
1183 ])
1184
1185 dnl Test whether the string produced by the snprintf function is always NUL
1186 dnl terminated. (ISO C99, POSIX:2001)
1187 dnl Result is gl_cv_func_snprintf_truncation_c99.
1188
1189 AC_DEFUN([gl_SNPRINTF_TRUNCATION_C99],
1190 [
1191 AC_REQUIRE([AC_PROG_CC])
1192 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1193 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1194 AC_CACHE_CHECK([whether snprintf truncates the result as in C99],
1195 [gl_cv_func_snprintf_truncation_c99],
1196 [
1197 AC_RUN_IFELSE(
1198 [AC_LANG_SOURCE([[
1199 #include <stdio.h>
1200 #include <string.h>
1201 #if HAVE_SNPRINTF
1202 # define my_snprintf snprintf
1203 #else
1204 # include <stdarg.h>
1205 static int my_snprintf (char *buf, int size, const char *format, ...)
1206 {
1207 va_list args;
1208 int ret;
1209 va_start (args, format);
1210 ret = vsnprintf (buf, size, format, args);
1211 va_end (args);
1212 return ret;
1213 }
1214 #endif
1215 static char buf[100];
1216 int main ()
1217 {
1218 strcpy (buf, "ABCDEF");
1219 my_snprintf (buf, 3, "%d %d", 4567, 89);
1220 if (memcmp (buf, "45\0DEF", 6) != 0)
1221 return 1;
1222 return 0;
1223 }]])],
1224 [gl_cv_func_snprintf_truncation_c99=yes],
1225 [gl_cv_func_snprintf_truncation_c99=no],
1226 [
1227 changequote(,)dnl
1228 case "$host_os" in
1229 # Guess yes on glibc systems.
1230 *-gnu* | gnu*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1231 # Guess yes on musl systems.
1232 *-musl*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1233 # Guess yes on FreeBSD >= 5.
1234 freebsd[1-4].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1235 freebsd* | kfreebsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1236 # Guess yes on Mac OS X >= 10.3.
1237 darwin[1-6].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1238 darwin*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1239 # Guess yes on OpenBSD >= 3.9.
1240 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
1241 gl_cv_func_snprintf_truncation_c99="guessing no";;
1242 openbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1243 # Guess yes on Solaris >= 2.6.
1244 solaris2.[0-5] | solaris2.[0-5].*)
1245 gl_cv_func_snprintf_truncation_c99="guessing no";;
1246 solaris*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1247 # Guess yes on AIX >= 4.
1248 aix[1-3]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1249 aix*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1250 # Guess yes on HP-UX >= 11.
1251 hpux[7-9]* | hpux10*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1252 hpux*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1253 # Guess yes on IRIX >= 6.5.
1254 irix6.5) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1255 # Guess yes on OSF/1 >= 5.
1256 osf[3-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1257 osf*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1258 # Guess yes on NetBSD >= 3.
1259 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1260 gl_cv_func_snprintf_truncation_c99="guessing no";;
1261 netbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1262 # Guess yes on BeOS.
1263 beos*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1264 # Guess yes on Android.
1265 linux*-android*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1266 # Guess no on native Windows.
1267 mingw*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1268 # If we don't know, obey --enable-cross-guesses.
1269 *) gl_cv_func_snprintf_truncation_c99="$gl_cross_guess_normal";;
1270 esac
1271 changequote([,])dnl
1272 ])
1273 ])
1274 ])
1275
1276 dnl Test whether the return value of the snprintf function is the number
1277 dnl of bytes (excluding the terminating NUL) that would have been produced
1278 dnl if the buffer had been large enough. (ISO C99, POSIX:2001)
1279 dnl For example, this test program fails on IRIX 6.5:
1280 dnl ---------------------------------------------------------------------
1281 dnl #include <stdio.h>
1282 dnl int main()
1283 dnl {
1284 dnl static char buf[8];
1285 dnl int retval = snprintf (buf, 3, "%d", 12345);
1286 dnl return retval >= 0 && retval < 3;
1287 dnl }
1288 dnl ---------------------------------------------------------------------
1289 dnl Result is gl_cv_func_snprintf_retval_c99.
1290
1291 AC_DEFUN_ONCE([gl_SNPRINTF_RETVAL_C99],
1292 [
1293 AC_REQUIRE([AC_PROG_CC])
1294 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1295 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1296 AC_CACHE_CHECK([whether snprintf returns a byte count as in C99],
1297 [gl_cv_func_snprintf_retval_c99],
1298 [
1299 AC_RUN_IFELSE(
1300 [AC_LANG_SOURCE([[
1301 #include <stdio.h>
1302 #include <string.h>
1303 #if HAVE_SNPRINTF
1304 # define my_snprintf snprintf
1305 #else
1306 # include <stdarg.h>
1307 static int my_snprintf (char *buf, int size, const char *format, ...)
1308 {
1309 va_list args;
1310 int ret;
1311 va_start (args, format);
1312 ret = vsnprintf (buf, size, format, args);
1313 va_end (args);
1314 return ret;
1315 }
1316 #endif
1317 static char buf[100];
1318 int main ()
1319 {
1320 strcpy (buf, "ABCDEF");
1321 if (my_snprintf (buf, 3, "%d %d", 4567, 89) != 7)
1322 return 1;
1323 if (my_snprintf (buf, 0, "%d %d", 4567, 89) != 7)
1324 return 2;
1325 if (my_snprintf (NULL, 0, "%d %d", 4567, 89) != 7)
1326 return 3;
1327 return 0;
1328 }]])],
1329 [gl_cv_func_snprintf_retval_c99=yes],
1330 [gl_cv_func_snprintf_retval_c99=no],
1331 [case "$host_os" in
1332 changequote(,)dnl
1333 # Guess yes on glibc systems.
1334 *-gnu* | gnu*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1335 # Guess yes on musl systems.
1336 *-musl*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1337 # Guess yes on FreeBSD >= 5.
1338 freebsd[1-4].*) gl_cv_func_snprintf_retval_c99="guessing no";;
1339 freebsd* | kfreebsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1340 # Guess yes on Mac OS X >= 10.3.
1341 darwin[1-6].*) gl_cv_func_snprintf_retval_c99="guessing no";;
1342 darwin*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1343 # Guess yes on OpenBSD >= 3.9.
1344 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
1345 gl_cv_func_snprintf_retval_c99="guessing no";;
1346 openbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1347 # Guess yes on Solaris >= 2.10.
1348 solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";;
1349 solaris*) gl_cv_func_printf_sizes_c99="guessing no";;
1350 # Guess yes on AIX >= 4.
1351 aix[1-3]*) gl_cv_func_snprintf_retval_c99="guessing no";;
1352 aix*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1353 # Guess yes on NetBSD >= 3.
1354 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1355 gl_cv_func_snprintf_retval_c99="guessing no";;
1356 netbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1357 # Guess yes on BeOS.
1358 beos*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1359 # Guess yes on Android.
1360 linux*-android*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1361 changequote([,])dnl
1362 # Guess yes on MSVC, no on mingw.
1363 mingw*) AC_EGREP_CPP([Known], [
1364 #ifdef _MSC_VER
1365 Known
1366 #endif
1367 ],
1368 [gl_cv_func_snprintf_retval_c99="guessing yes"],
1369 [gl_cv_func_snprintf_retval_c99="guessing no"])
1370 ;;
1371 # If we don't know, obey --enable-cross-guesses.
1372 *) gl_cv_func_snprintf_retval_c99="$gl_cross_guess_normal";;
1373 esac
1374 ])
1375 ])
1376 ])
1377
1378 dnl Test whether the snprintf function supports the %n format directive
1379 dnl also in truncated portions of the format string. (ISO C99, POSIX:2001)
1380 dnl Result is gl_cv_func_snprintf_directive_n.
1381
1382 AC_DEFUN([gl_SNPRINTF_DIRECTIVE_N],
1383 [
1384 AC_REQUIRE([AC_PROG_CC])
1385 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1386 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1387 AC_CACHE_CHECK([whether snprintf fully supports the 'n' directive],
1388 [gl_cv_func_snprintf_directive_n],
1389 [
1390 AC_RUN_IFELSE(
1391 [AC_LANG_SOURCE([[
1392 #include <stdio.h>
1393 #include <string.h>
1394 #if HAVE_SNPRINTF
1395 # define my_snprintf snprintf
1396 #else
1397 # include <stdarg.h>
1398 static int my_snprintf (char *buf, int size, const char *format, ...)
1399 {
1400 va_list args;
1401 int ret;
1402 va_start (args, format);
1403 ret = vsnprintf (buf, size, format, args);
1404 va_end (args);
1405 return ret;
1406 }
1407 #endif
1408 static char fmtstring[10];
1409 static char buf[100];
1410 int main ()
1411 {
1412 int count = -1;
1413 /* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2)
1414 support %n in format strings in read-only memory but not in writable
1415 memory. */
1416 strcpy (fmtstring, "%d %n");
1417 my_snprintf (buf, 4, fmtstring, 12345, &count, 33, 44, 55);
1418 if (count != 6)
1419 return 1;
1420 return 0;
1421 }]])],
1422 [gl_cv_func_snprintf_directive_n=yes],
1423 [gl_cv_func_snprintf_directive_n=no],
1424 [
1425 case "$host_os" in
1426 # Guess no on glibc when _FORTIFY_SOURCE >= 2.
1427 *-gnu* | gnu*) AC_COMPILE_IFELSE(
1428 [AC_LANG_SOURCE(
1429 [[#if _FORTIFY_SOURCE >= 2
1430 error fail
1431 #endif
1432 ]])],
1433 [gl_cv_func_snprintf_directive_n="guessing yes"],
1434 [gl_cv_func_snprintf_directive_n="guessing no"])
1435 ;;
1436 changequote(,)dnl
1437 # Guess yes on musl systems.
1438 *-musl*) gl_cv_func_snprintf_directive_n="guessing yes";;
1439 # Guess yes on FreeBSD >= 5.
1440 freebsd[1-4].*) gl_cv_func_snprintf_directive_n="guessing no";;
1441 freebsd* | kfreebsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
1442 # Guess yes on Mac OS X >= 10.3.
1443 darwin[1-6].*) gl_cv_func_snprintf_directive_n="guessing no";;
1444 darwin*) gl_cv_func_snprintf_directive_n="guessing yes";;
1445 # Guess yes on Solaris >= 2.6.
1446 solaris2.[0-5] | solaris2.[0-5].*)
1447 gl_cv_func_snprintf_directive_n="guessing no";;
1448 solaris*) gl_cv_func_snprintf_directive_n="guessing yes";;
1449 # Guess yes on AIX >= 4.
1450 aix[1-3]*) gl_cv_func_snprintf_directive_n="guessing no";;
1451 aix*) gl_cv_func_snprintf_directive_n="guessing yes";;
1452 # Guess yes on IRIX >= 6.5.
1453 irix6.5) gl_cv_func_snprintf_directive_n="guessing yes";;
1454 # Guess yes on OSF/1 >= 5.
1455 osf[3-4]*) gl_cv_func_snprintf_directive_n="guessing no";;
1456 osf*) gl_cv_func_snprintf_directive_n="guessing yes";;
1457 # Guess yes on NetBSD >= 3.
1458 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1459 gl_cv_func_snprintf_directive_n="guessing no";;
1460 netbsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
1461 # Guess yes on BeOS.
1462 beos*) gl_cv_func_snprintf_directive_n="guessing yes";;
1463 # Guess no on Android.
1464 linux*-android*) gl_cv_func_snprintf_directive_n="guessing no";;
1465 # Guess no on native Windows.
1466 mingw*) gl_cv_func_snprintf_directive_n="guessing no";;
1467 # If we don't know, obey --enable-cross-guesses.
1468 *) gl_cv_func_snprintf_directive_n="$gl_cross_guess_normal";;
1469 changequote([,])dnl
1470 esac
1471 ])
1472 ])
1473 ])
1474
1475 dnl Test whether the snprintf function, when passed a size = 1, writes any
1476 dnl output without bounds in this case, behaving like sprintf. This is the
1477 dnl case on Linux libc5.
1478 dnl Result is gl_cv_func_snprintf_size1.
1479
1480 AC_DEFUN([gl_SNPRINTF_SIZE1],
1481 [
1482 AC_REQUIRE([AC_PROG_CC])
1483 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1484 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1485 AC_CACHE_CHECK([whether snprintf respects a size of 1],
1486 [gl_cv_func_snprintf_size1],
1487 [
1488 AC_RUN_IFELSE(
1489 [AC_LANG_SOURCE([[
1490 #include <stdio.h>
1491 #if HAVE_SNPRINTF
1492 # define my_snprintf snprintf
1493 #else
1494 # include <stdarg.h>
1495 static int my_snprintf (char *buf, int size, const char *format, ...)
1496 {
1497 va_list args;
1498 int ret;
1499 va_start (args, format);
1500 ret = vsnprintf (buf, size, format, args);
1501 va_end (args);
1502 return ret;
1503 }
1504 #endif
1505 int main()
1506 {
1507 static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1508 my_snprintf (buf, 1, "%d", 12345);
1509 return buf[1] != 'E';
1510 }]])],
1511 [gl_cv_func_snprintf_size1=yes],
1512 [gl_cv_func_snprintf_size1=no],
1513 [case "$host_os" in
1514 # Guess yes on Android.
1515 linux*-android*) gl_cv_func_snprintf_size1="guessing yes" ;;
1516 # Guess yes on native Windows.
1517 mingw*) gl_cv_func_snprintf_size1="guessing yes" ;;
1518 *) gl_cv_func_snprintf_size1="guessing yes" ;;
1519 esac
1520 ])
1521 ])
1522 ])
1523
1524 dnl Test whether the vsnprintf function, when passed a zero size, produces no
1525 dnl output. (ISO C99, POSIX:2001)
1526 dnl For example, snprintf nevertheless writes a NUL byte in this case
1527 dnl on OSF/1 5.1:
1528 dnl ---------------------------------------------------------------------
1529 dnl #include <stdio.h>
1530 dnl int main()
1531 dnl {
1532 dnl static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1533 dnl snprintf (buf, 0, "%d", 12345);
1534 dnl return buf[0] != 'D';
1535 dnl }
1536 dnl ---------------------------------------------------------------------
1537 dnl And vsnprintf writes any output without bounds in this case, behaving like
1538 dnl vsprintf, on HP-UX 11 and OSF/1 5.1:
1539 dnl ---------------------------------------------------------------------
1540 dnl #include <stdarg.h>
1541 dnl #include <stdio.h>
1542 dnl static int my_snprintf (char *buf, int size, const char *format, ...)
1543 dnl {
1544 dnl va_list args;
1545 dnl int ret;
1546 dnl va_start (args, format);
1547 dnl ret = vsnprintf (buf, size, format, args);
1548 dnl va_end (args);
1549 dnl return ret;
1550 dnl }
1551 dnl int main()
1552 dnl {
1553 dnl static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1554 dnl my_snprintf (buf, 0, "%d", 12345);
1555 dnl return buf[0] != 'D';
1556 dnl }
1557 dnl ---------------------------------------------------------------------
1558 dnl Result is gl_cv_func_vsnprintf_zerosize_c99.
1559
1560 AC_DEFUN([gl_VSNPRINTF_ZEROSIZE_C99],
1561 [
1562 AC_REQUIRE([AC_PROG_CC])
1563 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1564 AC_CACHE_CHECK([whether vsnprintf respects a zero size as in C99],
1565 [gl_cv_func_vsnprintf_zerosize_c99],
1566 [
1567 AC_RUN_IFELSE(
1568 [AC_LANG_SOURCE([[
1569 #include <stdarg.h>
1570 #include <stdio.h>
1571 static int my_snprintf (char *buf, int size, const char *format, ...)
1572 {
1573 va_list args;
1574 int ret;
1575 va_start (args, format);
1576 ret = vsnprintf (buf, size, format, args);
1577 va_end (args);
1578 return ret;
1579 }
1580 int main()
1581 {
1582 static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1583 my_snprintf (buf, 0, "%d", 12345);
1584 return buf[0] != 'D';
1585 }]])],
1586 [gl_cv_func_vsnprintf_zerosize_c99=yes],
1587 [gl_cv_func_vsnprintf_zerosize_c99=no],
1588 [
1589 changequote(,)dnl
1590 case "$host_os" in
1591 # Guess yes on glibc systems.
1592 *-gnu* | gnu*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1593 # Guess yes on musl systems.
1594 *-musl*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1595 # Guess yes on FreeBSD >= 5.
1596 freebsd[1-4].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1597 freebsd* | kfreebsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1598 # Guess yes on Mac OS X >= 10.3.
1599 darwin[1-6].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1600 darwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1601 # Guess yes on Cygwin.
1602 cygwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1603 # Guess yes on Solaris >= 2.6.
1604 solaris2.[0-5] | solaris2.[0-5].*)
1605 gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1606 solaris*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1607 # Guess yes on AIX >= 4.
1608 aix[1-3]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1609 aix*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1610 # Guess yes on IRIX >= 6.5.
1611 irix6.5) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1612 # Guess yes on NetBSD >= 3.
1613 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1614 gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1615 netbsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1616 # Guess yes on BeOS.
1617 beos*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1618 # Guess yes on Android.
1619 linux*-android*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1620 # Guess yes on native Windows.
1621 mingw* | pw*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1622 # If we don't know, obey --enable-cross-guesses.
1623 *) gl_cv_func_vsnprintf_zerosize_c99="$gl_cross_guess_normal";;
1624 esac
1625 changequote([,])dnl
1626 ])
1627 ])
1628 ])
1629
1630 dnl The results of these tests on various platforms are:
1631 dnl
1632 dnl 1 = gl_PRINTF_SIZES_C99
1633 dnl 2 = gl_PRINTF_LONG_DOUBLE
1634 dnl 3 = gl_PRINTF_INFINITE
1635 dnl 4 = gl_PRINTF_INFINITE_LONG_DOUBLE
1636 dnl 5 = gl_PRINTF_DIRECTIVE_A
1637 dnl 6 = gl_PRINTF_DIRECTIVE_F
1638 dnl 7 = gl_PRINTF_DIRECTIVE_N
1639 dnl 8 = gl_PRINTF_DIRECTIVE_LS
1640 dnl 9 = gl_PRINTF_POSITIONS
1641 dnl 10 = gl_PRINTF_FLAG_GROUPING
1642 dnl 11 = gl_PRINTF_FLAG_LEFTADJUST
1643 dnl 12 = gl_PRINTF_FLAG_ZERO
1644 dnl 13 = gl_PRINTF_PRECISION
1645 dnl 14 = gl_PRINTF_ENOMEM
1646 dnl 15 = gl_SNPRINTF_PRESENCE
1647 dnl 16 = gl_SNPRINTF_TRUNCATION_C99
1648 dnl 17 = gl_SNPRINTF_RETVAL_C99
1649 dnl 18 = gl_SNPRINTF_DIRECTIVE_N
1650 dnl 19 = gl_SNPRINTF_SIZE1
1651 dnl 20 = gl_VSNPRINTF_ZEROSIZE_C99
1652 dnl
1653 dnl 1 = checking whether printf supports size specifiers as in C99...
1654 dnl 2 = checking whether printf supports 'long double' arguments...
1655 dnl 3 = checking whether printf supports infinite 'double' arguments...
1656 dnl 4 = checking whether printf supports infinite 'long double' arguments...
1657 dnl 5 = checking whether printf supports the 'a' and 'A' directives...
1658 dnl 6 = checking whether printf supports the 'F' directive...
1659 dnl 7 = checking whether printf supports the 'n' directive...
1660 dnl 8 = checking whether printf supports the 'ls' directive...
1661 dnl 9 = checking whether printf supports POSIX/XSI format strings with positions...
1662 dnl 10 = checking whether printf supports the grouping flag...
1663 dnl 11 = checking whether printf supports the left-adjust flag correctly...
1664 dnl 12 = checking whether printf supports the zero flag correctly...
1665 dnl 13 = checking whether printf supports large precisions...
1666 dnl 14 = checking whether printf survives out-of-memory conditions...
1667 dnl 15 = checking for snprintf...
1668 dnl 16 = checking whether snprintf truncates the result as in C99...
1669 dnl 17 = checking whether snprintf returns a byte count as in C99...
1670 dnl 18 = checking whether snprintf fully supports the 'n' directive...
1671 dnl 19 = checking whether snprintf respects a size of 1...
1672 dnl 20 = checking whether vsnprintf respects a zero size as in C99...
1673 dnl
1674 dnl . = yes, # = no.
1675 dnl
1676 dnl 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1677 dnl glibc 2.5 . . . . . . . . . . . . . . . . . . . .
1678 dnl glibc 2.3.6 . . . . # . . . . . . . . . . . . . . .
1679 dnl FreeBSD 5.4, 6.1 . . . . # . . . . . . # . # . . . . . .
1680 dnl Mac OS X 10.5.8 . . . # # . . . . . . # . . . . . . . .
1681 dnl Mac OS X 10.3.9 . . . . # . . . . . . # . # . . . . . .
1682 dnl OpenBSD 3.9, 4.0 . . # # # # . # . # . # . # . . . . . .
1683 dnl Cygwin 1.7.0 (2009) . . . # . . . ? . . . . . ? . . . . . .
1684 dnl Cygwin 1.5.25 (2008) . . . # # . . # . . . . . # . . . . . .
1685 dnl Cygwin 1.5.19 (2006) # . . # # # . # . # . # # # . . . . . .
1686 dnl Solaris 11.4 . . # # # . . # . . . # . . . . . . . .
1687 dnl Solaris 11.3 . . . . # . . # . . . . . . . . . . . .
1688 dnl Solaris 11.0 . . # # # . . # . . . # . . . . . . . .
1689 dnl Solaris 10 . . # # # . . # . . . # # . . . . . . .
1690 dnl Solaris 2.6 ... 9 # . # # # # . # . . . # # . . . # . . .
1691 dnl Solaris 2.5.1 # . # # # # . # . . . # . . # # # # # #
1692 dnl AIX 7.1 . . # # # . . . . . . # # . . . . . . .
1693 dnl AIX 5.2 . . # # # . . . . . . # . . . . . . . .
1694 dnl AIX 4.3.2, 5.1 # . # # # # . . . . . # . . . . # . . .
1695 dnl HP-UX 11.31 . . . . # . . . . . . # . . . . # # . .
1696 dnl HP-UX 11.{00,11,23} # . . . # # . . . . . # . . . . # # . #
1697 dnl HP-UX 10.20 # . # . # # . ? . . # # . . . . # # ? #
1698 dnl IRIX 6.5 # . # # # # . # . . . # . . . . # . . .
1699 dnl OSF/1 5.1 # . # # # # . . . . . # . . . . # . . #
1700 dnl OSF/1 4.0d # . # # # # . . . . . # . . # # # # # #
1701 dnl NetBSD 5.0 . . . # # . . . . . . # . # . . . . . .
1702 dnl NetBSD 4.0 . ? ? ? ? ? . ? . ? ? ? ? ? . . . ? ? ?
1703 dnl NetBSD 3.0 . . . . # # . ? # # ? # . # . . . . . .
1704 dnl Haiku . . . # # # . # . . . . . ? . . ? . . .
1705 dnl BeOS # # . # # # . ? # . ? . # ? . . ? . . .
1706 dnl Android 4.3 . . # # # # # # . # . # . # . . . # . .
1707 dnl old mingw / msvcrt # # # # # # . . # # . # # ? . # # # . .
1708 dnl MSVC 9 # # # # # # # . # # . # # ? # # # # . .
1709 dnl mingw 2009-2011 . # . # . . . . # # . . . ? . . . . . .
1710 dnl mingw-w64 2011 # # # # # # . . # # . # # ? . # # # . .