Debian Codegraph @

m4/printf.m4

raw
1 # printf.m4 serial 84
2 dnl Copyright (C) 2003, 2007-2023 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* | midipix*) 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 midnightbsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
71 # Guess yes on Mac OS X >= 10.3.
72 darwin[1-6].*) gl_cv_func_printf_sizes_c99="guessing no";;
73 darwin*) gl_cv_func_printf_sizes_c99="guessing yes";;
74 # Guess yes on OpenBSD >= 3.9.
75 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
76 gl_cv_func_printf_sizes_c99="guessing no";;
77 openbsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
78 # Guess yes on Solaris >= 2.10.
79 solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";;
80 solaris*) gl_cv_func_printf_sizes_c99="guessing no";;
81 # Guess yes on NetBSD >= 3.
82 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
83 gl_cv_func_printf_sizes_c99="guessing no";;
84 netbsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
85 # Guess yes on Android.
86 linux*-android*) gl_cv_func_printf_sizes_c99="guessing yes";;
87 changequote([,])dnl
88 # Guess yes on MSVC, no on mingw.
89 mingw*) AC_EGREP_CPP([Known], [
90 #ifdef _MSC_VER
91 Known
92 #endif
93 ],
94 [gl_cv_func_printf_sizes_c99="guessing yes"],
95 [gl_cv_func_printf_sizes_c99="guessing no"])
96 ;;
97 # If we don't know, obey --enable-cross-guesses.
98 *) gl_cv_func_printf_sizes_c99="$gl_cross_guess_normal";;
99 esac
100 ])
101 ])
102 ])
103
104 dnl Test whether the *printf family of functions supports the 'w8', 'w16',
105 dnl 'w32', 'w64', 'wf8', 'wf16', 'wf32', 'wf64' size specifiers. (ISO C23)
106 dnl Result is gl_cv_func_printf_sizes_c23.
107
108 AC_DEFUN([gl_PRINTF_SIZES_C23],
109 [
110 AC_REQUIRE([AC_PROG_CC])
111 AC_REQUIRE([gl_AC_HEADER_STDINT_H])
112 AC_REQUIRE([gl_AC_HEADER_INTTYPES_H])
113 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
114 AC_CACHE_CHECK([whether printf supports size specifiers as in C23],
115 [gl_cv_func_printf_sizes_c23],
116 [
117 AC_RUN_IFELSE(
118 [AC_LANG_SOURCE([[
119 #include <stddef.h>
120 #include <stdio.h>
121 #include <string.h>
122 #include <sys/types.h>
123 #if HAVE_STDINT_H_WITH_UINTMAX
124 # include <stdint.h>
125 #endif
126 #if HAVE_INTTYPES_H_WITH_UINTMAX
127 # include <inttypes.h>
128 #endif
129 static char buf[100];
130 int main ()
131 {
132 int result = 0;
133 buf[0] = '\0';
134 if (sprintf (buf, "%w8u %d", (uint8_t) 123, 33, 44, 55) < 0
135 || strcmp (buf, "123 33") != 0)
136 result |= 1;
137 buf[0] = '\0';
138 if (sprintf (buf, "%wf8u %d", (uint_fast8_t) 123, 33, 44, 55) < 0
139 || strcmp (buf, "123 33") != 0)
140 result |= 1;
141 buf[0] = '\0';
142 if (sprintf (buf, "%w16u %d", (uint16_t) 12345, 33, 44, 55) < 0
143 || strcmp (buf, "12345 33") != 0)
144 result |= 2;
145 buf[0] = '\0';
146 if (sprintf (buf, "%wf16u %d", (uint_fast16_t) 12345, 33, 44, 55) < 0
147 || strcmp (buf, "12345 33") != 0)
148 result |= 2;
149 buf[0] = '\0';
150 if (sprintf (buf, "%w32u %d", (uint32_t) 12345671, 33, 44, 55) < 0
151 || strcmp (buf, "12345671 33") != 0)
152 result |= 4;
153 buf[0] = '\0';
154 if (sprintf (buf, "%wf32u %d", (uint_fast32_t) 12345671, 33, 44, 55) < 0
155 || strcmp (buf, "12345671 33") != 0)
156 result |= 4;
157 #if HAVE_STDINT_H_WITH_UINTMAX || HAVE_INTTYPES_H_WITH_UINTMAX
158 buf[0] = '\0';
159 if (sprintf (buf, "%w64u %d", (uint64_t) 12345671, 33, 44, 55) < 0
160 || strcmp (buf, "12345671 33") != 0)
161 result |= 8;
162 buf[0] = '\0';
163 if (sprintf (buf, "%wf64u %d", (uint_fast64_t) 12345671, 33, 44, 55) < 0
164 || strcmp (buf, "12345671 33") != 0)
165 result |= 8;
166 #else
167 result |= 8;
168 #endif
169 return result;
170 }]])],
171 [gl_cv_func_printf_sizes_c23=yes],
172 [gl_cv_func_printf_sizes_c23=no],
173 [
174 case "$host_os" in
175 # Guess no on glibc systems.
176 *-gnu* | gnu*) gl_cv_func_printf_sizes_c23="guessing no";;
177 # Guess no on musl systems.
178 *-musl* | midipix*) gl_cv_func_printf_sizes_c23="guessing no";;
179 # Guess no on Android.
180 linux*-android*) gl_cv_func_printf_sizes_c23="guessing no";;
181 # Guess no on native Windows.
182 mingw*) gl_cv_func_printf_sizes_c23="guessing no";;
183 # If we don't know, obey --enable-cross-guesses.
184 *) gl_cv_func_printf_sizes_c23="$gl_cross_guess_normal";;
185 esac
186 ])
187 ])
188 ])
189
190 dnl Test whether the *printf family of functions supports 'long double'
191 dnl arguments together with the 'L' size specifier. (ISO C99, POSIX:2001)
192 dnl Result is gl_cv_func_printf_long_double.
193
194 AC_DEFUN([gl_PRINTF_LONG_DOUBLE],
195 [
196 AC_REQUIRE([AC_PROG_CC])
197 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
198 AC_CACHE_CHECK([whether printf supports 'long double' arguments],
199 [gl_cv_func_printf_long_double],
200 [
201 AC_RUN_IFELSE(
202 [AC_LANG_SOURCE([[
203 #include <stdio.h>
204 #include <string.h>
205 static char buf[10000];
206 int main ()
207 {
208 int result = 0;
209 buf[0] = '\0';
210 if (sprintf (buf, "%Lf %d", 1.75L, 33, 44, 55) < 0
211 || strcmp (buf, "1.750000 33") != 0)
212 result |= 1;
213 buf[0] = '\0';
214 if (sprintf (buf, "%Le %d", 1.75L, 33, 44, 55) < 0
215 || strcmp (buf, "1.750000e+00 33") != 0)
216 result |= 2;
217 buf[0] = '\0';
218 if (sprintf (buf, "%Lg %d", 1.75L, 33, 44, 55) < 0
219 || strcmp (buf, "1.75 33") != 0)
220 result |= 4;
221 return result;
222 }]])],
223 [gl_cv_func_printf_long_double=yes],
224 [gl_cv_func_printf_long_double=no],
225 [case "$host_os" in
226 # Guess no on BeOS.
227 beos*) gl_cv_func_printf_long_double="guessing no";;
228 # Guess yes on Android.
229 linux*-android*) gl_cv_func_printf_long_double="guessing yes";;
230 # Guess yes on MSVC, no on mingw.
231 mingw*) AC_EGREP_CPP([Known], [
232 #ifdef _MSC_VER
233 Known
234 #endif
235 ],
236 [gl_cv_func_printf_long_double="guessing yes"],
237 [gl_cv_func_printf_long_double="guessing no"])
238 ;;
239 *) gl_cv_func_printf_long_double="guessing yes";;
240 esac
241 ])
242 ])
243 ])
244
245 dnl Test whether the *printf family of functions supports infinite and NaN
246 dnl 'double' arguments and negative zero arguments in the %f, %e, %g
247 dnl directives. (ISO C99, POSIX:2001)
248 dnl Result is gl_cv_func_printf_infinite.
249
250 AC_DEFUN([gl_PRINTF_INFINITE],
251 [
252 AC_REQUIRE([AC_PROG_CC])
253 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
254 AC_CACHE_CHECK([whether printf supports infinite 'double' arguments],
255 [gl_cv_func_printf_infinite],
256 [
257 AC_RUN_IFELSE(
258 [AC_LANG_SOURCE([[
259 #include <stdio.h>
260 #include <string.h>
261 static int
262 strisnan (const char *string, size_t start_index, size_t end_index)
263 {
264 if (start_index < end_index)
265 {
266 if (string[start_index] == '-')
267 start_index++;
268 if (start_index + 3 <= end_index
269 && memcmp (string + start_index, "nan", 3) == 0)
270 {
271 start_index += 3;
272 if (start_index == end_index
273 || (string[start_index] == '(' && string[end_index - 1] == ')'))
274 return 1;
275 }
276 }
277 return 0;
278 }
279 static int
280 have_minus_zero ()
281 {
282 static double plus_zero = 0.0;
283 double minus_zero = - plus_zero;
284 return memcmp (&plus_zero, &minus_zero, sizeof (double)) != 0;
285 }
286 static char buf[10000];
287 static double zero = 0.0;
288 int main ()
289 {
290 int result = 0;
291 if (sprintf (buf, "%f", 1.0 / zero) < 0
292 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
293 result |= 1;
294 if (sprintf (buf, "%f", -1.0 / zero) < 0
295 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
296 result |= 1;
297 if (sprintf (buf, "%f", zero / zero) < 0
298 || !strisnan (buf, 0, strlen (buf)))
299 result |= 2;
300 if (sprintf (buf, "%e", 1.0 / zero) < 0
301 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
302 result |= 4;
303 if (sprintf (buf, "%e", -1.0 / zero) < 0
304 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
305 result |= 4;
306 if (sprintf (buf, "%e", zero / zero) < 0
307 || !strisnan (buf, 0, strlen (buf)))
308 result |= 8;
309 if (sprintf (buf, "%g", 1.0 / zero) < 0
310 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
311 result |= 16;
312 if (sprintf (buf, "%g", -1.0 / zero) < 0
313 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
314 result |= 16;
315 if (sprintf (buf, "%g", zero / zero) < 0
316 || !strisnan (buf, 0, strlen (buf)))
317 result |= 32;
318 /* This test fails on HP-UX 10.20. */
319 if (have_minus_zero ())
320 if (sprintf (buf, "%g", - zero) < 0
321 || strcmp (buf, "-0") != 0)
322 result |= 64;
323 return result;
324 }]])],
325 [gl_cv_func_printf_infinite=yes],
326 [gl_cv_func_printf_infinite=no],
327 [
328 case "$host_os" in
329 changequote(,)dnl
330 # Guess yes on glibc systems.
331 *-gnu* | gnu*) gl_cv_func_printf_infinite="guessing yes";;
332 # Guess yes on musl systems.
333 *-musl* | midipix*) gl_cv_func_printf_infinite="guessing yes";;
334 # Guess yes on FreeBSD >= 6.
335 freebsd[1-5].*) gl_cv_func_printf_infinite="guessing no";;
336 freebsd* | kfreebsd*) gl_cv_func_printf_infinite="guessing yes";;
337 midnightbsd*) gl_cv_func_printf_infinite="guessing yes";;
338 # Guess yes on Mac OS X >= 10.3.
339 darwin[1-6].*) gl_cv_func_printf_infinite="guessing no";;
340 darwin*) gl_cv_func_printf_infinite="guessing yes";;
341 # Guess yes on HP-UX >= 11.
342 hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite="guessing no";;
343 hpux*) gl_cv_func_printf_infinite="guessing yes";;
344 # Guess yes on NetBSD >= 3.
345 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
346 gl_cv_func_printf_infinite="guessing no";;
347 netbsd*) gl_cv_func_printf_infinite="guessing yes";;
348 # Guess yes on OpenBSD >= 6.0.
349 openbsd[1-5].*) gl_cv_func_printf_infinite="guessing no";;
350 openbsd*) gl_cv_func_printf_infinite="guessing yes";;
351 # Guess yes on BeOS.
352 beos*) gl_cv_func_printf_infinite="guessing yes";;
353 # Guess no on Android.
354 linux*-android*) gl_cv_func_printf_infinite="guessing no";;
355 changequote([,])dnl
356 # Guess yes on MSVC, no on mingw.
357 mingw*) AC_EGREP_CPP([Known], [
358 #ifdef _MSC_VER
359 Known
360 #endif
361 ],
362 [gl_cv_func_printf_infinite="guessing yes"],
363 [gl_cv_func_printf_infinite="guessing no"])
364 ;;
365 # If we don't know, obey --enable-cross-guesses.
366 *) gl_cv_func_printf_infinite="$gl_cross_guess_normal";;
367 esac
368 ])
369 ])
370 ])
371
372 dnl Test whether the *printf family of functions supports infinite and NaN
373 dnl 'long double' arguments in the %f, %e, %g directives. (ISO C99, POSIX:2001)
374 dnl Result is gl_cv_func_printf_infinite_long_double.
375
376 AC_DEFUN([gl_PRINTF_INFINITE_LONG_DOUBLE],
377 [
378 AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
379 AC_REQUIRE([AC_PROG_CC])
380 AC_REQUIRE([gl_BIGENDIAN])
381 AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
382 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
383 dnl The user can set or unset the variable gl_printf_safe to indicate
384 dnl that he wishes a safe handling of non-IEEE-754 'long double' values.
385 if test -n "$gl_printf_safe"; then
386 AC_DEFINE([CHECK_PRINTF_SAFE], [1],
387 [Define if you wish *printf() functions that have a safe handling of
388 non-IEEE-754 'long double' values.])
389 fi
390 case "$gl_cv_func_printf_long_double" in
391 *yes)
392 AC_CACHE_CHECK([whether printf supports infinite 'long double' arguments],
393 [gl_cv_func_printf_infinite_long_double],
394 [
395 AC_RUN_IFELSE(
396 [AC_LANG_SOURCE([[
397 ]GL_NOCRASH[
398 #include <float.h>
399 #include <stdio.h>
400 #include <string.h>
401 static int
402 strisnan (const char *string, size_t start_index, size_t end_index)
403 {
404 if (start_index < end_index)
405 {
406 if (string[start_index] == '-')
407 start_index++;
408 if (start_index + 3 <= end_index
409 && memcmp (string + start_index, "nan", 3) == 0)
410 {
411 start_index += 3;
412 if (start_index == end_index
413 || (string[start_index] == '(' && string[end_index - 1] == ')'))
414 return 1;
415 }
416 }
417 return 0;
418 }
419 static char buf[10000];
420 static long double zeroL = 0.0L;
421 int main ()
422 {
423 int result = 0;
424 nocrash_init();
425 if (sprintf (buf, "%Lf", 1.0L / zeroL) < 0
426 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
427 result |= 1;
428 if (sprintf (buf, "%Lf", -1.0L / zeroL) < 0
429 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
430 result |= 1;
431 if (sprintf (buf, "%Lf", zeroL / zeroL) < 0
432 || !strisnan (buf, 0, strlen (buf)))
433 result |= 1;
434 if (sprintf (buf, "%Le", 1.0L / zeroL) < 0
435 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
436 result |= 1;
437 if (sprintf (buf, "%Le", -1.0L / zeroL) < 0
438 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
439 result |= 1;
440 if (sprintf (buf, "%Le", zeroL / zeroL) < 0
441 || !strisnan (buf, 0, strlen (buf)))
442 result |= 1;
443 if (sprintf (buf, "%Lg", 1.0L / zeroL) < 0
444 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
445 result |= 1;
446 if (sprintf (buf, "%Lg", -1.0L / zeroL) < 0
447 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
448 result |= 1;
449 if (sprintf (buf, "%Lg", zeroL / zeroL) < 0
450 || !strisnan (buf, 0, strlen (buf)))
451 result |= 1;
452 #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
453 /* Representation of an 80-bit 'long double' as an initializer for a sequence
454 of 'unsigned int' words. */
455 # ifdef WORDS_BIGENDIAN
456 # define LDBL80_WORDS(exponent,manthi,mantlo) \
457 { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
458 ((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16), \
459 (unsigned int) (mantlo) << 16 \
460 }
461 # else
462 # define LDBL80_WORDS(exponent,manthi,mantlo) \
463 { mantlo, manthi, exponent }
464 # endif
465 { /* Quiet NaN. */
466 static union { unsigned int word[4]; long double value; } x =
467 { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
468 if (sprintf (buf, "%Lf", x.value) < 0
469 || !strisnan (buf, 0, strlen (buf)))
470 result |= 2;
471 if (sprintf (buf, "%Le", x.value) < 0
472 || !strisnan (buf, 0, strlen (buf)))
473 result |= 2;
474 if (sprintf (buf, "%Lg", x.value) < 0
475 || !strisnan (buf, 0, strlen (buf)))
476 result |= 2;
477 }
478 {
479 /* Signalling NaN. */
480 static union { unsigned int word[4]; long double value; } x =
481 { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
482 if (sprintf (buf, "%Lf", x.value) < 0
483 || !strisnan (buf, 0, strlen (buf)))
484 result |= 2;
485 if (sprintf (buf, "%Le", x.value) < 0
486 || !strisnan (buf, 0, strlen (buf)))
487 result |= 2;
488 if (sprintf (buf, "%Lg", x.value) < 0
489 || !strisnan (buf, 0, strlen (buf)))
490 result |= 2;
491 }
492 { /* Pseudo-NaN. */
493 static union { unsigned int word[4]; long double value; } x =
494 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
495 if (sprintf (buf, "%Lf", x.value) <= 0)
496 result |= 4;
497 if (sprintf (buf, "%Le", x.value) <= 0)
498 result |= 4;
499 if (sprintf (buf, "%Lg", x.value) <= 0)
500 result |= 4;
501 }
502 { /* Pseudo-Infinity. */
503 static union { unsigned int word[4]; long double value; } x =
504 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
505 if (sprintf (buf, "%Lf", x.value) <= 0)
506 result |= 8;
507 if (sprintf (buf, "%Le", x.value) <= 0)
508 result |= 8;
509 if (sprintf (buf, "%Lg", x.value) <= 0)
510 result |= 8;
511 }
512 { /* Pseudo-Zero. */
513 static union { unsigned int word[4]; long double value; } x =
514 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
515 if (sprintf (buf, "%Lf", x.value) <= 0)
516 result |= 16;
517 if (sprintf (buf, "%Le", x.value) <= 0)
518 result |= 16;
519 if (sprintf (buf, "%Lg", x.value) <= 0)
520 result |= 16;
521 }
522 { /* Unnormalized number. */
523 static union { unsigned int word[4]; long double value; } x =
524 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
525 if (sprintf (buf, "%Lf", x.value) <= 0)
526 result |= 32;
527 if (sprintf (buf, "%Le", x.value) <= 0)
528 result |= 32;
529 if (sprintf (buf, "%Lg", x.value) <= 0)
530 result |= 32;
531 }
532 { /* Pseudo-Denormal. */
533 static union { unsigned int word[4]; long double value; } x =
534 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
535 if (sprintf (buf, "%Lf", x.value) <= 0)
536 result |= 64;
537 if (sprintf (buf, "%Le", x.value) <= 0)
538 result |= 64;
539 if (sprintf (buf, "%Lg", x.value) <= 0)
540 result |= 64;
541 }
542 #endif
543 return result;
544 }]])],
545 [gl_cv_func_printf_infinite_long_double=yes],
546 [gl_cv_func_printf_infinite_long_double=no],
547 [case "$host_cpu" in
548 # Guess no on ia64, x86_64, i386.
549 ia64 | x86_64 | i*86) gl_cv_func_printf_infinite_long_double="guessing no";;
550 *)
551 case "$host_os" in
552 changequote(,)dnl
553 # Guess yes on glibc systems.
554 *-gnu* | gnu*) gl_cv_func_printf_infinite_long_double="guessing yes";;
555 # Guess yes on musl systems.
556 *-musl* | midipix*) gl_cv_func_printf_infinite_long_double="guessing yes";;
557 # Guess yes on FreeBSD >= 6.
558 freebsd[1-5].*) gl_cv_func_printf_infinite_long_double="guessing no";;
559 freebsd* | kfreebsd*) gl_cv_func_printf_infinite_long_double="guessing yes";;
560 midnightbsd*) gl_cv_func_printf_infinite_long_double="guessing yes";;
561 # Guess yes on HP-UX >= 11.
562 hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite_long_double="guessing no";;
563 hpux*) gl_cv_func_printf_infinite_long_double="guessing yes";;
564 # Guess yes on OpenBSD >= 6.0.
565 openbsd[1-5].*) gl_cv_func_printf_infinite_long_double="guessing no";;
566 openbsd*) gl_cv_func_printf_infinite_long_double="guessing yes";;
567 # Guess no on Android.
568 linux*-android*) gl_cv_func_printf_infinite_long_double="guessing no";;
569 changequote([,])dnl
570 # Guess yes on MSVC, no on mingw.
571 mingw*) AC_EGREP_CPP([Known], [
572 #ifdef _MSC_VER
573 Known
574 #endif
575 ],
576 [gl_cv_func_printf_infinite_long_double="guessing yes"],
577 [gl_cv_func_printf_infinite_long_double="guessing no"])
578 ;;
579 # If we don't know, obey --enable-cross-guesses.
580 *) gl_cv_func_printf_infinite_long_double="$gl_cross_guess_normal";;
581 esac
582 ;;
583 esac
584 ])
585 ])
586 ;;
587 *)
588 gl_cv_func_printf_infinite_long_double="irrelevant"
589 ;;
590 esac
591 ])
592
593 dnl Test whether the *printf family of functions supports the 'a' and 'A'
594 dnl conversion specifier for hexadecimal output of floating-point numbers.
595 dnl (ISO C99, POSIX:2001)
596 dnl Result is gl_cv_func_printf_directive_a.
597
598 AC_DEFUN([gl_PRINTF_DIRECTIVE_A],
599 [
600 AC_REQUIRE([AC_PROG_CC])
601 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
602 AC_CACHE_CHECK([whether printf supports the 'a' and 'A' directives],
603 [gl_cv_func_printf_directive_a],
604 [
605 AC_RUN_IFELSE(
606 [AC_LANG_SOURCE([[
607 #include <stdio.h>
608 #include <string.h>
609 static char buf[100];
610 static double zero = 0.0;
611 int main ()
612 {
613 int result = 0;
614 if (sprintf (buf, "%a %d", 3.1416015625, 33, 44, 55) < 0
615 || (strcmp (buf, "0x1.922p+1 33") != 0
616 && strcmp (buf, "0x3.244p+0 33") != 0
617 && strcmp (buf, "0x6.488p-1 33") != 0
618 && strcmp (buf, "0xc.91p-2 33") != 0))
619 result |= 1;
620 if (sprintf (buf, "%A %d", -3.1416015625, 33, 44, 55) < 0
621 || (strcmp (buf, "-0X1.922P+1 33") != 0
622 && strcmp (buf, "-0X3.244P+0 33") != 0
623 && strcmp (buf, "-0X6.488P-1 33") != 0
624 && strcmp (buf, "-0XC.91P-2 33") != 0))
625 result |= 2;
626 /* This catches a FreeBSD 13.0 bug: it doesn't round. */
627 if (sprintf (buf, "%.2a %d", 1.51, 33, 44, 55) < 0
628 || (strcmp (buf, "0x1.83p+0 33") != 0
629 && strcmp (buf, "0x3.05p-1 33") != 0
630 && strcmp (buf, "0x6.0ap-2 33") != 0
631 && strcmp (buf, "0xc.14p-3 33") != 0))
632 result |= 4;
633 /* This catches a Mac OS X 10.12.4 (Darwin 16.5) bug: it doesn't round. */
634 if (sprintf (buf, "%.0a %d", 1.51, 33, 44, 55) < 0
635 || (strcmp (buf, "0x2p+0 33") != 0
636 && strcmp (buf, "0x3p-1 33") != 0
637 && strcmp (buf, "0x6p-2 33") != 0
638 && strcmp (buf, "0xcp-3 33") != 0))
639 result |= 4;
640 /* This catches a FreeBSD 6.1 bug. See
641 <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */
642 if (sprintf (buf, "%010a %d", 1.0 / zero, 33, 44, 55) < 0
643 || buf[0] == '0')
644 result |= 8;
645 /* This catches a Mac OS X 10.3.9 (Darwin 7.9) bug. */
646 if (sprintf (buf, "%.1a", 1.999) < 0
647 || (strcmp (buf, "0x1.0p+1") != 0
648 && strcmp (buf, "0x2.0p+0") != 0
649 && strcmp (buf, "0x4.0p-1") != 0
650 && strcmp (buf, "0x8.0p-2") != 0))
651 result |= 16;
652 /* This catches the same Mac OS X 10.3.9 (Darwin 7.9) bug and also a
653 glibc 2.4 bug <https://sourceware.org/bugzilla/show_bug.cgi?id=2908>. */
654 if (sprintf (buf, "%.1La", 1.999L) < 0
655 || (strcmp (buf, "0x1.0p+1") != 0
656 && strcmp (buf, "0x2.0p+0") != 0
657 && strcmp (buf, "0x4.0p-1") != 0
658 && strcmp (buf, "0x8.0p-2") != 0))
659 result |= 32;
660 return result;
661 }]])],
662 [gl_cv_func_printf_directive_a=yes],
663 [gl_cv_func_printf_directive_a=no],
664 [
665 case "$host_os" in
666 # Guess yes on glibc >= 2.5 systems.
667 *-gnu* | gnu*)
668 AC_EGREP_CPP([BZ2908], [
669 #include <features.h>
670 #ifdef __GNU_LIBRARY__
671 #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 5) || (__GLIBC__ > 2)) && !defined __UCLIBC__
672 BZ2908
673 #endif
674 #endif
675 ],
676 [gl_cv_func_printf_directive_a="guessing yes"],
677 [gl_cv_func_printf_directive_a="guessing no"])
678 ;;
679 # Guess yes on musl systems.
680 *-musl* | midipix*) gl_cv_func_printf_directive_a="guessing yes";;
681 # Guess no on Android.
682 linux*-android*) gl_cv_func_printf_directive_a="guessing no";;
683 # Guess no on native Windows.
684 mingw*) gl_cv_func_printf_directive_a="guessing no";;
685 # If we don't know, obey --enable-cross-guesses.
686 *) gl_cv_func_printf_directive_a="$gl_cross_guess_normal";;
687 esac
688 ])
689 ])
690 ])
691
692 dnl Test whether the *printf family of functions supports the 'b' conversion
693 dnl specifier for binary output of integers.
694 dnl (ISO C23)
695 dnl Result is gl_cv_func_printf_directive_b.
696
697 AC_DEFUN([gl_PRINTF_DIRECTIVE_B],
698 [
699 AC_REQUIRE([AC_PROG_CC])
700 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
701 AC_CACHE_CHECK([whether printf supports the 'b' directive],
702 [gl_cv_func_printf_directive_b],
703 [
704 AC_RUN_IFELSE(
705 [AC_LANG_SOURCE([[
706 #include <stdio.h>
707 #include <string.h>
708 static char buf[100];
709 int main ()
710 {
711 int result = 0;
712 if (sprintf (buf, "%b %d", 12345, 33, 44, 55) < 0
713 || strcmp (buf, "11000000111001 33") != 0)
714 result |= 1;
715 return result;
716 }]])],
717 [gl_cv_func_printf_directive_b=yes],
718 [gl_cv_func_printf_directive_b=no],
719 [
720 case "$host_os" in
721 # Guess yes on glibc >= 2.35 systems.
722 *-gnu* | gnu*)
723 AC_EGREP_CPP([Lucky], [
724 #include <features.h>
725 #ifdef __GNU_LIBRARY__
726 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 35) || (__GLIBC__ > 2)
727 Lucky user
728 #endif
729 #endif
730 ],
731 [gl_cv_func_printf_directive_uppercase_b="guessing yes"],
732 [gl_cv_func_printf_directive_uppercase_b="guessing no"])
733 ;;
734 # Guess no on musl systems.
735 *-musl* | midipix*) gl_cv_func_printf_directive_b="guessing no";;
736 # Guess no on Android.
737 linux*-android*) gl_cv_func_printf_directive_b="guessing no";;
738 # Guess no on native Windows.
739 mingw*) gl_cv_func_printf_directive_b="guessing no";;
740 # If we don't know, obey --enable-cross-guesses.
741 *) gl_cv_func_printf_directive_b="$gl_cross_guess_normal";;
742 esac
743 ])
744 ])
745 ])
746
747 dnl Test whether the *printf family of functions supports the 'B' conversion
748 dnl specifier for binary output of integers.
749 dnl (GNU, encouraged by ISO C23 § 7.23.6.1)
750 dnl Result is gl_cv_func_printf_directive_uppercase_b.
751
752 AC_DEFUN([gl_PRINTF_DIRECTIVE_UPPERCASE_B],
753 [
754 AC_REQUIRE([AC_PROG_CC])
755 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
756 AC_CACHE_CHECK([whether printf supports the 'B' directive],
757 [gl_cv_func_printf_directive_uppercase_b],
758 [
759 AC_RUN_IFELSE(
760 [AC_LANG_SOURCE([[
761 #include <stdio.h>
762 #include <string.h>
763 static char buf[100];
764 int main ()
765 {
766 int result = 0;
767 if (sprintf (buf, "%#B %d", 12345, 33, 44, 55) < 0
768 || strcmp (buf, "0B11000000111001 33") != 0)
769 result |= 1;
770 return result;
771 }]])],
772 [gl_cv_func_printf_directive_uppercase_b=yes],
773 [gl_cv_func_printf_directive_uppercase_b=no],
774 [
775 case "$host_os" in
776 # Guess yes on glibc >= 2.35 systems.
777 *-gnu* | gnu*)
778 AC_EGREP_CPP([Lucky], [
779 #include <features.h>
780 #ifdef __GNU_LIBRARY__
781 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 35) || (__GLIBC__ > 2)
782 Lucky user
783 #endif
784 #endif
785 ],
786 [gl_cv_func_printf_directive_uppercase_b="guessing yes"],
787 [gl_cv_func_printf_directive_uppercase_b="guessing no"])
788 ;;
789 # Guess no on musl systems.
790 *-musl* | midipix*) gl_cv_func_printf_directive_uppercase_b="guessing no";;
791 # Guess no on Android.
792 linux*-android*) gl_cv_func_printf_directive_uppercase_b="guessing no";;
793 # Guess no on native Windows.
794 mingw*) gl_cv_func_printf_directive_uppercase_b="guessing no";;
795 # If we don't know, obey --enable-cross-guesses.
796 *) gl_cv_func_printf_directive_uppercase_b="$gl_cross_guess_normal";;
797 esac
798 ])
799 ])
800 ])
801
802 dnl Test whether the *printf family of functions supports the %F format
803 dnl directive. (ISO C99, POSIX:2001)
804 dnl Result is gl_cv_func_printf_directive_f.
805
806 AC_DEFUN([gl_PRINTF_DIRECTIVE_F],
807 [
808 AC_REQUIRE([AC_PROG_CC])
809 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
810 AC_CACHE_CHECK([whether printf supports the 'F' directive],
811 [gl_cv_func_printf_directive_f],
812 [
813 AC_RUN_IFELSE(
814 [AC_LANG_SOURCE([[
815 #include <stdio.h>
816 #include <string.h>
817 static char buf[100];
818 static double zero = 0.0;
819 int main ()
820 {
821 int result = 0;
822 if (sprintf (buf, "%F %d", 1234567.0, 33, 44, 55) < 0
823 || strcmp (buf, "1234567.000000 33") != 0)
824 result |= 1;
825 if (sprintf (buf, "%F", 1.0 / zero) < 0
826 || (strcmp (buf, "INF") != 0 && strcmp (buf, "INFINITY") != 0))
827 result |= 2;
828 /* This catches a Cygwin 1.5.x bug. */
829 if (sprintf (buf, "%.F", 1234.0) < 0
830 || strcmp (buf, "1234") != 0)
831 result |= 4;
832 return result;
833 }]])],
834 [gl_cv_func_printf_directive_f=yes],
835 [gl_cv_func_printf_directive_f=no],
836 [
837 case "$host_os" in
838 changequote(,)dnl
839 # Guess yes on glibc systems.
840 *-gnu* | gnu*) gl_cv_func_printf_directive_f="guessing yes";;
841 # Guess yes on musl systems.
842 *-musl* | midipix*) gl_cv_func_printf_directive_f="guessing yes";;
843 # Guess yes on FreeBSD >= 6.
844 freebsd[1-5].*) gl_cv_func_printf_directive_f="guessing no";;
845 freebsd* | kfreebsd*) gl_cv_func_printf_directive_f="guessing yes";;
846 midnightbsd*) gl_cv_func_printf_directive_f="guessing yes";;
847 # Guess yes on Mac OS X >= 10.3.
848 darwin[1-6].*) gl_cv_func_printf_directive_f="guessing no";;
849 darwin*) gl_cv_func_printf_directive_f="guessing yes";;
850 # Guess yes on OpenBSD >= 6.0.
851 openbsd[1-5].*) gl_cv_func_printf_directive_f="guessing no";;
852 openbsd*) gl_cv_func_printf_directive_f="guessing yes";;
853 # Guess yes on Solaris >= 2.10.
854 solaris2.[1-9][0-9]*) gl_cv_func_printf_directive_f="guessing yes";;
855 solaris*) gl_cv_func_printf_directive_f="guessing no";;
856 # Guess no on Android.
857 linux*-android*) gl_cv_func_printf_directive_f="guessing no";;
858 changequote([,])dnl
859 # Guess yes on MSVC, no on mingw.
860 mingw*) AC_EGREP_CPP([Known], [
861 #ifdef _MSC_VER
862 Known
863 #endif
864 ],
865 [gl_cv_func_printf_directive_f="guessing yes"],
866 [gl_cv_func_printf_directive_f="guessing no"])
867 ;;
868 # If we don't know, obey --enable-cross-guesses.
869 *) gl_cv_func_printf_directive_f="$gl_cross_guess_normal";;
870 esac
871 ])
872 ])
873 ])
874
875 dnl Test whether the *printf family of functions supports the %n format
876 dnl directive. (ISO C99, POSIX:2001)
877 dnl Result is gl_cv_func_printf_directive_n.
878
879 AC_DEFUN([gl_PRINTF_DIRECTIVE_N],
880 [
881 AC_REQUIRE([AC_PROG_CC])
882 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
883 AC_CACHE_CHECK([whether printf supports the 'n' directive],
884 [gl_cv_func_printf_directive_n],
885 [
886 AC_RUN_IFELSE(
887 [AC_LANG_SOURCE([[
888 #include <stdio.h>
889 #include <stdlib.h>
890 #include <string.h>
891 #ifdef _MSC_VER
892 #include <inttypes.h>
893 /* See page about "Parameter Validation" on msdn.microsoft.com.
894 <https://docs.microsoft.com/en-us/cpp/c-runtime-library/parameter-validation>
895 <https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/set-invalid-parameter-handler-set-thread-local-invalid-parameter-handler> */
896 static void cdecl
897 invalid_parameter_handler (const wchar_t *expression,
898 const wchar_t *function,
899 const wchar_t *file, unsigned int line,
900 uintptr_t dummy)
901 {
902 exit (1);
903 }
904 #endif
905 static char fmtstring[10];
906 static char buf[100];
907 int main ()
908 {
909 int count = -1;
910 #ifdef _MSC_VER
911 _set_invalid_parameter_handler (invalid_parameter_handler);
912 #endif
913 /* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2)
914 support %n in format strings in read-only memory but not in writable
915 memory. */
916 strcpy (fmtstring, "%d %n");
917 if (sprintf (buf, fmtstring, 123, &count, 33, 44, 55) < 0
918 || strcmp (buf, "123 ") != 0
919 || count != 4)
920 return 1;
921 return 0;
922 }]])],
923 [gl_cv_func_printf_directive_n=yes],
924 [gl_cv_func_printf_directive_n=no],
925 [case "$host_os" in
926 # Guess no on glibc when _FORTIFY_SOURCE >= 2.
927 *-gnu* | gnu*) AC_COMPILE_IFELSE(
928 [AC_LANG_SOURCE(
929 [[#if _FORTIFY_SOURCE >= 2
930 error fail
931 #endif
932 ]])],
933 [gl_cv_func_printf_directive_n="guessing yes"],
934 [gl_cv_func_printf_directive_n="guessing no"])
935 ;;
936 # Guess no on Android.
937 linux*-android*) gl_cv_func_printf_directive_n="guessing no";;
938 # Guess no on native Windows.
939 mingw*) gl_cv_func_printf_directive_n="guessing no";;
940 *) gl_cv_func_printf_directive_n="guessing yes";;
941 esac
942 ])
943 ])
944 ])
945
946 dnl Test whether the *printf family of functions supports the %ls format
947 dnl directive and in particular, when a precision is specified, whether
948 dnl the functions stop converting the wide string argument when the number
949 dnl of bytes that have been produced by this conversion equals or exceeds
950 dnl the precision.
951 dnl Result is gl_cv_func_printf_directive_ls.
952
953 AC_DEFUN([gl_PRINTF_DIRECTIVE_LS],
954 [
955 AC_REQUIRE([AC_PROG_CC])
956 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
957 AC_CACHE_CHECK([whether printf supports the 'ls' directive],
958 [gl_cv_func_printf_directive_ls],
959 [
960 AC_RUN_IFELSE(
961 [AC_LANG_SOURCE([[
962 #include <stdio.h>
963 #include <wchar.h>
964 #include <string.h>
965 int main ()
966 {
967 int result = 0;
968 char buf[100];
969 /* Test whether %ls works at all.
970 This test fails on OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku, but not on
971 Cygwin 1.5. */
972 {
973 static const wchar_t wstring[] = { 'a', 'b', 'c', 0 };
974 buf[0] = '\0';
975 if (sprintf (buf, "%ls", wstring) < 0
976 || strcmp (buf, "abc") != 0)
977 result |= 1;
978 }
979 /* This test fails on IRIX 6.5, Solaris 2.6, Cygwin 1.5, Haiku (with an
980 assertion failure inside libc), but not on OpenBSD 4.0. */
981 {
982 static const wchar_t wstring[] = { 'a', 0 };
983 buf[0] = '\0';
984 if (sprintf (buf, "%ls", wstring) < 0
985 || strcmp (buf, "a") != 0)
986 result |= 2;
987 }
988 /* Test whether precisions in %ls are supported as specified in ISO C 99
989 section 7.19.6.1:
990 "If a precision is specified, no more than that many bytes are written
991 (including shift sequences, if any), and the array shall contain a
992 null wide character if, to equal the multibyte character sequence
993 length given by the precision, the function would need to access a
994 wide character one past the end of the array."
995 This test fails on Solaris 10. */
996 {
997 static const wchar_t wstring[] = { 'a', 'b', (wchar_t) 0xfdfdfdfd, 0 };
998 buf[0] = '\0';
999 if (sprintf (buf, "%.2ls", wstring) < 0
1000 || strcmp (buf, "ab") != 0)
1001 result |= 8;
1002 }
1003 return result;
1004 }]])],
1005 [gl_cv_func_printf_directive_ls=yes],
1006 [gl_cv_func_printf_directive_ls=no],
1007 [
1008 changequote(,)dnl
1009 case "$host_os" in
1010 # Guess yes on OpenBSD >= 6.0.
1011 openbsd[1-5].*) gl_cv_func_printf_directive_ls="guessing no";;
1012 openbsd*) gl_cv_func_printf_directive_ls="guessing yes";;
1013 irix*) gl_cv_func_printf_directive_ls="guessing no";;
1014 solaris*) gl_cv_func_printf_directive_ls="guessing no";;
1015 cygwin*) gl_cv_func_printf_directive_ls="guessing no";;
1016 beos* | haiku*) gl_cv_func_printf_directive_ls="guessing no";;
1017 # Guess no on Android.
1018 linux*-android*) gl_cv_func_printf_directive_ls="guessing no";;
1019 # Guess yes on native Windows.
1020 mingw*) gl_cv_func_printf_directive_ls="guessing yes";;
1021 *) gl_cv_func_printf_directive_ls="guessing yes";;
1022 esac
1023 changequote([,])dnl
1024 ])
1025 ])
1026 ])
1027
1028 dnl Test whether the *printf family of functions supports the %lc format
1029 dnl directive and in particular, when the argument is a null wide character,
1030 dnl whether the functions don't produce a NUL byte.
1031 dnl Result is gl_cv_func_printf_directive_lc.
1032
1033 AC_DEFUN([gl_PRINTF_DIRECTIVE_LC],
1034 [
1035 AC_REQUIRE([AC_PROG_CC])
1036 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1037 AC_CACHE_CHECK([whether printf supports the 'lc' directive correctly],
1038 [gl_cv_func_printf_directive_lc],
1039 [
1040 AC_RUN_IFELSE(
1041 [AC_LANG_SOURCE([[
1042 #include <stdio.h>
1043 #include <wchar.h>
1044 #include <string.h>
1045 int main ()
1046 {
1047 int result = 0;
1048 char buf[100];
1049 /* This test fails on glibc 2.35, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2,
1050 macOS 12.5, AIX 7.2, Solaris 11.4.
1051 glibc 2.35 bug: <https://sourceware.org/bugzilla/show_bug.cgi?id=30257> */
1052 {
1053 buf[0] = '\0';
1054 if (sprintf (buf, "%lc%lc%lc", (wint_t) 'a', (wint_t) 0, (wint_t) 'z') < 0
1055 || strcmp (buf, "az") != 0)
1056 result |= 1;
1057 }
1058 return result;
1059 }]])],
1060 [gl_cv_func_printf_directive_lc=yes],
1061 [gl_cv_func_printf_directive_lc=no],
1062 [
1063 changequote(,)dnl
1064 case "$host_os" in
1065 # Guess yes on musl libc.
1066 *-musl* | midipix*) gl_cv_func_printf_directive_lc="guessing yes";;
1067 # Guess no otherwise.
1068 *) gl_cv_func_printf_directive_lc="guessing no";;
1069 esac
1070 changequote([,])dnl
1071 ])
1072 ])
1073 ])
1074
1075 dnl Test whether the *printf family of functions supports POSIX/XSI format
1076 dnl strings with positions. (POSIX:2001)
1077 dnl Result is gl_cv_func_printf_positions.
1078
1079 AC_DEFUN_ONCE([gl_PRINTF_POSITIONS],
1080 [
1081 AC_REQUIRE([AC_PROG_CC])
1082 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1083 AC_CACHE_CHECK([whether printf supports POSIX/XSI format strings with positions],
1084 [gl_cv_func_printf_positions],
1085 [
1086 AC_RUN_IFELSE(
1087 [AC_LANG_SOURCE([[
1088 #include <stdio.h>
1089 #include <string.h>
1090 /* The string "%2$d %1$d", with dollar characters protected from the shell's
1091 dollar expansion (possibly an autoconf bug). */
1092 static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' };
1093 static char buf[100];
1094 int main ()
1095 {
1096 sprintf (buf, format, 33, 55);
1097 return (strcmp (buf, "55 33") != 0);
1098 }]])],
1099 [gl_cv_func_printf_positions=yes],
1100 [gl_cv_func_printf_positions=no],
1101 [
1102 changequote(,)dnl
1103 case "$host_os" in
1104 netbsd[1-3]* | netbsdelf[1-3]* | netbsdaout[1-3]* | netbsdcoff[1-3]*)
1105 gl_cv_func_printf_positions="guessing no";;
1106 beos*) gl_cv_func_printf_positions="guessing no";;
1107 # Guess yes on Android.
1108 linux*-android*) gl_cv_func_printf_positions="guessing yes";;
1109 # Guess no on native Windows.
1110 mingw* | pw*) gl_cv_func_printf_positions="guessing no";;
1111 *) gl_cv_func_printf_positions="guessing yes";;
1112 esac
1113 changequote([,])dnl
1114 ])
1115 ])
1116 ])
1117
1118 dnl Test whether the *printf family of functions supports POSIX/XSI format
1119 dnl strings with the ' flag for grouping of decimal digits. (POSIX:2001)
1120 dnl Result is gl_cv_func_printf_flag_grouping.
1121
1122 AC_DEFUN([gl_PRINTF_FLAG_GROUPING],
1123 [
1124 AC_REQUIRE([AC_PROG_CC])
1125 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1126 AC_CACHE_CHECK([whether printf supports the grouping flag],
1127 [gl_cv_func_printf_flag_grouping],
1128 [
1129 AC_RUN_IFELSE(
1130 [AC_LANG_SOURCE([[
1131 #include <stdio.h>
1132 #include <string.h>
1133 static char buf[100];
1134 int main ()
1135 {
1136 if (sprintf (buf, "%'d %d", 1234567, 99) < 0
1137 || buf[strlen (buf) - 1] != '9')
1138 return 1;
1139 return 0;
1140 }]])],
1141 [gl_cv_func_printf_flag_grouping=yes],
1142 [gl_cv_func_printf_flag_grouping=no],
1143 [
1144 changequote(,)dnl
1145 case "$host_os" in
1146 cygwin*) gl_cv_func_printf_flag_grouping="guessing no";;
1147 netbsd*) gl_cv_func_printf_flag_grouping="guessing no";;
1148 # Guess no on Android.
1149 linux*-android*) gl_cv_func_printf_flag_grouping="guessing no";;
1150 # Guess no on native Windows.
1151 mingw* | pw*) gl_cv_func_printf_flag_grouping="guessing no";;
1152 *) gl_cv_func_printf_flag_grouping="guessing yes";;
1153 esac
1154 changequote([,])dnl
1155 ])
1156 ])
1157 ])
1158
1159 dnl Test whether the *printf family of functions supports the - flag correctly.
1160 dnl (ISO C99.) See
1161 dnl <https://lists.gnu.org/r/bug-coreutils/2008-02/msg00035.html>
1162 dnl Result is gl_cv_func_printf_flag_leftadjust.
1163
1164 AC_DEFUN([gl_PRINTF_FLAG_LEFTADJUST],
1165 [
1166 AC_REQUIRE([AC_PROG_CC])
1167 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1168 AC_CACHE_CHECK([whether printf supports the left-adjust flag correctly],
1169 [gl_cv_func_printf_flag_leftadjust],
1170 [
1171 AC_RUN_IFELSE(
1172 [AC_LANG_SOURCE([[
1173 #include <stdio.h>
1174 #include <string.h>
1175 static char buf[100];
1176 int main ()
1177 {
1178 /* Check that a '-' flag is not annihilated by a negative width. */
1179 if (sprintf (buf, "a%-*sc", -3, "b") < 0
1180 || strcmp (buf, "ab c") != 0)
1181 return 1;
1182 return 0;
1183 }]])],
1184 [gl_cv_func_printf_flag_leftadjust=yes],
1185 [gl_cv_func_printf_flag_leftadjust=no],
1186 [
1187 changequote(,)dnl
1188 case "$host_os" in
1189 # Guess yes on HP-UX 11.
1190 hpux11*) gl_cv_func_printf_flag_leftadjust="guessing yes";;
1191 # Guess no on HP-UX 10 and older.
1192 hpux*) gl_cv_func_printf_flag_leftadjust="guessing no";;
1193 # Guess yes on Android.
1194 linux*-android*) gl_cv_func_printf_flag_leftadjust="guessing yes";;
1195 # Guess yes on native Windows.
1196 mingw*) gl_cv_func_printf_flag_leftadjust="guessing yes";;
1197 # Guess yes otherwise.
1198 *) gl_cv_func_printf_flag_leftadjust="guessing yes";;
1199 esac
1200 changequote([,])dnl
1201 ])
1202 ])
1203 ])
1204
1205 dnl Test whether the *printf family of functions supports padding of non-finite
1206 dnl values with the 0 flag correctly. (ISO C99 + TC1 + TC2.) See
1207 dnl <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html>
1208 dnl Result is gl_cv_func_printf_flag_zero.
1209
1210 AC_DEFUN([gl_PRINTF_FLAG_ZERO],
1211 [
1212 AC_REQUIRE([AC_PROG_CC])
1213 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1214 AC_CACHE_CHECK([whether printf supports the zero flag correctly],
1215 [gl_cv_func_printf_flag_zero],
1216 [
1217 AC_RUN_IFELSE(
1218 [AC_LANG_SOURCE([[
1219 #include <stdio.h>
1220 #include <string.h>
1221 static char buf[100];
1222 static double zero = 0.0;
1223 int main ()
1224 {
1225 if (sprintf (buf, "%010f", 1.0 / zero, 33, 44, 55) < 0
1226 || (strcmp (buf, " inf") != 0
1227 && strcmp (buf, " infinity") != 0))
1228 return 1;
1229 return 0;
1230 }]])],
1231 [gl_cv_func_printf_flag_zero=yes],
1232 [gl_cv_func_printf_flag_zero=no],
1233 [
1234 changequote(,)dnl
1235 case "$host_os" in
1236 # Guess yes on glibc systems.
1237 *-gnu* | gnu*) gl_cv_func_printf_flag_zero="guessing yes";;
1238 # Guess yes on musl systems.
1239 *-musl* | midipix*) gl_cv_func_printf_flag_zero="guessing yes";;
1240 # Guess yes on BeOS.
1241 beos*) gl_cv_func_printf_flag_zero="guessing yes";;
1242 # Guess no on Android.
1243 linux*-android*) gl_cv_func_printf_flag_zero="guessing no";;
1244 # Guess no on native Windows.
1245 mingw*) gl_cv_func_printf_flag_zero="guessing no";;
1246 # If we don't know, obey --enable-cross-guesses.
1247 *) gl_cv_func_printf_flag_zero="$gl_cross_guess_normal";;
1248 esac
1249 changequote([,])dnl
1250 ])
1251 ])
1252 ])
1253
1254 dnl Test whether the *printf family of functions supports large precisions.
1255 dnl On mingw, precisions larger than 512 are treated like 512, in integer,
1256 dnl floating-point or pointer output. On Solaris 10/x86, precisions larger
1257 dnl than 510 in floating-point output crash the program. On Solaris 10/SPARC,
1258 dnl precisions larger than 510 in floating-point output yield wrong results.
1259 dnl On AIX 7.1, precisions larger than 998 in floating-point output yield
1260 dnl wrong results. On BeOS, precisions larger than 1044 crash the program.
1261 dnl Result is gl_cv_func_printf_precision.
1262
1263 AC_DEFUN([gl_PRINTF_PRECISION],
1264 [
1265 AC_REQUIRE([AC_PROG_CC])
1266 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1267 AC_CACHE_CHECK([whether printf supports large precisions],
1268 [gl_cv_func_printf_precision],
1269 [
1270 AC_RUN_IFELSE(
1271 [AC_LANG_SOURCE([[
1272 #include <stdio.h>
1273 #include <string.h>
1274 static char buf[5000];
1275 int main ()
1276 {
1277 int result = 0;
1278 #ifdef __BEOS__
1279 /* On BeOS, this would crash and show a dialog box. Avoid the crash. */
1280 return 1;
1281 #endif
1282 if (sprintf (buf, "%.4000d %d", 1, 33, 44) < 4000 + 3)
1283 result |= 1;
1284 if (sprintf (buf, "%.4000f %d", 1.0, 33, 44) < 4000 + 5)
1285 result |= 2;
1286 if (sprintf (buf, "%.511f %d", 1.0, 33, 44) < 511 + 5
1287 || buf[0] != '1')
1288 result |= 4;
1289 if (sprintf (buf, "%.999f %d", 1.0, 33, 44) < 999 + 5
1290 || buf[0] != '1')
1291 result |= 4;
1292 return result;
1293 }]])],
1294 [gl_cv_func_printf_precision=yes],
1295 [gl_cv_func_printf_precision=no],
1296 [
1297 changequote(,)dnl
1298 case "$host_os" in
1299 # Guess no only on Solaris, native Windows, and BeOS systems.
1300 solaris*) gl_cv_func_printf_precision="guessing no" ;;
1301 mingw* | pw*) gl_cv_func_printf_precision="guessing no" ;;
1302 beos*) gl_cv_func_printf_precision="guessing no" ;;
1303 # Guess yes on Android.
1304 linux*-android*) gl_cv_func_printf_precision="guessing yes" ;;
1305 *) gl_cv_func_printf_precision="guessing yes" ;;
1306 esac
1307 changequote([,])dnl
1308 ])
1309 ])
1310 ])
1311
1312 dnl Test whether the *printf family of functions recovers gracefully in case
1313 dnl of an out-of-memory condition, or whether it crashes the entire program.
1314 dnl Result is gl_cv_func_printf_enomem.
1315
1316 AC_DEFUN([gl_PRINTF_ENOMEM],
1317 [
1318 AC_REQUIRE([AC_PROG_CC])
1319 AC_REQUIRE([gl_MULTIARCH])
1320 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1321 AC_CACHE_CHECK([whether printf survives out-of-memory conditions],
1322 [gl_cv_func_printf_enomem],
1323 [
1324 gl_cv_func_printf_enomem="guessing no"
1325 if test "$cross_compiling" = no; then
1326 if test $APPLE_UNIVERSAL_BUILD = 0; then
1327 AC_LANG_CONFTEST([AC_LANG_SOURCE([[
1328 ]GL_NOCRASH[
1329 #include <stdio.h>
1330 #include <sys/types.h>
1331 #include <sys/time.h>
1332 #include <sys/resource.h>
1333 #include <errno.h>
1334 int main()
1335 {
1336 struct rlimit limit;
1337 int ret;
1338 nocrash_init ();
1339 /* Some printf implementations allocate temporary space with malloc. */
1340 /* On BSD systems, malloc() is limited by RLIMIT_DATA. */
1341 #ifdef RLIMIT_DATA
1342 if (getrlimit (RLIMIT_DATA, &limit) < 0)
1343 return 77;
1344 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
1345 limit.rlim_max = 5000000;
1346 limit.rlim_cur = limit.rlim_max;
1347 if (setrlimit (RLIMIT_DATA, &limit) < 0)
1348 return 77;
1349 #endif
1350 /* On Linux systems, malloc() is limited by RLIMIT_AS. */
1351 #ifdef RLIMIT_AS
1352 if (getrlimit (RLIMIT_AS, &limit) < 0)
1353 return 77;
1354 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
1355 limit.rlim_max = 5000000;
1356 limit.rlim_cur = limit.rlim_max;
1357 if (setrlimit (RLIMIT_AS, &limit) < 0)
1358 return 77;
1359 #endif
1360 /* Some printf implementations allocate temporary space on the stack. */
1361 #ifdef RLIMIT_STACK
1362 if (getrlimit (RLIMIT_STACK, &limit) < 0)
1363 return 77;
1364 if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
1365 limit.rlim_max = 5000000;
1366 limit.rlim_cur = limit.rlim_max;
1367 if (setrlimit (RLIMIT_STACK, &limit) < 0)
1368 return 77;
1369 #endif
1370 ret = printf ("%.5000000f", 1.0);
1371 return !(ret == 5000002 || (ret < 0 && errno == ENOMEM));
1372 }
1373 ]])])
1374 if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
1375 (./conftest 2>&AS_MESSAGE_LOG_FD
1376 result=$?
1377 _AS_ECHO_LOG([\$? = $result])
1378 if test $result != 0 && test $result != 77; then result=1; fi
1379 exit $result
1380 ) >/dev/null 2>/dev/null
1381 case $? in
1382 0) gl_cv_func_printf_enomem="yes" ;;
1383 77) gl_cv_func_printf_enomem="guessing no" ;;
1384 *) gl_cv_func_printf_enomem="no" ;;
1385 esac
1386 else
1387 gl_cv_func_printf_enomem="guessing no"
1388 fi
1389 rm -fr conftest*
1390 else
1391 dnl A universal build on Apple Mac OS X platforms.
1392 dnl The result would be 'no' in 32-bit mode and 'yes' in 64-bit mode.
1393 dnl But we need a configuration result that is valid in both modes.
1394 gl_cv_func_printf_enomem="guessing no"
1395 fi
1396 fi
1397 if test "$gl_cv_func_printf_enomem" = "guessing no"; then
1398 changequote(,)dnl
1399 case "$host_os" in
1400 # Guess yes on glibc systems.
1401 *-gnu* | gnu*) gl_cv_func_printf_enomem="guessing yes";;
1402 # Guess yes on Solaris.
1403 solaris*) gl_cv_func_printf_enomem="guessing yes";;
1404 # Guess yes on AIX.
1405 aix*) gl_cv_func_printf_enomem="guessing yes";;
1406 # Guess yes on HP-UX/hppa.
1407 hpux*) case "$host_cpu" in
1408 hppa*) gl_cv_func_printf_enomem="guessing yes";;
1409 *) gl_cv_func_printf_enomem="guessing no";;
1410 esac
1411 ;;
1412 # Guess yes on IRIX.
1413 irix*) gl_cv_func_printf_enomem="guessing yes";;
1414 # Guess yes on OSF/1.
1415 osf*) gl_cv_func_printf_enomem="guessing yes";;
1416 # Guess yes on BeOS.
1417 beos*) gl_cv_func_printf_enomem="guessing yes";;
1418 # Guess yes on Haiku.
1419 haiku*) gl_cv_func_printf_enomem="guessing yes";;
1420 # Guess no on Android.
1421 linux*-android*) gl_cv_func_printf_enomem="guessing no";;
1422 # If we don't know, obey --enable-cross-guesses.
1423 *) gl_cv_func_printf_enomem="$gl_cross_guess_normal";;
1424 esac
1425 changequote([,])dnl
1426 fi
1427 ])
1428 ])
1429
1430 dnl Test whether the snprintf function exists. (ISO C99, POSIX:2001)
1431 dnl Result is ac_cv_func_snprintf.
1432
1433 AC_DEFUN([gl_SNPRINTF_PRESENCE],
1434 [
1435 AC_CHECK_FUNCS_ONCE([snprintf])
1436 ])
1437
1438 dnl Test whether the string produced by the snprintf function is always NUL
1439 dnl terminated. (ISO C99, POSIX:2001)
1440 dnl Result is gl_cv_func_snprintf_truncation_c99.
1441
1442 AC_DEFUN_ONCE([gl_SNPRINTF_TRUNCATION_C99],
1443 [
1444 AC_REQUIRE([AC_PROG_CC])
1445 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1446 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1447 AC_CACHE_CHECK([whether snprintf truncates the result as in C99],
1448 [gl_cv_func_snprintf_truncation_c99],
1449 [
1450 AC_RUN_IFELSE(
1451 [AC_LANG_SOURCE([[
1452 #include <stdio.h>
1453 #include <string.h>
1454 #if HAVE_SNPRINTF
1455 # define my_snprintf snprintf
1456 #else
1457 # include <stdarg.h>
1458 static int my_snprintf (char *buf, int size, const char *format, ...)
1459 {
1460 va_list args;
1461 int ret;
1462 va_start (args, format);
1463 ret = vsnprintf (buf, size, format, args);
1464 va_end (args);
1465 return ret;
1466 }
1467 #endif
1468 static char buf[100];
1469 int main ()
1470 {
1471 strcpy (buf, "ABCDEF");
1472 my_snprintf (buf, 3, "%d %d", 4567, 89);
1473 if (memcmp (buf, "45\0DEF", 6) != 0)
1474 return 1;
1475 return 0;
1476 }]])],
1477 [gl_cv_func_snprintf_truncation_c99=yes],
1478 [gl_cv_func_snprintf_truncation_c99=no],
1479 [
1480 changequote(,)dnl
1481 case "$host_os" in
1482 # Guess yes on glibc systems.
1483 *-gnu* | gnu*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1484 # Guess yes on musl systems.
1485 *-musl* | midipix*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1486 # Guess yes on FreeBSD >= 5.
1487 freebsd[1-4].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1488 freebsd* | kfreebsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1489 midnightbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1490 # Guess yes on Mac OS X >= 10.3.
1491 darwin[1-6].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1492 darwin*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1493 # Guess yes on OpenBSD >= 3.9.
1494 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
1495 gl_cv_func_snprintf_truncation_c99="guessing no";;
1496 openbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1497 # Guess yes on Solaris >= 2.6.
1498 solaris2.[0-5] | solaris2.[0-5].*)
1499 gl_cv_func_snprintf_truncation_c99="guessing no";;
1500 solaris*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1501 # Guess yes on AIX >= 4.
1502 aix[1-3]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1503 aix*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1504 # Guess yes on HP-UX >= 11.
1505 hpux[7-9]* | hpux10*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1506 hpux*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1507 # Guess yes on IRIX >= 6.5.
1508 irix6.5) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1509 # Guess yes on OSF/1 >= 5.
1510 osf[3-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1511 osf*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1512 # Guess yes on NetBSD >= 3.
1513 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1514 gl_cv_func_snprintf_truncation_c99="guessing no";;
1515 netbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1516 # Guess yes on BeOS.
1517 beos*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1518 # Guess yes on Android.
1519 linux*-android*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1520 # Guess no on native Windows.
1521 mingw*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1522 # If we don't know, obey --enable-cross-guesses.
1523 *) gl_cv_func_snprintf_truncation_c99="$gl_cross_guess_normal";;
1524 esac
1525 changequote([,])dnl
1526 ])
1527 ])
1528 ])
1529
1530 dnl Test whether the return value of the snprintf function is the number
1531 dnl of bytes (excluding the terminating NUL) that would have been produced
1532 dnl if the buffer had been large enough. (ISO C99, POSIX:2001)
1533 dnl For example, this test program fails on IRIX 6.5:
1534 dnl ---------------------------------------------------------------------
1535 dnl #include <stdio.h>
1536 dnl int main()
1537 dnl {
1538 dnl static char buf[8];
1539 dnl int retval = snprintf (buf, 3, "%d", 12345);
1540 dnl return retval >= 0 && retval < 3;
1541 dnl }
1542 dnl ---------------------------------------------------------------------
1543 dnl Result is gl_cv_func_snprintf_retval_c99.
1544
1545 AC_DEFUN_ONCE([gl_SNPRINTF_RETVAL_C99],
1546 [
1547 AC_REQUIRE([AC_PROG_CC])
1548 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1549 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1550 AC_CACHE_CHECK([whether snprintf returns a byte count as in C99],
1551 [gl_cv_func_snprintf_retval_c99],
1552 [
1553 AC_RUN_IFELSE(
1554 [AC_LANG_SOURCE([[
1555 #include <stdio.h>
1556 #include <string.h>
1557 #if HAVE_SNPRINTF
1558 # define my_snprintf snprintf
1559 #else
1560 # include <stdarg.h>
1561 static int my_snprintf (char *buf, int size, const char *format, ...)
1562 {
1563 va_list args;
1564 int ret;
1565 va_start (args, format);
1566 ret = vsnprintf (buf, size, format, args);
1567 va_end (args);
1568 return ret;
1569 }
1570 #endif
1571 static char buf[100];
1572 int main ()
1573 {
1574 strcpy (buf, "ABCDEF");
1575 if (my_snprintf (buf, 3, "%d %d", 4567, 89) != 7)
1576 return 1;
1577 if (my_snprintf (buf, 0, "%d %d", 4567, 89) != 7)
1578 return 2;
1579 if (my_snprintf (NULL, 0, "%d %d", 4567, 89) != 7)
1580 return 3;
1581 return 0;
1582 }]])],
1583 [gl_cv_func_snprintf_retval_c99=yes],
1584 [gl_cv_func_snprintf_retval_c99=no],
1585 [case "$host_os" in
1586 changequote(,)dnl
1587 # Guess yes on glibc systems.
1588 *-gnu* | gnu*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1589 # Guess yes on musl systems.
1590 *-musl* | midipix*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1591 # Guess yes on FreeBSD >= 5.
1592 freebsd[1-4].*) gl_cv_func_snprintf_retval_c99="guessing no";;
1593 freebsd* | kfreebsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1594 midnightbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1595 # Guess yes on Mac OS X >= 10.3.
1596 darwin[1-6].*) gl_cv_func_snprintf_retval_c99="guessing no";;
1597 darwin*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1598 # Guess yes on OpenBSD >= 3.9.
1599 openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
1600 gl_cv_func_snprintf_retval_c99="guessing no";;
1601 openbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1602 # Guess yes on Solaris >= 2.10.
1603 solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";;
1604 solaris*) gl_cv_func_printf_sizes_c99="guessing no";;
1605 # Guess yes on AIX >= 4.
1606 aix[1-3]*) gl_cv_func_snprintf_retval_c99="guessing no";;
1607 aix*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1608 # Guess yes on NetBSD >= 3.
1609 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1610 gl_cv_func_snprintf_retval_c99="guessing no";;
1611 netbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1612 # Guess yes on BeOS.
1613 beos*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1614 # Guess yes on Android.
1615 linux*-android*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1616 changequote([,])dnl
1617 # Guess yes on MSVC, no on mingw.
1618 mingw*) AC_EGREP_CPP([Known], [
1619 #ifdef _MSC_VER
1620 Known
1621 #endif
1622 ],
1623 [gl_cv_func_snprintf_retval_c99="guessing yes"],
1624 [gl_cv_func_snprintf_retval_c99="guessing no"])
1625 ;;
1626 # If we don't know, obey --enable-cross-guesses.
1627 *) gl_cv_func_snprintf_retval_c99="$gl_cross_guess_normal";;
1628 esac
1629 ])
1630 ])
1631 ])
1632
1633 dnl Test whether the snprintf function supports the %n format directive
1634 dnl also in truncated portions of the format string. (ISO C99, POSIX:2001)
1635 dnl Result is gl_cv_func_snprintf_directive_n.
1636
1637 AC_DEFUN([gl_SNPRINTF_DIRECTIVE_N],
1638 [
1639 AC_REQUIRE([AC_PROG_CC])
1640 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1641 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1642 AC_CACHE_CHECK([whether snprintf fully supports the 'n' directive],
1643 [gl_cv_func_snprintf_directive_n],
1644 [
1645 AC_RUN_IFELSE(
1646 [AC_LANG_SOURCE([[
1647 #include <stdio.h>
1648 #include <string.h>
1649 #if HAVE_SNPRINTF
1650 # define my_snprintf snprintf
1651 #else
1652 # include <stdarg.h>
1653 static int my_snprintf (char *buf, int size, const char *format, ...)
1654 {
1655 va_list args;
1656 int ret;
1657 va_start (args, format);
1658 ret = vsnprintf (buf, size, format, args);
1659 va_end (args);
1660 return ret;
1661 }
1662 #endif
1663 static char fmtstring[10];
1664 static char buf[100];
1665 int main ()
1666 {
1667 int count = -1;
1668 /* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2)
1669 support %n in format strings in read-only memory but not in writable
1670 memory. */
1671 strcpy (fmtstring, "%d %n");
1672 my_snprintf (buf, 4, fmtstring, 12345, &count, 33, 44, 55);
1673 if (count != 6)
1674 return 1;
1675 return 0;
1676 }]])],
1677 [gl_cv_func_snprintf_directive_n=yes],
1678 [gl_cv_func_snprintf_directive_n=no],
1679 [
1680 case "$host_os" in
1681 # Guess no on glibc when _FORTIFY_SOURCE >= 2.
1682 *-gnu* | gnu*) AC_COMPILE_IFELSE(
1683 [AC_LANG_SOURCE(
1684 [[#if _FORTIFY_SOURCE >= 2
1685 error fail
1686 #endif
1687 ]])],
1688 [gl_cv_func_snprintf_directive_n="guessing yes"],
1689 [gl_cv_func_snprintf_directive_n="guessing no"])
1690 ;;
1691 changequote(,)dnl
1692 # Guess yes on musl systems.
1693 *-musl* | midipix*) gl_cv_func_snprintf_directive_n="guessing yes";;
1694 # Guess yes on FreeBSD >= 5.
1695 freebsd[1-4].*) gl_cv_func_snprintf_directive_n="guessing no";;
1696 freebsd* | kfreebsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
1697 midnightbsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
1698 # Guess yes on Mac OS X >= 10.3.
1699 darwin[1-6].*) gl_cv_func_snprintf_directive_n="guessing no";;
1700 darwin*) gl_cv_func_snprintf_directive_n="guessing yes";;
1701 # Guess yes on Solaris >= 2.6.
1702 solaris2.[0-5] | solaris2.[0-5].*)
1703 gl_cv_func_snprintf_directive_n="guessing no";;
1704 solaris*) gl_cv_func_snprintf_directive_n="guessing yes";;
1705 # Guess yes on AIX >= 4.
1706 aix[1-3]*) gl_cv_func_snprintf_directive_n="guessing no";;
1707 aix*) gl_cv_func_snprintf_directive_n="guessing yes";;
1708 # Guess yes on IRIX >= 6.5.
1709 irix6.5) gl_cv_func_snprintf_directive_n="guessing yes";;
1710 # Guess yes on OSF/1 >= 5.
1711 osf[3-4]*) gl_cv_func_snprintf_directive_n="guessing no";;
1712 osf*) gl_cv_func_snprintf_directive_n="guessing yes";;
1713 # Guess yes on NetBSD >= 3.
1714 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1715 gl_cv_func_snprintf_directive_n="guessing no";;
1716 netbsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
1717 # Guess yes on BeOS.
1718 beos*) gl_cv_func_snprintf_directive_n="guessing yes";;
1719 # Guess no on Android.
1720 linux*-android*) gl_cv_func_snprintf_directive_n="guessing no";;
1721 # Guess no on native Windows.
1722 mingw*) gl_cv_func_snprintf_directive_n="guessing no";;
1723 # If we don't know, obey --enable-cross-guesses.
1724 *) gl_cv_func_snprintf_directive_n="$gl_cross_guess_normal";;
1725 changequote([,])dnl
1726 esac
1727 ])
1728 ])
1729 ])
1730
1731 dnl Test whether the snprintf function, when passed a size = 1, writes any
1732 dnl output without bounds in this case, behaving like sprintf. This is the
1733 dnl case on Linux libc5.
1734 dnl Result is gl_cv_func_snprintf_size1.
1735
1736 AC_DEFUN([gl_SNPRINTF_SIZE1],
1737 [
1738 AC_REQUIRE([AC_PROG_CC])
1739 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1740 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1741 AC_CACHE_CHECK([whether snprintf respects a size of 1],
1742 [gl_cv_func_snprintf_size1],
1743 [
1744 AC_RUN_IFELSE(
1745 [AC_LANG_SOURCE([[
1746 #include <stdio.h>
1747 #if HAVE_SNPRINTF
1748 # define my_snprintf snprintf
1749 #else
1750 # include <stdarg.h>
1751 static int my_snprintf (char *buf, int size, const char *format, ...)
1752 {
1753 va_list args;
1754 int ret;
1755 va_start (args, format);
1756 ret = vsnprintf (buf, size, format, args);
1757 va_end (args);
1758 return ret;
1759 }
1760 #endif
1761 int main()
1762 {
1763 static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1764 my_snprintf (buf, 1, "%d", 12345);
1765 return buf[1] != 'E';
1766 }]])],
1767 [gl_cv_func_snprintf_size1=yes],
1768 [gl_cv_func_snprintf_size1=no],
1769 [case "$host_os" in
1770 # Guess yes on Android.
1771 linux*-android*) gl_cv_func_snprintf_size1="guessing yes" ;;
1772 # Guess yes on native Windows.
1773 mingw*) gl_cv_func_snprintf_size1="guessing yes" ;;
1774 *) gl_cv_func_snprintf_size1="guessing yes" ;;
1775 esac
1776 ])
1777 ])
1778 ])
1779
1780 dnl Test whether the vsnprintf function, when passed a zero size, produces no
1781 dnl output. (ISO C99, POSIX:2001)
1782 dnl For example, snprintf nevertheless writes a NUL byte in this case
1783 dnl on OSF/1 5.1:
1784 dnl ---------------------------------------------------------------------
1785 dnl #include <stdio.h>
1786 dnl int main()
1787 dnl {
1788 dnl static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1789 dnl snprintf (buf, 0, "%d", 12345);
1790 dnl return buf[0] != 'D';
1791 dnl }
1792 dnl ---------------------------------------------------------------------
1793 dnl And vsnprintf writes any output without bounds in this case, behaving like
1794 dnl vsprintf, on HP-UX 11 and OSF/1 5.1:
1795 dnl ---------------------------------------------------------------------
1796 dnl #include <stdarg.h>
1797 dnl #include <stdio.h>
1798 dnl static int my_snprintf (char *buf, int size, const char *format, ...)
1799 dnl {
1800 dnl va_list args;
1801 dnl int ret;
1802 dnl va_start (args, format);
1803 dnl ret = vsnprintf (buf, size, format, args);
1804 dnl va_end (args);
1805 dnl return ret;
1806 dnl }
1807 dnl int main()
1808 dnl {
1809 dnl static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1810 dnl my_snprintf (buf, 0, "%d", 12345);
1811 dnl return buf[0] != 'D';
1812 dnl }
1813 dnl ---------------------------------------------------------------------
1814 dnl Result is gl_cv_func_vsnprintf_zerosize_c99.
1815
1816 AC_DEFUN([gl_VSNPRINTF_ZEROSIZE_C99],
1817 [
1818 AC_REQUIRE([AC_PROG_CC])
1819 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1820 AC_CACHE_CHECK([whether vsnprintf respects a zero size as in C99],
1821 [gl_cv_func_vsnprintf_zerosize_c99],
1822 [
1823 AC_RUN_IFELSE(
1824 [AC_LANG_SOURCE([[
1825 #include <stdarg.h>
1826 #include <stdio.h>
1827 static int my_snprintf (char *buf, int size, const char *format, ...)
1828 {
1829 va_list args;
1830 int ret;
1831 va_start (args, format);
1832 ret = vsnprintf (buf, size, format, args);
1833 va_end (args);
1834 return ret;
1835 }
1836 int main()
1837 {
1838 static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
1839 my_snprintf (buf, 0, "%d", 12345);
1840 return buf[0] != 'D';
1841 }]])],
1842 [gl_cv_func_vsnprintf_zerosize_c99=yes],
1843 [gl_cv_func_vsnprintf_zerosize_c99=no],
1844 [
1845 changequote(,)dnl
1846 case "$host_os" in
1847 # Guess yes on glibc systems.
1848 *-gnu* | gnu*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1849 # Guess yes on musl systems.
1850 *-musl* | midipix*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1851 # Guess yes on FreeBSD >= 5.
1852 freebsd[1-4].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1853 freebsd* | kfreebsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1854 midnightbsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1855 # Guess yes on Mac OS X >= 10.3.
1856 darwin[1-6].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1857 darwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1858 # Guess yes on Cygwin.
1859 cygwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1860 # Guess yes on Solaris >= 2.6.
1861 solaris2.[0-5] | solaris2.[0-5].*)
1862 gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1863 solaris*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1864 # Guess yes on AIX >= 4.
1865 aix[1-3]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1866 aix*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1867 # Guess yes on IRIX >= 6.5.
1868 irix6.5) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1869 # Guess yes on NetBSD >= 3.
1870 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
1871 gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1872 netbsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1873 # Guess yes on BeOS.
1874 beos*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1875 # Guess yes on Android.
1876 linux*-android*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1877 # Guess yes on native Windows.
1878 mingw* | pw*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1879 # If we don't know, obey --enable-cross-guesses.
1880 *) gl_cv_func_vsnprintf_zerosize_c99="$gl_cross_guess_normal";;
1881 esac
1882 changequote([,])dnl
1883 ])
1884 ])
1885 ])
1886
1887 dnl Test whether the swprintf function works correctly when it produces output
1888 dnl that contains null wide characters.
1889 dnl Result is gl_cv_func_swprintf_works.
1890
1891 AC_DEFUN([gl_SWPRINTF_WORKS],
1892 [
1893 AC_REQUIRE([AC_PROG_CC])
1894 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1895 AC_CHECK_FUNCS_ONCE([swprintf])
1896 AC_CACHE_CHECK([whether swprintf works],
1897 [gl_cv_func_swprintf_works],
1898 [
1899 AC_RUN_IFELSE(
1900 [AC_LANG_SOURCE([[
1901 #ifndef __USE_MINGW_ANSI_STDIO
1902 # define __USE_MINGW_ANSI_STDIO 1
1903 #endif
1904 #include <stdio.h>
1905 #include <wchar.h>
1906 int main()
1907 {
1908 int result = 0;
1909 { /* This test fails on musl libc 1.2.3, FreeBSD, NetBSD, OpenBSD, macOS, AIX. */
1910 wchar_t buf[5] = { 0xBEEF, 0xBEEF, 0xBEEF, 0xBEEF, 0xBEEF };
1911 int ret = swprintf (buf, 4, L"%cz", '\0');
1912 /* Expected result:
1913 ret = 2, buf[0] = 0x0, buf[1] = 0x7a, buf[2] = 0x0, buf[3] = 0xbeef
1914 musl libc 1.2.3:
1915 ret = 2, buf[0] = 0x0, buf[1] = 0x0, buf[2] = 0x0, buf[3] = 0x0
1916 Reported at <https://www.openwall.com/lists/musl/2023/03/22/9>.
1917 FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2, macOS 12.5, AIX 7.2:
1918 ret = 2, buf[0] = 0x0, buf[1] = 0xbeef, buf[2] = 0xbeef, buf[3] = 0xbeef
1919 */
1920 if (ret < 0 || buf[1] != 'z')
1921 result |= 1;
1922 }
1923 { /* This test fails on mingw. */
1924 wchar_t buf[2];
1925 int ret = swprintf (buf, 2, L"%lc", (wint_t)0);
1926 /* Expected: ret = 1
1927 mingw: ret = 0
1928 */
1929 if (ret != 1)
1930 result |= 2;
1931 }
1932 return result;
1933 }]])],
1934 [gl_cv_func_swprintf_works=yes],
1935 [gl_cv_func_swprintf_works=no],
1936 [case "$host_os" in
1937 # Guess yes on glibc systems.
1938 *-gnu* | gnu*) gl_cv_func_swprintf_works="guessing yes";;
1939 # Guess no on musl systems.
1940 *-musl* | midipix*) gl_cv_func_swprintf_works="guessing no";;
1941 # Guess no on FreeBSD, NetBSD, OpenBSD, macOS, AIX.
1942 freebsd* | midnightbsd* | netbsd* | openbsd* | darwin* | aix*)
1943 gl_cv_func_swprintf_works="guessing no";;
1944 # Guess no on native Windows.
1945 mingw* | pw*) gl_cv_func_swprintf_works="guessing no";;
1946 # If we don't know, obey --enable-cross-guesses.
1947 *) gl_cv_func_swprintf_works="$gl_cross_guess_normal";;
1948 esac
1949 ])
1950 ])
1951 ])
1952
1953 dnl Test whether the *wprintf family of functions supports the 'a' and 'A'
1954 dnl conversion specifier for hexadecimal output of 'long double' numbers.
1955 dnl (ISO C99, POSIX:2001)
1956 dnl Result is gl_cv_func_swprintf_directive_la.
1957
1958 AC_DEFUN([gl_SWPRINTF_DIRECTIVE_LA],
1959 [
1960 AC_REQUIRE([AC_PROG_CC])
1961 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1962 AC_CACHE_CHECK([whether swprintf supports the 'La' and 'LA' directives],
1963 [gl_cv_func_swprintf_directive_la],
1964 [
1965 AC_RUN_IFELSE(
1966 [AC_LANG_SOURCE([[
1967 #include <stdio.h>
1968 #include <wchar.h>
1969 static wchar_t buf[100];
1970 int main ()
1971 {
1972 int result = 0;
1973 /* This catches a glibc 2.15 and Haiku 2022 bug. */
1974 if (swprintf (buf, sizeof (buf) / sizeof (wchar_t),
1975 L"%La %d", 3.1416015625L, 33, 44, 55) < 0
1976 || (wcscmp (buf, L"0x1.922p+1 33") != 0
1977 && wcscmp (buf, L"0x3.244p+0 33") != 0
1978 && wcscmp (buf, L"0x6.488p-1 33") != 0
1979 && wcscmp (buf, L"0xc.91p-2 33") != 0))
1980 result |= 1;
1981 return result;
1982 }]])],
1983 [gl_cv_func_swprintf_directive_la=yes],
1984 [gl_cv_func_swprintf_directive_la=no],
1985 [case "$host_os" in
1986 # Guess yes on glibc >= 2.17 systems.
1987 *-gnu* | gnu*)
1988 AC_EGREP_CPP([Unlucky], [
1989 #include <features.h>
1990 #ifdef __GNU_LIBRARY__
1991 #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 16) || (__GLIBC__ > 2)) && !defined __UCLIBC__
1992 Unlucky
1993 #endif
1994 #endif
1995 ],
1996 [gl_cv_func_swprintf_directive_la="guessing yes"],
1997 [gl_cv_func_swprintf_directive_la="guessing no"])
1998 ;;
1999 # Guess yes on musl systems.
2000 *-musl* | midipix*) gl_cv_func_swprintf_directive_la="guessing yes";;
2001 # Guess yes on Android.
2002 linux*-android*) gl_cv_func_swprintf_directive_la="guessing yes";;
2003 # Guess no on native Windows.
2004 mingw*) gl_cv_func_swprintf_directive_la="guessing no";;
2005 # If we don't know, obey --enable-cross-guesses.
2006 *) gl_cv_func_swprintf_directive_la="$gl_cross_guess_normal";;
2007 esac
2008 ])
2009 ])
2010 ])
2011
2012 dnl Test whether the *wprintf family of functions supports the 'lc' conversion
2013 dnl specifier for all wide characters.
2014 dnl (ISO C11, POSIX:2001)
2015 dnl Result is gl_cv_func_swprintf_directive_lc.
2016
2017 AC_DEFUN([gl_SWPRINTF_DIRECTIVE_LC],
2018 [
2019 AC_REQUIRE([AC_PROG_CC])
2020 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
2021 AC_CACHE_CHECK([whether swprintf supports the 'lc' directive],
2022 [gl_cv_func_swprintf_directive_lc],
2023 [
2024 AC_RUN_IFELSE(
2025 [AC_LANG_SOURCE([[
2026 #include <stdio.h>
2027 #include <wchar.h>
2028 static wchar_t buf[100];
2029 static wint_t L_invalid = (wchar_t) 0x76543210;
2030 int main ()
2031 {
2032 int result = 0;
2033 /* This catches a musl libc 1.2.4, Android bug.
2034 Reported at <https://www.openwall.com/lists/musl/2023/06/12/3>. */
2035 if (swprintf (buf, sizeof (buf) / sizeof (wchar_t),
2036 L"%lc %d", L_invalid, 33, 44, 55) < 0)
2037 result |= 1;
2038 return result;
2039 }]])],
2040 [gl_cv_func_swprintf_directive_lc=yes],
2041 [gl_cv_func_swprintf_directive_lc=no],
2042 [case "$host_os" in
2043 # Guess yes on glibc systems.
2044 *-gnu* | gnu*) gl_cv_func_swprintf_directive_lc="guessing yes";;
2045 # Guess no on musl systems.
2046 *-musl* | midipix*) gl_cv_func_swprintf_directive_lc="guessing no";;
2047 # Guess no on Android.
2048 linux*-android*) gl_cv_func_swprintf_directive_lc="guessing no";;
2049 # Guess yes on native Windows.
2050 mingw*) gl_cv_func_swprintf_directive_lc="guessing yes";;
2051 # If we don't know, obey --enable-cross-guesses.
2052 *) gl_cv_func_swprintf_directive_lc="$gl_cross_guess_normal";;
2053 esac
2054 ])
2055 ])
2056 ])
2057
2058 dnl The results of these tests on various platforms are:
2059 dnl
2060 dnl 1 = gl_PRINTF_SIZES_C99
2061 dnl 2 = gl_PRINTF_SIZES_C23
2062 dnl 3 = gl_PRINTF_LONG_DOUBLE
2063 dnl 4 = gl_PRINTF_INFINITE
2064 dnl 5 = gl_PRINTF_INFINITE_LONG_DOUBLE
2065 dnl 6 = gl_PRINTF_DIRECTIVE_A
2066 dnl 7 = gl_PRINTF_DIRECTIVE_B
2067 dnl 8 = gl_PRINTF_DIRECTIVE_UPPERCASE_B
2068 dnl 9 = gl_PRINTF_DIRECTIVE_F
2069 dnl 10 = gl_PRINTF_DIRECTIVE_N
2070 dnl 11 = gl_PRINTF_DIRECTIVE_LS
2071 dnl 12 = gl_PRINTF_DIRECTIVE_LC
2072 dnl 13 = gl_PRINTF_POSITIONS
2073 dnl 14 = gl_PRINTF_FLAG_GROUPING
2074 dnl 15 = gl_PRINTF_FLAG_LEFTADJUST
2075 dnl 16 = gl_PRINTF_FLAG_ZERO
2076 dnl 17 = gl_PRINTF_PRECISION
2077 dnl 18 = gl_PRINTF_ENOMEM
2078 dnl 19 = gl_SNPRINTF_PRESENCE
2079 dnl 20 = gl_SNPRINTF_TRUNCATION_C99
2080 dnl 21 = gl_SNPRINTF_RETVAL_C99
2081 dnl 22 = gl_SNPRINTF_DIRECTIVE_N
2082 dnl 23 = gl_SNPRINTF_SIZE1
2083 dnl 24 = gl_VSNPRINTF_ZEROSIZE_C99
2084 dnl 25 = gl_SWPRINTF_WORKS
2085 dnl 26 = gl_SWPRINTF_DIRECTIVE_LA
2086 dnl 27 = gl_SWPRINTF_DIRECTIVE_LC
2087 dnl
2088 dnl 1 = checking whether printf supports size specifiers as in C99...
2089 dnl 2 = checking whether printf supports size specifiers as in C23...
2090 dnl 3 = checking whether printf supports 'long double' arguments...
2091 dnl 4 = checking whether printf supports infinite 'double' arguments...
2092 dnl 5 = checking whether printf supports infinite 'long double' arguments...
2093 dnl 6 = checking whether printf supports the 'a' and 'A' directives...
2094 dnl 7 = checking whether printf supports the 'b' directive...
2095 dnl 8 = checking whether printf supports the 'B' directive...
2096 dnl 9 = checking whether printf supports the 'F' directive...
2097 dnl 10 = checking whether printf supports the 'n' directive...
2098 dnl 11 = checking whether printf supports the 'ls' directive...
2099 dnl 12 = checking whether printf supports the 'lc' directive correctly...
2100 dnl 13 = checking whether printf supports POSIX/XSI format strings with positions...
2101 dnl 14 = checking whether printf supports the grouping flag...
2102 dnl 15 = checking whether printf supports the left-adjust flag correctly...
2103 dnl 16 = checking whether printf supports the zero flag correctly...
2104 dnl 17 = checking whether printf supports large precisions...
2105 dnl 18 = checking whether printf survives out-of-memory conditions...
2106 dnl 19 = checking for snprintf...
2107 dnl 20 = checking whether snprintf truncates the result as in C99...
2108 dnl 21 = checking whether snprintf returns a byte count as in C99...
2109 dnl 22 = checking whether snprintf fully supports the 'n' directive...
2110 dnl 23 = checking whether snprintf respects a size of 1...
2111 dnl 24 = checking whether vsnprintf respects a zero size as in C99...
2112 dnl 25 = checking whether swprintf works...
2113 dnl 26 = checking whether swprintf supports the 'La' and 'LA' directives...
2114 dnl 27 = checking whether swprintf supports the 'lc' directive...
2115 dnl
2116 dnl . = yes, # = no.
2117 dnl
2118 dnl 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
2119 dnl musl libc 1.2.3 . # . . . . # # . . . . . . . . . . . . . . . . # . #
2120 dnl glibc 2.35 . # . . . . . . . . . # . . . . . . . . . . . . . . .
2121 dnl glibc 2.5 . # . . . . # # . . . # . . . . . . . . . . . . . # .
2122 dnl glibc 2.3.6 . # . . . # # # . . . # . . . . . . . . . . . . . # .
2123 dnl FreeBSD 13.0 . # . . . # # # . . . # . . . . . # . . . . . . # . #
2124 dnl FreeBSD 5.4, 6.1 . # . . . # # # . . . # . . . # . # . . . . . . # ? ?
2125 dnl Mac OS X 10.13.5 . # . . # # # # . # . # . . . . . . . . . # . . # ? ?
2126 dnl Mac OS X 10.5.8 . # . . # # # # . . . # . . . # . . . . . . . . # ? ?
2127 dnl Mac OS X 10.3.9 . # . . . # # # . . . # . . . # . # . . . . . . # ? ?
2128 dnl OpenBSD 6.0, 6.7 . # . . . # # # . . . # . . . . . # . . . . . . # . #
2129 dnl OpenBSD 3.9, 4.0 . # . # # # # # # . # # . # . # . # . . . . . . # ? ?
2130 dnl Cygwin 1.7.0 (2009) . # . . # . # # . . ? ? . . . . . ? . . . . . . ? ? ?
2131 dnl Cygwin 1.5.25 (2008) . # . . # # # # . . # ? . . . . . # . . . . . . ? ? ?
2132 dnl Cygwin 1.5.19 (2006) # # . . # # # # # . # ? . # . # # # . . . . . . ? ? ?
2133 dnl Solaris 11.4 . # . # # # # # . . # # . . . # . . . . . . . . . # .
2134 dnl Solaris 11.3 . # . . . # # # . . # # . . . . . . . . . . . . . # .
2135 dnl Solaris 11.0 . # . # # # # # . . # # . . . # . . . . . . . . ? ? ?
2136 dnl Solaris 10 . # . # # # # # . . # # . . . # # . . . . . . . . # .
2137 dnl Solaris 2.6 ... 9 # # . # # # # # # . # # . . . # # . . . # . . . ? ? ?
2138 dnl Solaris 2.5.1 # # . # # # # # # . # # . . . # . . # # # # # # ? ? ?
2139 dnl AIX 7.1 . # . # # # # # . . . # . . . # # . . . . . . . # . .
2140 dnl AIX 5.2 . # . # # # # # . . . # . . . # . . . . . . . . # ? ?
2141 dnl AIX 4.3.2, 5.1 # # . # # # # # # . . # . . . # . . . . # . . . # ? ?
2142 dnl HP-UX 11.31 . # . . . # # # . . . ? . . . # . . . . # # . . ? ? ?
2143 dnl HP-UX 11.{00,11,23} # # . . . # # # # . . ? . . . # . . . . # # . # ? ? ?
2144 dnl HP-UX 10.20 # # . # . # # # # . ? ? . . # # . . . . # # ? # ? ? ?
2145 dnl IRIX 6.5 # # . # # # # # # . # # . . . # . . . . # . . . # ? ?
2146 dnl OSF/1 5.1 # # . # # # # # # . . ? . . . # . . . . # . . # ? ? ?
2147 dnl OSF/1 4.0d # # . # # # # # # . . ? . . . # . . # # # # # # ? ? ?
2148 dnl NetBSD 9.0 . # . . . # # # . . . # . . . . . . . . . . . . # . #
2149 dnl NetBSD 5.0 . # . . # # # # . . . # . . . # . # . . . . . . # ? ?
2150 dnl NetBSD 4.0 . # ? ? ? ? # # ? . ? # . ? ? ? ? ? . . . ? ? ? # ? ?
2151 dnl NetBSD 3.0 . # . . . # # # # . ? # # # ? # . # . . . . . . # ? ?
2152 dnl Haiku . # . . # # # # # . # ? . . . . . ? . . ? . . . . # .
2153 dnl BeOS # # # . # # # # # . ? ? # . ? . # ? . . ? . . . ? ? ?
2154 dnl Android 4.3 . # . # # # # # # # # ? . # . # . # . . . # . . ? ? ?
2155 dnl old mingw / msvcrt # # # # # # # # # . . ? # # . # # ? . # # # . . # ? ?
2156 dnl MSVC 9 # # # # # # # # # # . ? # # . # # ? # # # # . . # ? ?
2157 dnl mingw 2009-2011 . # # . # . # # . . . ? # # . . . ? . . . . . . # ? ?
2158 dnl mingw-w64 2011 # # # # # # # # # . . ? # # . # # ? . # # # . . # ? ?