Debian Codegraph @

m4/printf.m4

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