Debian Codegraph @

m4/vasnprintf.m4

raw
1 # vasnprintf.m4 serial 50
2 dnl Copyright (C) 2002-2004, 2006-2023 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 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_CHECK_FUNCS_ONCE([swprintf wcsnlen mbrtowc])
98 AC_CHECK_DECLS([_snwprintf], , , [[#include <stdio.h>]])
99 AC_CHECK_DECLS([wcsnlen], , , [[#include <wchar.h>]])
100 gl_SWPRINTF_WORKS
101 case "$gl_cv_func_swprintf_works" in
102 *yes)
103 AC_DEFINE([HAVE_WORKING_SWPRINTF], [1],
104 [Define if the swprintf function works correctly when it produces output
105 that contains null wide characters.])
106 ;;
107 esac
108 gl_MBRTOWC_C_LOCALE
109 case "$gl_cv_func_mbrtowc_C_locale_sans_EILSEQ" in
110 *yes)
111 AC_CACHE_CHECK([whether swprintf in the C locale is free of encoding errors],
112 [gl_cv_func_swprintf_C_locale_sans_EILSEQ],
113 [
114 AC_RUN_IFELSE(
115 [AC_LANG_SOURCE([[
116 #ifndef __USE_MINGW_ANSI_STDIO
117 # define __USE_MINGW_ANSI_STDIO 1
118 #endif
119 #include <stdio.h>
120 #include <wchar.h>
121 int main()
122 {
123 int result = 0;
124 { /* This test fails on glibc 2.35, musl libc 1.2.4, FreeBSD 13.2, NetBSD 9.3,
125 OpenBSD 7.2, Cygwin 2.9.0.
126 Reported at <https://www.openwall.com/lists/musl/2023/06/12/2>. */
127 wchar_t buf[12];
128 int ret = swprintf (buf, 12, L"%c", '\377');
129 if (ret < 0)
130 result |= 1;
131 }
132 return result;
133 }]])],
134 [gl_cv_func_swprintf_C_locale_sans_EILSEQ=yes],
135 [gl_cv_func_swprintf_C_locale_sans_EILSEQ=no],
136 [case "$host_os" in
137 # Guess no on glibc systems.
138 *-gnu* | gnu*) gl_cv_func_swprintf_C_locale_sans_EILSEQ="guessing yes";;
139 # Guess no on musl systems.
140 *-musl* | midipix*) gl_cv_func_swprintf_C_locale_sans_EILSEQ="guessing no";;
141 # If we don't know, obey --enable-cross-guesses.
142 *) gl_cv_func_swprintf_C_locale_sans_EILSEQ="$gl_cross_guess_normal";;
143 esac
144 ])
145 ])
146 ;;
147 esac
148 if case "$gl_cv_func_mbrtowc_C_locale_sans_EILSEQ" in
149 *yes) false ;;
150 *) true ;;
151 esac \
152 || case "$gl_cv_func_swprintf_C_locale_sans_EILSEQ" in
153 *yes) false ;;
154 *) true ;;
155 esac; then
156 AC_DEFINE([NEED_WPRINTF_DIRECTIVE_C], [1],
157 [Define if the vasnwprintf implementation needs special code for
158 the 'c' directive.])
159 fi
160 gl_SWPRINTF_DIRECTIVE_LA
161 case "$gl_cv_func_swprintf_directive_la" in
162 *yes) ;;
163 *)
164 AC_DEFINE([NEED_WPRINTF_DIRECTIVE_LA], [1],
165 [Define if the vasnwprintf implementation needs special code for
166 the 'a' directive with 'long double' arguments.])
167 ;;
168 esac
169 gl_SWPRINTF_DIRECTIVE_LC
170 case "$gl_cv_func_swprintf_directive_lc" in
171 *yes) ;;
172 *)
173 AC_DEFINE([NEED_WPRINTF_DIRECTIVE_LC], [1],
174 [Define if the vasnwprintf implementation needs special code for
175 the 'lc' directive.])
176 ;;
177 esac
178 gl_MUSL_LIBC
179 gl_PREREQ_VASNXPRINTF
180 ])
181
182 # Common prerequisites of lib/vasnprintf.c and lib/vasnwprintf.c.
183 AC_DEFUN_ONCE([gl_PREREQ_VASNXPRINTF],
184 [
185 AC_REQUIRE([AC_FUNC_ALLOCA])
186 AC_REQUIRE([gt_TYPE_WCHAR_T])
187 AC_REQUIRE([gt_TYPE_WINT_T])
188 AC_CHECK_FUNCS([wcslen])
189 dnl Knowing DBL_EXPBIT0_WORD and DBL_EXPBIT0_BIT enables an optimization
190 dnl in the code for NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE.
191 AC_REQUIRE([gl_DOUBLE_EXPONENT_LOCATION])
192 ])
193
194 # Extra prerequisites of lib/vasnprintf.c for supporting 'long double'
195 # arguments.
196 AC_DEFUN_ONCE([gl_PREREQ_VASNPRINTF_LONG_DOUBLE],
197 [
198 AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
199 case "$gl_cv_func_printf_long_double" in
200 *yes)
201 ;;
202 *)
203 AC_DEFINE([NEED_PRINTF_LONG_DOUBLE], [1],
204 [Define if the vasnprintf implementation needs special code for
205 'long double' arguments.])
206 ;;
207 esac
208 ])
209
210 # Extra prerequisites of lib/vasnprintf.c for supporting infinite 'double'
211 # arguments.
212 AC_DEFUN([gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE],
213 [
214 AC_REQUIRE([gl_PRINTF_INFINITE])
215 case "$gl_cv_func_printf_infinite" in
216 *yes)
217 ;;
218 *)
219 AC_DEFINE([NEED_PRINTF_INFINITE_DOUBLE], [1],
220 [Define if the vasnprintf implementation needs special code for
221 infinite 'double' arguments.])
222 ;;
223 esac
224 ])
225
226 # Extra prerequisites of lib/vasnprintf.c for supporting infinite 'long double'
227 # arguments.
228 AC_DEFUN([gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE],
229 [
230 AC_REQUIRE([gl_PRINTF_INFINITE_LONG_DOUBLE])
231 dnl There is no need to set NEED_PRINTF_INFINITE_LONG_DOUBLE if
232 dnl NEED_PRINTF_LONG_DOUBLE is already set.
233 AC_REQUIRE([gl_PREREQ_VASNPRINTF_LONG_DOUBLE])
234 case "$gl_cv_func_printf_long_double" in
235 *yes)
236 case "$gl_cv_func_printf_infinite_long_double" in
237 *yes)
238 ;;
239 *)
240 AC_DEFINE([NEED_PRINTF_INFINITE_LONG_DOUBLE], [1],
241 [Define if the vasnprintf implementation needs special code for
242 infinite 'long double' arguments.])
243 ;;
244 esac
245 ;;
246 esac
247 ])
248
249 # Extra prerequisites of lib/vasnprintf.c for supporting the 'a' directive.
250 AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_A],
251 [
252 AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
253 case "$gl_cv_func_printf_directive_a" in
254 *yes)
255 ;;
256 *)
257 AC_DEFINE([NEED_PRINTF_DIRECTIVE_A], [1],
258 [Define if the vasnprintf implementation needs special code for
259 the 'a' and 'A' directives.])
260 gl_CHECK_FUNCS_ANDROID([nl_langinfo], [[#include <langinfo.h>]])
261 ;;
262 esac
263 ])
264
265 # Extra prerequisites of lib/vasnprintf.c for supporting the 'b' directive.
266 AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_B],
267 [
268 AC_REQUIRE([gl_PRINTF_DIRECTIVE_B])
269 case "$gl_cv_func_printf_directive_b" in
270 *yes)
271 ;;
272 *)
273 AC_DEFINE([NEED_PRINTF_DIRECTIVE_B], [1],
274 [Define if the vasnprintf implementation needs special code for
275 the 'b' directive.])
276 ;;
277 esac
278 ])
279
280 # Extra prerequisites of lib/vasnprintf.c for supporting the 'F' directive.
281 AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_F],
282 [
283 AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
284 case "$gl_cv_func_printf_directive_f" in
285 *yes)
286 ;;
287 *)
288 AC_DEFINE([NEED_PRINTF_DIRECTIVE_F], [1],
289 [Define if the vasnprintf implementation needs special code for
290 the 'F' directive.])
291 ;;
292 esac
293 ])
294
295 # Extra prerequisites of lib/vasnprintf.c for supporting the 'ls' directive.
296 AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_LS],
297 [
298 AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
299 case "$gl_cv_func_printf_directive_ls" in
300 *yes)
301 ;;
302 *)
303 AC_DEFINE([NEED_PRINTF_DIRECTIVE_LS], [1],
304 [Define if the vasnprintf implementation needs special code for
305 the 'ls' directive.])
306 ;;
307 esac
308 ])
309
310 # Extra prerequisites of lib/vasnprintf.c for supporting the 'lc' directive.
311 AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_LC],
312 [
313 AC_REQUIRE([gl_PRINTF_DIRECTIVE_LC])
314 case "$gl_cv_func_printf_directive_lc" in
315 *yes)
316 ;;
317 *)
318 AC_DEFINE([NEED_PRINTF_DIRECTIVE_LC], [1],
319 [Define if the vasnprintf implementation needs special code for
320 the 'lc' directive.])
321 ;;
322 esac
323 ])
324
325 # Extra prerequisites of lib/vasnprintf.c for supporting the ' flag.
326 AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_GROUPING],
327 [
328 AC_REQUIRE([gl_PRINTF_FLAG_GROUPING])
329 case "$gl_cv_func_printf_flag_grouping" in
330 *yes)
331 ;;
332 *)
333 AC_DEFINE([NEED_PRINTF_FLAG_GROUPING], [1],
334 [Define if the vasnprintf implementation needs special code for the
335 ' flag.])
336 ;;
337 esac
338 ])
339
340 # Extra prerequisites of lib/vasnprintf.c for supporting the '-' flag.
341 AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_LEFTADJUST],
342 [
343 AC_REQUIRE([gl_PRINTF_FLAG_LEFTADJUST])
344 case "$gl_cv_func_printf_flag_leftadjust" in
345 *yes)
346 ;;
347 *)
348 AC_DEFINE([NEED_PRINTF_FLAG_LEFTADJUST], [1],
349 [Define if the vasnprintf implementation needs special code for the
350 '-' flag.])
351 ;;
352 esac
353 ])
354
355 # Extra prerequisites of lib/vasnprintf.c for supporting the 0 flag.
356 AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_ZERO],
357 [
358 AC_REQUIRE([gl_PRINTF_FLAG_ZERO])
359 case "$gl_cv_func_printf_flag_zero" in
360 *yes)
361 ;;
362 *)
363 AC_DEFINE([NEED_PRINTF_FLAG_ZERO], [1],
364 [Define if the vasnprintf implementation needs special code for the
365 0 flag.])
366 ;;
367 esac
368 ])
369
370 # Extra prerequisites of lib/vasnprintf.c for supporting large precisions.
371 AC_DEFUN([gl_PREREQ_VASNPRINTF_PRECISION],
372 [
373 AC_REQUIRE([gl_PRINTF_PRECISION])
374 case "$gl_cv_func_printf_precision" in
375 *yes)
376 ;;
377 *)
378 AC_DEFINE([NEED_PRINTF_UNBOUNDED_PRECISION], [1],
379 [Define if the vasnprintf implementation needs special code for
380 supporting large precisions without arbitrary bounds.])
381 AC_DEFINE([NEED_PRINTF_DOUBLE], [1],
382 [Define if the vasnprintf implementation needs special code for
383 'double' arguments.])
384 AC_DEFINE([NEED_PRINTF_LONG_DOUBLE], [1],
385 [Define if the vasnprintf implementation needs special code for
386 'long double' arguments.])
387 ;;
388 esac
389 ])
390
391 # Extra prerequisites of lib/vasnprintf.c for surviving out-of-memory
392 # conditions.
393 AC_DEFUN([gl_PREREQ_VASNPRINTF_ENOMEM],
394 [
395 AC_REQUIRE([gl_PRINTF_ENOMEM])
396 case "$gl_cv_func_printf_enomem" in
397 *yes)
398 ;;
399 *)
400 AC_DEFINE([NEED_PRINTF_ENOMEM], [1],
401 [Define if the vasnprintf implementation needs special code for
402 surviving out-of-memory conditions.])
403 AC_DEFINE([NEED_PRINTF_DOUBLE], [1],
404 [Define if the vasnprintf implementation needs special code for
405 'double' arguments.])
406 AC_DEFINE([NEED_PRINTF_LONG_DOUBLE], [1],
407 [Define if the vasnprintf implementation needs special code for
408 'long double' arguments.])
409 ;;
410 esac
411 ])
412
413 # Prerequisites of lib/vasnprintf.c including all extras for POSIX compliance.
414 AC_DEFUN([gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS],
415 [
416 AC_REQUIRE([gl_PREREQ_VASNPRINTF])
417 gl_PREREQ_VASNPRINTF_LONG_DOUBLE
418 gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE
419 gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE
420 gl_PREREQ_VASNPRINTF_DIRECTIVE_A
421 gl_PREREQ_VASNPRINTF_DIRECTIVE_B
422 gl_PREREQ_VASNPRINTF_DIRECTIVE_F
423 gl_PREREQ_VASNPRINTF_DIRECTIVE_LS
424 gl_PREREQ_VASNPRINTF_DIRECTIVE_LC
425 gl_PREREQ_VASNPRINTF_FLAG_GROUPING
426 gl_PREREQ_VASNPRINTF_FLAG_LEFTADJUST
427 gl_PREREQ_VASNPRINTF_FLAG_ZERO
428 gl_PREREQ_VASNPRINTF_PRECISION
429 gl_PREREQ_VASNPRINTF_ENOMEM
430 ])
431
432 # Extra prerequisites of lib/vasnprintf.c for supporting the 'B' directive.
433 AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_UPPERCASE_B],
434 [
435 AC_REQUIRE([gl_PRINTF_DIRECTIVE_UPPERCASE_B])
436 case "$gl_cv_func_printf_directive_uppercase_b" in
437 *yes)
438 ;;
439 *)
440 AC_DEFINE([NEED_PRINTF_DIRECTIVE_UPPERCASE_B], [1],
441 [Define if the vasnprintf implementation needs special code for
442 the 'B' directive.])
443 ;;
444 esac
445 ])
446
447 # Prerequisites of lib/vasnprintf.c including all extras for POSIX compliance
448 # and GNU compatibility.
449 AC_DEFUN([gl_PREREQ_VASNPRINTF_WITH_GNU_EXTRAS],
450 [
451 gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS
452 AC_DEFINE([SUPPORT_GNU_PRINTF_DIRECTIVES], [1],
453 [Define if the vasnprintf implementation should support GNU compatible
454 printf directives.])
455 gl_PREREQ_VASNPRINTF_DIRECTIVE_UPPERCASE_B
456 ])
457
458 # Prerequisites of lib/asnprintf.c.
459 # Prerequisites of lib/asnwprintf.c.
460 AC_DEFUN([gl_PREREQ_ASNPRINTF],
461 [
462 ])