Debian Codegraph @

m4/vasnprintf.m4

raw
1 # vasnprintf.m4 serial 52
2 dnl Copyright (C) 2002-2004, 2006-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 AC_DEFUN([gl_FUNC_VASNPRINTF],
8 [
9 AC_CHECK_FUNCS_ONCE([vasnprintf])
10 if test $ac_cv_func_vasnprintf = no; then
11 gl_REPLACE_VASNPRINTF
12 fi
13 ])
14
15 AC_DEFUN([gl_REPLACE_VASNPRINTF],
16 [
17 AC_CHECK_FUNCS_ONCE([vasnprintf])
18 AC_LIBOBJ([vasnprintf])
19 AC_LIBOBJ([printf-args])
20 AC_LIBOBJ([printf-parse])
21 AC_LIBOBJ([asnprintf])
22 if test $ac_cv_func_vasnprintf = yes; then
23 AC_DEFINE([REPLACE_VASNPRINTF], [1],
24 [Define if vasnprintf exists but is overridden by gnulib.])
25 fi
26 gl_PREREQ_PRINTF_ARGS
27 gl_PREREQ_PRINTF_PARSE
28 gl_PREREQ_VASNPRINTF
29 gl_PREREQ_ASNPRINTF
30 ])
31
32 AC_DEFUN([gl_FUNC_VASNWPRINTF],
33 [
34 AC_LIBOBJ([printf-args])
35 gl_PREREQ_PRINTF_ARGS
36 gl_PREREQ_PRINTF_PARSE
37 gl_PREREQ_VASNWPRINTF
38 gl_PREREQ_ASNPRINTF
39 ])
40
41 # Prerequisites of lib/printf-args.h, lib/printf-args.c.
42 AC_DEFUN([gl_PREREQ_PRINTF_ARGS],
43 [
44 AC_REQUIRE([gt_TYPE_WCHAR_T])
45 AC_REQUIRE([gt_TYPE_WINT_T])
46 ])
47
48 # Prerequisites of lib/printf-parse.h, lib/printf-parse.c.
49 # Prerequisites of lib/wprintf-parse.h, lib/wprintf-parse.c.
50 AC_DEFUN([gl_PREREQ_PRINTF_PARSE],
51 [
52 AC_REQUIRE([gl_FEATURES_H])
53 AC_REQUIRE([gt_TYPE_WCHAR_T])
54 AC_REQUIRE([gt_TYPE_WINT_T])
55 AC_REQUIRE([AC_TYPE_SIZE_T])
56 AC_CHECK_TYPE([ptrdiff_t], ,
57 [AC_DEFINE([ptrdiff_t], [long],
58 [Define as the type of the result of subtracting two pointers, if the system doesn't define it.])
59 ])
60 AC_REQUIRE([gt_AC_TYPE_INTMAX_T])
61 ])
62
63 # Prerequisites of lib/vasnprintf.c if !WIDE_CHAR_VERSION.
64 AC_DEFUN_ONCE([gl_PREREQ_VASNPRINTF],
65 [
66 AC_CHECK_FUNCS([snprintf strnlen wcrtomb])
67 dnl Use the _snprintf function only if it is declared (because on NetBSD it
68 dnl is defined as a weak alias of snprintf; we prefer to use the latter).
69 AC_CHECK_DECLS([_snprintf], , , [[#include <stdio.h>]])
70 dnl We can avoid a lot of code by assuming that snprintf's return value
71 dnl conforms to ISO C99. So check that.
72 AC_REQUIRE([gl_SNPRINTF_RETVAL_C99])
73 case "$gl_cv_func_snprintf_retval_c99" in
74 *yes)
75 AC_DEFINE([HAVE_SNPRINTF_RETVAL_C99], [1],
76 [Define if the return value of the snprintf function is the number of
77 of bytes (excluding the terminating NUL) that would have been produced
78 if the buffer had been large enough.])
79 ;;
80 esac
81 dnl Additionally, the use of %n can be eliminated by assuming that snprintf
82 dnl always produces NUL-terminated strings (no truncation).
83 AC_REQUIRE([gl_SNPRINTF_TRUNCATION_C99])
84 case "$gl_cv_func_snprintf_truncation_c99" in
85 *yes)
86 AC_DEFINE([HAVE_SNPRINTF_TRUNCATION_C99], [1],
87 [Define if the string produced by the snprintf function is always NUL
88 terminated.])
89 ;;
90 esac
91 gl_PREREQ_VASNXPRINTF
92 ])
93
94 # Prerequisites of lib/vasnwprintf.c.
95 AC_DEFUN_ONCE([gl_PREREQ_VASNWPRINTF],
96 [
97 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
98 AC_CHECK_FUNCS_ONCE([swprintf wcsnlen mbrtowc])
99 AC_CHECK_DECLS([_snwprintf], , , [[#include <stdio.h>]])
100 AC_CHECK_DECLS([wcsnlen], , , [[#include <wchar.h>]])
101 gl_SWPRINTF_WORKS
102 case "$gl_cv_func_swprintf_works" in
103 *yes)
104 AC_DEFINE([HAVE_WORKING_SWPRINTF], [1],
105 [Define if the swprintf function works correctly when it produces output
106 that contains null wide characters.])
107 ;;
108 esac
109 gl_MBRTOWC_C_LOCALE
110 case "$gl_cv_func_mbrtowc_C_locale_sans_EILSEQ" in
111 *yes)
112 AC_CACHE_CHECK([whether swprintf in the C locale is free of encoding errors],
113 [gl_cv_func_swprintf_C_locale_sans_EILSEQ],
114 [
115 AC_RUN_IFELSE(
116 [AC_LANG_SOURCE([[
117 #ifndef __USE_MINGW_ANSI_STDIO
118 # define __USE_MINGW_ANSI_STDIO 1
119 #endif
120 #include <stdio.h>
121 #include <wchar.h>
122 int main()
123 {
124 int result = 0;
125 { /* This test fails on glibc 2.35, musl libc 1.2.4, FreeBSD 13.2, NetBSD 9.3,
126 OpenBSD 7.2, Cygwin 2.9.0.
127 Reported at <https://www.openwall.com/lists/musl/2023/06/12/2>. */
128 wchar_t buf[12];
129 int ret = swprintf (buf, 12, L"%c", '\377');
130 if (ret < 0)
131 result |= 1;
132 }
133 return result;
134 }]])],
135 [gl_cv_func_swprintf_C_locale_sans_EILSEQ=yes],
136 [gl_cv_func_swprintf_C_locale_sans_EILSEQ=no],
137 [case "$host_os" in
138 # Guess no on glibc systems.
139 *-gnu* | gnu*) gl_cv_func_swprintf_C_locale_sans_EILSEQ="guessing yes";;
140 # Guess no on musl systems.
141 *-musl* | midipix*) gl_cv_func_swprintf_C_locale_sans_EILSEQ="guessing no";;
142 # If we don't know, obey --enable-cross-guesses.
143 *) gl_cv_func_swprintf_C_locale_sans_EILSEQ="$gl_cross_guess_normal";;
144 esac
145 ])
146 ])
147 ;;
148 esac
149 if case "$gl_cv_func_mbrtowc_C_locale_sans_EILSEQ" in
150 *yes) false ;;
151 *) true ;;
152 esac \
153 || case "$gl_cv_func_swprintf_C_locale_sans_EILSEQ" in
154 *yes) false ;;
155 *) true ;;
156 esac; then
157 AC_DEFINE([NEED_WPRINTF_DIRECTIVE_C], [1],
158 [Define if the vasnwprintf implementation needs special code for
159 the 'c' directive.])
160 fi
161 gl_SWPRINTF_DIRECTIVE_LA
162 case "$gl_cv_func_swprintf_directive_la" in
163 *yes) ;;
164 *)
165 AC_DEFINE([NEED_WPRINTF_DIRECTIVE_LA], [1],
166 [Define if the vasnwprintf implementation needs special code for
167 the 'a' directive with 'long double' arguments.])
168 ;;
169 esac
170 gl_SWPRINTF_DIRECTIVE_LC
171 case "$gl_cv_func_swprintf_directive_lc" in
172 *yes) ;;
173 *)
174 AC_DEFINE([NEED_WPRINTF_DIRECTIVE_LC], [1],
175 [Define if the vasnwprintf implementation needs special code for
176 the 'lc' directive.])
177 ;;
178 esac
179 gl_MUSL_LIBC
180 gl_PREREQ_VASNXPRINTF
181 ])
182
183 # Common prerequisites of lib/vasnprintf.c and lib/vasnwprintf.c.
184 AC_DEFUN_ONCE([gl_PREREQ_VASNXPRINTF],
185 [
186 AC_REQUIRE([AC_FUNC_ALLOCA])
187 AC_REQUIRE([gt_TYPE_WCHAR_T])
188 AC_REQUIRE([gt_TYPE_WINT_T])
189 AC_CHECK_FUNCS([wcslen])
190 dnl Knowing DBL_EXPBIT0_WORD and DBL_EXPBIT0_BIT enables an optimization
191 dnl in the code for NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE.
192 AC_REQUIRE([gl_DOUBLE_EXPONENT_LOCATION])
193 ])
194
195 # Extra prerequisites of lib/vasnprintf.c for supporting 'long double'
196 # arguments.
197 AC_DEFUN_ONCE([gl_PREREQ_VASNPRINTF_LONG_DOUBLE],
198 [
199 AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
200 case "$gl_cv_func_printf_long_double" in
201 *yes)
202 ;;
203 *)
204 AC_DEFINE([NEED_PRINTF_LONG_DOUBLE], [1],
205 [Define if the vasnprintf implementation needs special code for
206 'long double' arguments.])
207 ;;
208 esac
209 ])
210
211 # Extra prerequisites of lib/vasnprintf.c for supporting infinite 'double'
212 # arguments.
213 AC_DEFUN([gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE],
214 [
215 AC_REQUIRE([gl_PRINTF_INFINITE])
216 case "$gl_cv_func_printf_infinite" in
217 *yes)
218 ;;
219 *)
220 AC_DEFINE([NEED_PRINTF_INFINITE_DOUBLE], [1],
221 [Define if the vasnprintf implementation needs special code for
222 infinite 'double' arguments.])
223 ;;
224 esac
225 ])
226
227 # Extra prerequisites of lib/vasnprintf.c for supporting infinite 'long double'
228 # arguments.
229 AC_DEFUN([gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE],
230 [
231 AC_REQUIRE([gl_PRINTF_INFINITE_LONG_DOUBLE])
232 dnl There is no need to set NEED_PRINTF_INFINITE_LONG_DOUBLE if
233 dnl NEED_PRINTF_LONG_DOUBLE is already set.
234 AC_REQUIRE([gl_PREREQ_VASNPRINTF_LONG_DOUBLE])
235 case "$gl_cv_func_printf_long_double" in
236 *yes)
237 case "$gl_cv_func_printf_infinite_long_double" in
238 *yes)
239 ;;
240 *)
241 AC_DEFINE([NEED_PRINTF_INFINITE_LONG_DOUBLE], [1],
242 [Define if the vasnprintf implementation needs special code for
243 infinite 'long double' arguments.])
244 ;;
245 esac
246 ;;
247 esac
248 ])
249
250 # Extra prerequisites of lib/vasnprintf.c for supporting the 'a' directive.
251 AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_A],
252 [
253 AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
254 case "$gl_cv_func_printf_directive_a" in
255 *yes)
256 ;;
257 *)
258 AC_DEFINE([NEED_PRINTF_DIRECTIVE_A], [1],
259 [Define if the vasnprintf implementation needs special code for
260 the 'a' and 'A' directives.])
261 gl_CHECK_FUNCS_ANDROID([nl_langinfo], [[#include <langinfo.h>]])
262 ;;
263 esac
264 ])
265
266 # Extra prerequisites of lib/vasnprintf.c for supporting the 'b' directive.
267 AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_B],
268 [
269 AC_REQUIRE([gl_PRINTF_DIRECTIVE_B])
270 case "$gl_cv_func_printf_directive_b" in
271 *yes)
272 ;;
273 *)
274 AC_DEFINE([NEED_PRINTF_DIRECTIVE_B], [1],
275 [Define if the vasnprintf implementation needs special code for
276 the 'b' directive.])
277 ;;
278 esac
279 ])
280
281 # Extra prerequisites of lib/vasnprintf.c for supporting the 'F' directive.
282 AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_F],
283 [
284 AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
285 case "$gl_cv_func_printf_directive_f" in
286 *yes)
287 ;;
288 *)
289 AC_DEFINE([NEED_PRINTF_DIRECTIVE_F], [1],
290 [Define if the vasnprintf implementation needs special code for
291 the 'F' directive.])
292 ;;
293 esac
294 ])
295
296 # Extra prerequisites of lib/vasnprintf.c for supporting the 'ls' directive.
297 AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_LS],
298 [
299 AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
300 case "$gl_cv_func_printf_directive_ls" in
301 *yes)
302 ;;
303 *)
304 AC_DEFINE([NEED_PRINTF_DIRECTIVE_LS], [1],
305 [Define if the vasnprintf implementation needs special code for
306 the 'ls' directive.])
307 ;;
308 esac
309 ])
310
311 # Extra prerequisites of lib/vasnprintf.c for supporting the 'lc' directive.
312 AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_LC],
313 [
314 AC_REQUIRE([gl_PRINTF_DIRECTIVE_LC])
315 case "$gl_cv_func_printf_directive_lc" in
316 *yes)
317 ;;
318 *)
319 AC_DEFINE([NEED_PRINTF_DIRECTIVE_LC], [1],
320 [Define if the vasnprintf implementation needs special code for
321 the 'lc' directive.])
322 ;;
323 esac
324 ])
325
326 # Extra prerequisites of lib/vasnprintf.c for supporting the ' flag.
327 AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_GROUPING],
328 [
329 AC_REQUIRE([gl_PRINTF_FLAG_GROUPING])
330 case "$gl_cv_func_printf_flag_grouping" in
331 *yes)
332 ;;
333 *)
334 AC_DEFINE([NEED_PRINTF_FLAG_GROUPING], [1],
335 [Define if the vasnprintf implementation needs special code for the
336 ' flag.])
337 ;;
338 esac
339 ])
340
341 # Extra prerequisites of lib/vasnprintf.c for supporting the '-' flag.
342 AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_LEFTADJUST],
343 [
344 AC_REQUIRE([gl_PRINTF_FLAG_LEFTADJUST])
345 case "$gl_cv_func_printf_flag_leftadjust" in
346 *yes)
347 ;;
348 *)
349 AC_DEFINE([NEED_PRINTF_FLAG_LEFTADJUST], [1],
350 [Define if the vasnprintf implementation needs special code for the
351 '-' flag.])
352 ;;
353 esac
354 ])
355
356 # Extra prerequisites of lib/vasnprintf.c for supporting the 0 flag.
357 AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_ZERO],
358 [
359 AC_REQUIRE([gl_PRINTF_FLAG_ZERO])
360 case "$gl_cv_func_printf_flag_zero" in
361 *yes)
362 ;;
363 *)
364 AC_DEFINE([NEED_PRINTF_FLAG_ZERO], [1],
365 [Define if the vasnprintf implementation needs special code for the
366 0 flag.])
367 ;;
368 esac
369 ])
370
371 # Extra prerequisites of lib/vasnprintf.c for supporting the # flag with a
372 # zero precision and a zero value in the 'x' and 'X' directives.
373 AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_ALT_PRECISION_ZERO],
374 [
375 AC_REQUIRE([gl_PRINTF_FLAG_ALT_PRECISION_ZERO])
376 case "$gl_cv_func_printf_flag_alt_precision_zero" in
377 *yes)
378 ;;
379 *)
380 AC_DEFINE([NEED_PRINTF_FLAG_ALT_PRECISION_ZERO], [1],
381 [Define if the vasnprintf implementation needs special code for the
382 # flag with a zero precision and a zero value in the 'x' and 'X' directives.])
383 ;;
384 esac
385 ])
386
387 # Extra prerequisites of lib/vasnprintf.c for supporting large precisions.
388 AC_DEFUN([gl_PREREQ_VASNPRINTF_PRECISION],
389 [
390 AC_REQUIRE([gl_PRINTF_PRECISION])
391 case "$gl_cv_func_printf_precision" in
392 *yes)
393 ;;
394 *)
395 AC_DEFINE([NEED_PRINTF_UNBOUNDED_PRECISION], [1],
396 [Define if the vasnprintf implementation needs special code for
397 supporting large precisions without arbitrary bounds.])
398 AC_DEFINE([NEED_PRINTF_DOUBLE], [1],
399 [Define if the vasnprintf implementation needs special code for
400 'double' arguments.])
401 AC_DEFINE([NEED_PRINTF_LONG_DOUBLE], [1],
402 [Define if the vasnprintf implementation needs special code for
403 'long double' arguments.])
404 ;;
405 esac
406 ])
407
408 # Extra prerequisites of lib/vasnprintf.c for surviving out-of-memory
409 # conditions.
410 AC_DEFUN([gl_PREREQ_VASNPRINTF_ENOMEM],
411 [
412 AC_REQUIRE([gl_PRINTF_ENOMEM])
413 case "$gl_cv_func_printf_enomem" in
414 *yes)
415 ;;
416 *)
417 AC_DEFINE([NEED_PRINTF_ENOMEM], [1],
418 [Define if the vasnprintf implementation needs special code for
419 surviving out-of-memory conditions.])
420 AC_DEFINE([NEED_PRINTF_DOUBLE], [1],
421 [Define if the vasnprintf implementation needs special code for
422 'double' arguments.])
423 AC_DEFINE([NEED_PRINTF_LONG_DOUBLE], [1],
424 [Define if the vasnprintf implementation needs special code for
425 'long double' arguments.])
426 ;;
427 esac
428 ])
429
430 # Prerequisites of lib/vasnprintf.c including all extras for POSIX compliance.
431 AC_DEFUN([gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS],
432 [
433 AC_REQUIRE([gl_PREREQ_VASNPRINTF])
434 gl_PREREQ_VASNPRINTF_LONG_DOUBLE
435 gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE
436 gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE
437 gl_PREREQ_VASNPRINTF_DIRECTIVE_A
438 gl_PREREQ_VASNPRINTF_DIRECTIVE_B
439 gl_PREREQ_VASNPRINTF_DIRECTIVE_F
440 gl_PREREQ_VASNPRINTF_DIRECTIVE_LS
441 gl_PREREQ_VASNPRINTF_DIRECTIVE_LC
442 gl_PREREQ_VASNPRINTF_FLAG_GROUPING
443 gl_PREREQ_VASNPRINTF_FLAG_LEFTADJUST
444 gl_PREREQ_VASNPRINTF_FLAG_ZERO
445 gl_PREREQ_VASNPRINTF_FLAG_ALT_PRECISION_ZERO
446 gl_PREREQ_VASNPRINTF_PRECISION
447 gl_PREREQ_VASNPRINTF_ENOMEM
448 ])
449
450 # Extra prerequisites of lib/vasnprintf.c for supporting the 'B' directive.
451 AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_UPPERCASE_B],
452 [
453 AC_REQUIRE([gl_PRINTF_DIRECTIVE_UPPERCASE_B])
454 case "$gl_cv_func_printf_directive_uppercase_b" in
455 *yes)
456 ;;
457 *)
458 AC_DEFINE([NEED_PRINTF_DIRECTIVE_UPPERCASE_B], [1],
459 [Define if the vasnprintf implementation needs special code for
460 the 'B' directive.])
461 ;;
462 esac
463 ])
464
465 # Prerequisites of lib/vasnprintf.c including all extras for POSIX compliance
466 # and GNU compatibility.
467 AC_DEFUN([gl_PREREQ_VASNPRINTF_WITH_GNU_EXTRAS],
468 [
469 gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS
470 AC_DEFINE([SUPPORT_GNU_PRINTF_DIRECTIVES], [1],
471 [Define if the vasnprintf implementation should support GNU compatible
472 printf directives.])
473 gl_PREREQ_VASNPRINTF_DIRECTIVE_UPPERCASE_B
474 ])
475
476 # Prerequisites of lib/asnprintf.c.
477 # Prerequisites of lib/asnwprintf.c.
478 AC_DEFUN([gl_PREREQ_ASNPRINTF],
479 [
480 ])