Debian Codegraph @

m4/printf.m4

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