summaryrefslogtreecommitdiffstats
path: root/gl/m4/vasnprintf.m4
diff options
context:
space:
mode:
Diffstat (limited to 'gl/m4/vasnprintf.m4')
-rw-r--r--gl/m4/vasnprintf.m4275
1 files changed, 256 insertions, 19 deletions
diff --git a/gl/m4/vasnprintf.m4 b/gl/m4/vasnprintf.m4
index 6361c843..1d040d6e 100644
--- a/gl/m4/vasnprintf.m4
+++ b/gl/m4/vasnprintf.m4
@@ -1,13 +1,47 @@
1# vasnprintf.m4 serial 38 1# vasnprintf.m4
2dnl Copyright (C) 2002-2004, 2006-2023 Free Software Foundation, Inc. 2# serial 56
3dnl Copyright (C) 2002-2004, 2006-2025 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 6dnl with or without modifications, as long as this notice is preserved.
7dnl This file is offered as-is, without any warranty.
6 8
7AC_DEFUN([gl_FUNC_VASNPRINTF], 9AC_DEFUN([gl_FUNC_VASNPRINTF],
8[ 10[
11 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
9 AC_CHECK_FUNCS_ONCE([vasnprintf]) 12 AC_CHECK_FUNCS_ONCE([vasnprintf])
10 if test $ac_cv_func_vasnprintf = no; then 13 if test $ac_cv_func_vasnprintf = yes; then
14 dnl On Cygwin, in directives with a huge width, the width is ignored, and
15 dnl the function returns a wrong result.
16 AC_CACHE_CHECK([whether vasnprintf works],
17 [gl_cv_func_vasnprintf_works],
18 [AC_RUN_IFELSE(
19 [AC_LANG_SOURCE(
20 [[#include <stdio.h>
21 ]],
22 [[size_t len;
23 char *res = vasnprintf (NULL, &len, "x%03000000000dy\n", -17);
24 /* On Cygwin 3.4.6, res is "x-17y\n" and len == 6: wrong. */
25 return (res != NULL && len < 10);
26 ]])
27 ],
28 [gl_cv_func_vasnprintf_works=yes],
29 [gl_cv_func_vasnprintf_works=no],
30 [case "$host_os" in
31 # Guess no on Cygwin.
32 cygwin*) gl_cv_func_vasnprintf_works="guessing no";;
33 # If we don't know, obey --enable-cross-guesses.
34 *) gl_cv_func_vasnprintf_works="$gl_cross_guess_normal";;
35 esac
36 ])
37 ])
38 fi
39 if test $ac_cv_func_vasnprintf != yes \
40 || case "$gl_cv_func_vasnprintf_works" in
41 *yes) false;;
42 *) true;;
43 esac
44 then
11 gl_REPLACE_VASNPRINTF 45 gl_REPLACE_VASNPRINTF
12 fi 46 fi
13]) 47])
@@ -29,18 +63,26 @@ AC_DEFUN([gl_REPLACE_VASNPRINTF],
29 gl_PREREQ_ASNPRINTF 63 gl_PREREQ_ASNPRINTF
30]) 64])
31 65
66AC_DEFUN([gl_FUNC_VASNWPRINTF],
67[
68 AC_LIBOBJ([printf-args])
69 gl_PREREQ_PRINTF_ARGS
70 gl_PREREQ_PRINTF_PARSE
71 gl_PREREQ_VASNWPRINTF
72 gl_PREREQ_ASNPRINTF
73])
74
32# Prerequisites of lib/printf-args.h, lib/printf-args.c. 75# Prerequisites of lib/printf-args.h, lib/printf-args.c.
33AC_DEFUN([gl_PREREQ_PRINTF_ARGS], 76AC_DEFUN([gl_PREREQ_PRINTF_ARGS],
34[ 77[
35 AC_REQUIRE([gt_TYPE_WCHAR_T])
36 AC_REQUIRE([gt_TYPE_WINT_T]) 78 AC_REQUIRE([gt_TYPE_WINT_T])
37]) 79])
38 80
39# Prerequisites of lib/printf-parse.h, lib/printf-parse.c. 81# Prerequisites of lib/printf-parse.h, lib/printf-parse.c.
82# Prerequisites of lib/wprintf-parse.h, lib/wprintf-parse.c.
40AC_DEFUN([gl_PREREQ_PRINTF_PARSE], 83AC_DEFUN([gl_PREREQ_PRINTF_PARSE],
41[ 84[
42 AC_REQUIRE([gl_FEATURES_H]) 85 AC_REQUIRE([gl_FEATURES_H])
43 AC_REQUIRE([gt_TYPE_WCHAR_T])
44 AC_REQUIRE([gt_TYPE_WINT_T]) 86 AC_REQUIRE([gt_TYPE_WINT_T])
45 AC_REQUIRE([AC_TYPE_SIZE_T]) 87 AC_REQUIRE([AC_TYPE_SIZE_T])
46 AC_CHECK_TYPE([ptrdiff_t], , 88 AC_CHECK_TYPE([ptrdiff_t], ,
@@ -50,19 +92,13 @@ AC_DEFUN([gl_PREREQ_PRINTF_PARSE],
50 AC_REQUIRE([gt_AC_TYPE_INTMAX_T]) 92 AC_REQUIRE([gt_AC_TYPE_INTMAX_T])
51]) 93])
52 94
53# Prerequisites of lib/vasnprintf.c. 95# Prerequisites of lib/vasnprintf.c if !WIDE_CHAR_VERSION.
54AC_DEFUN_ONCE([gl_PREREQ_VASNPRINTF], 96AC_DEFUN_ONCE([gl_PREREQ_VASNPRINTF],
55[ 97[
56 AC_REQUIRE([AC_FUNC_ALLOCA]) 98 AC_CHECK_FUNCS([snprintf strnlen wcrtomb])
57 AC_REQUIRE([gt_TYPE_WCHAR_T])
58 AC_REQUIRE([gt_TYPE_WINT_T])
59 AC_CHECK_FUNCS([snprintf strnlen wcslen wcsnlen mbrtowc wcrtomb])
60 dnl Use the _snprintf function only if it is declared (because on NetBSD it 99 dnl Use the _snprintf function only if it is declared (because on NetBSD it
61 dnl is defined as a weak alias of snprintf; we prefer to use the latter). 100 dnl is defined as a weak alias of snprintf; we prefer to use the latter).
62 AC_CHECK_DECLS([_snprintf], , , [[#include <stdio.h>]]) 101 AC_CHECK_DECLS([_snprintf], , , [[#include <stdio.h>]])
63 dnl Knowing DBL_EXPBIT0_WORD and DBL_EXPBIT0_BIT enables an optimization
64 dnl in the code for NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE.
65 AC_REQUIRE([gl_DOUBLE_EXPONENT_LOCATION])
66 dnl We can avoid a lot of code by assuming that snprintf's return value 102 dnl We can avoid a lot of code by assuming that snprintf's return value
67 dnl conforms to ISO C99. So check that. 103 dnl conforms to ISO C99. So check that.
68 AC_REQUIRE([gl_SNPRINTF_RETVAL_C99]) 104 AC_REQUIRE([gl_SNPRINTF_RETVAL_C99])
@@ -84,6 +120,107 @@ AC_DEFUN_ONCE([gl_PREREQ_VASNPRINTF],
84 terminated.]) 120 terminated.])
85 ;; 121 ;;
86 esac 122 esac
123 gl_PREREQ_VASNXPRINTF
124])
125
126# Prerequisites of lib/vasnwprintf.c.
127AC_DEFUN_ONCE([gl_PREREQ_VASNWPRINTF],
128[
129 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
130 AC_CHECK_FUNCS_ONCE([swprintf wcsnlen mbrtowc])
131 AC_CHECK_DECLS([_snwprintf], , , [[#include <stdio.h>]])
132 AC_CHECK_DECLS([wcsnlen], , , [[#include <wchar.h>]])
133 gl_SWPRINTF_WORKS
134 case "$gl_cv_func_swprintf_works" in
135 *yes)
136 AC_DEFINE([HAVE_WORKING_SWPRINTF], [1],
137 [Define if the swprintf function works correctly when it produces output
138 that contains null wide characters.])
139 ;;
140 esac
141 gl_MBRTOWC_C_LOCALE
142 case "$gl_cv_func_mbrtowc_C_locale_sans_EILSEQ" in
143 *yes)
144 AC_CACHE_CHECK([whether swprintf in the C locale is free of encoding errors],
145 [gl_cv_func_swprintf_C_locale_sans_EILSEQ],
146 [
147 AC_RUN_IFELSE(
148 [AC_LANG_SOURCE([[
149#ifndef __USE_MINGW_ANSI_STDIO
150# define __USE_MINGW_ANSI_STDIO 1
151#endif
152#include <stdio.h>
153#include <wchar.h>
154int main()
155{
156 int result = 0;
157 { /* This test fails on glibc 2.35, musl libc 1.2.4, FreeBSD 13.2, NetBSD 9.3,
158 OpenBSD 7.2, Cygwin 2.9.0.
159 Reported at <https://www.openwall.com/lists/musl/2023/06/12/2>. */
160 wchar_t buf[12];
161 int ret = swprintf (buf, 12, L"%c", '\377');
162 if (ret < 0)
163 result |= 1;
164 }
165 return result;
166}]])],
167 [gl_cv_func_swprintf_C_locale_sans_EILSEQ=yes],
168 [gl_cv_func_swprintf_C_locale_sans_EILSEQ=no],
169 [case "$host_os" in
170 # Guess no on glibc systems.
171 *-gnu* | gnu*) gl_cv_func_swprintf_C_locale_sans_EILSEQ="guessing yes";;
172 # Guess no on musl systems.
173 *-musl* | midipix*) gl_cv_func_swprintf_C_locale_sans_EILSEQ="guessing no";;
174 # If we don't know, obey --enable-cross-guesses.
175 *) gl_cv_func_swprintf_C_locale_sans_EILSEQ="$gl_cross_guess_normal";;
176 esac
177 ])
178 ])
179 ;;
180 esac
181 if case "$gl_cv_func_mbrtowc_C_locale_sans_EILSEQ" in
182 *yes) false ;;
183 *) true ;;
184 esac \
185 || case "$gl_cv_func_swprintf_C_locale_sans_EILSEQ" in
186 *yes) false ;;
187 *) true ;;
188 esac; then
189 AC_DEFINE([NEED_WPRINTF_DIRECTIVE_C], [1],
190 [Define if the vasnwprintf implementation needs special code for
191 the 'c' directive.])
192 fi
193 gl_SWPRINTF_DIRECTIVE_LA
194 case "$gl_cv_func_swprintf_directive_la" in
195 *yes) ;;
196 *)
197 AC_DEFINE([NEED_WPRINTF_DIRECTIVE_LA], [1],
198 [Define if the vasnwprintf implementation needs special code for
199 the 'a' directive with 'long double' arguments.])
200 ;;
201 esac
202 gl_SWPRINTF_DIRECTIVE_LC
203 case "$gl_cv_func_swprintf_directive_lc" in
204 *yes) ;;
205 *)
206 AC_DEFINE([NEED_WPRINTF_DIRECTIVE_LC], [1],
207 [Define if the vasnwprintf implementation needs special code for
208 the 'lc' directive.])
209 ;;
210 esac
211 gl_MUSL_LIBC
212 gl_PREREQ_VASNXPRINTF
213])
214
215# Common prerequisites of lib/vasnprintf.c and lib/vasnwprintf.c.
216AC_DEFUN_ONCE([gl_PREREQ_VASNXPRINTF],
217[
218 AC_REQUIRE([AC_FUNC_ALLOCA])
219 AC_REQUIRE([gt_TYPE_WINT_T])
220 AC_CHECK_FUNCS([wcslen])
221 dnl Knowing DBL_EXPBIT0_WORD and DBL_EXPBIT0_BIT enables an optimization
222 dnl in the code for NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE.
223 AC_REQUIRE([gl_DOUBLE_EXPONENT_LOCATION])
87]) 224])
88 225
89# Extra prerequisites of lib/vasnprintf.c for supporting 'long double' 226# Extra prerequisites of lib/vasnprintf.c for supporting 'long double'
@@ -152,7 +289,22 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_A],
152 AC_DEFINE([NEED_PRINTF_DIRECTIVE_A], [1], 289 AC_DEFINE([NEED_PRINTF_DIRECTIVE_A], [1],
153 [Define if the vasnprintf implementation needs special code for 290 [Define if the vasnprintf implementation needs special code for
154 the 'a' and 'A' directives.]) 291 the 'a' and 'A' directives.])
155 AC_CHECK_FUNCS([nl_langinfo]) 292 gl_CHECK_FUNCS_ANDROID([nl_langinfo], [[#include <langinfo.h>]])
293 ;;
294 esac
295])
296
297# Extra prerequisites of lib/vasnprintf.c for supporting the 'b' directive.
298AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_B],
299[
300 AC_REQUIRE([gl_PRINTF_DIRECTIVE_B])
301 case "$gl_cv_func_printf_directive_b" in
302 *yes)
303 ;;
304 *)
305 AC_DEFINE([NEED_PRINTF_DIRECTIVE_B], [1],
306 [Define if the vasnprintf implementation needs special code for
307 the 'b' directive.])
156 ;; 308 ;;
157 esac 309 esac
158]) 310])
@@ -187,18 +339,57 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_LS],
187 esac 339 esac
188]) 340])
189 341
190# Extra prerequisites of lib/vasnprintf.c for supporting the ' flag. 342# Extra prerequisites of lib/vasnprintf.c for supporting the 'lc' directive.
191AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_GROUPING], 343AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_LC],
192[ 344[
193 AC_REQUIRE([gl_PRINTF_FLAG_GROUPING]) 345 AC_REQUIRE([gl_PRINTF_DIRECTIVE_LC])
194 case "$gl_cv_func_printf_flag_grouping" in 346 case "$gl_cv_func_printf_directive_lc" in
195 *yes) 347 *yes)
196 ;; 348 ;;
197 *) 349 *)
350 AC_DEFINE([NEED_PRINTF_DIRECTIVE_LC], [1],
351 [Define if the vasnprintf implementation needs special code for
352 the 'lc' directive.])
353 ;;
354 esac
355])
356
357# Extra prerequisites of lib/vasnprintf.c for supporting the ' flag.
358AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_GROUPING],
359[
360 AC_REQUIRE([AC_CANONICAL_HOST])
361 AC_REQUIRE([gl_PRINTF_FLAG_GROUPING])
362 AC_REQUIRE([gl_PRINTF_FLAG_GROUPING_INT_PRECISION])
363 AC_REQUIRE([gl_PRINTF_FLAG_GROUPING_MULTIBYTE])
364 case "$host_os" in
365 mingw* | windows*)
366 dnl MSVC does not support the ' flag at all.
367 dnl mingw does not support it, unless __USE_MINGW_ANSI_STDIO is defined.
368 dnl mingw also has other bugs regarding the ' flag.
198 AC_DEFINE([NEED_PRINTF_FLAG_GROUPING], [1], 369 AC_DEFINE([NEED_PRINTF_FLAG_GROUPING], [1],
199 [Define if the vasnprintf implementation needs special code for the 370 [Define if the vasnprintf implementation needs special code for the
200 ' flag.]) 371 ' flag.])
201 ;; 372 ;;
373 *)
374 case "$gl_cv_func_printf_flag_grouping,$gl_cv_func_printf_flag_grouping_multibyte" in
375 *yes,*yes)
376 case "$gl_cv_func_printf_flag_grouping_int_precision" in
377 *yes)
378 ;;
379 *)
380 AC_DEFINE([NEED_PRINTF_FLAG_GROUPING_INT], [1],
381 [Define if the vasnprintf implementation needs special code for the
382 ' flag, for integer directives only.])
383 ;;
384 esac
385 ;;
386 *)
387 AC_DEFINE([NEED_PRINTF_FLAG_GROUPING], [1],
388 [Define if the vasnprintf implementation needs special code for the
389 ' flag.])
390 ;;
391 esac
392 ;;
202 esac 393 esac
203]) 394])
204 395
@@ -232,6 +423,22 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_ZERO],
232 esac 423 esac
233]) 424])
234 425
426# Extra prerequisites of lib/vasnprintf.c for supporting the # flag with a
427# zero precision and a zero value in the 'x' and 'X' directives.
428AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_ALT_PRECISION_ZERO],
429[
430 AC_REQUIRE([gl_PRINTF_FLAG_ALT_PRECISION_ZERO])
431 case "$gl_cv_func_printf_flag_alt_precision_zero" in
432 *yes)
433 ;;
434 *)
435 AC_DEFINE([NEED_PRINTF_FLAG_ALT_PRECISION_ZERO], [1],
436 [Define if the vasnprintf implementation needs special code for the
437 # flag with a zero precision and a zero value in the 'x' and 'X' directives.])
438 ;;
439 esac
440])
441
235# Extra prerequisites of lib/vasnprintf.c for supporting large precisions. 442# Extra prerequisites of lib/vasnprintf.c for supporting large precisions.
236AC_DEFUN([gl_PREREQ_VASNPRINTF_PRECISION], 443AC_DEFUN([gl_PREREQ_VASNPRINTF_PRECISION],
237[ 444[
@@ -276,23 +483,53 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF_ENOMEM],
276]) 483])
277 484
278# Prerequisites of lib/vasnprintf.c including all extras for POSIX compliance. 485# Prerequisites of lib/vasnprintf.c including all extras for POSIX compliance.
279AC_DEFUN([gl_PREREQ_VASNPRINTF_WITH_EXTRAS], 486AC_DEFUN([gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS],
280[ 487[
281 AC_REQUIRE([gl_PREREQ_VASNPRINTF]) 488 AC_REQUIRE([gl_PREREQ_VASNPRINTF])
282 gl_PREREQ_VASNPRINTF_LONG_DOUBLE 489 gl_PREREQ_VASNPRINTF_LONG_DOUBLE
283 gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE 490 gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE
284 gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE 491 gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE
285 gl_PREREQ_VASNPRINTF_DIRECTIVE_A 492 gl_PREREQ_VASNPRINTF_DIRECTIVE_A
493 gl_PREREQ_VASNPRINTF_DIRECTIVE_B
286 gl_PREREQ_VASNPRINTF_DIRECTIVE_F 494 gl_PREREQ_VASNPRINTF_DIRECTIVE_F
287 gl_PREREQ_VASNPRINTF_DIRECTIVE_LS 495 gl_PREREQ_VASNPRINTF_DIRECTIVE_LS
496 gl_PREREQ_VASNPRINTF_DIRECTIVE_LC
288 gl_PREREQ_VASNPRINTF_FLAG_GROUPING 497 gl_PREREQ_VASNPRINTF_FLAG_GROUPING
289 gl_PREREQ_VASNPRINTF_FLAG_LEFTADJUST 498 gl_PREREQ_VASNPRINTF_FLAG_LEFTADJUST
290 gl_PREREQ_VASNPRINTF_FLAG_ZERO 499 gl_PREREQ_VASNPRINTF_FLAG_ZERO
500 gl_PREREQ_VASNPRINTF_FLAG_ALT_PRECISION_ZERO
291 gl_PREREQ_VASNPRINTF_PRECISION 501 gl_PREREQ_VASNPRINTF_PRECISION
292 gl_PREREQ_VASNPRINTF_ENOMEM 502 gl_PREREQ_VASNPRINTF_ENOMEM
293]) 503])
294 504
505# Extra prerequisites of lib/vasnprintf.c for supporting the 'B' directive.
506AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_UPPERCASE_B],
507[
508 AC_REQUIRE([gl_PRINTF_DIRECTIVE_UPPERCASE_B])
509 case "$gl_cv_func_printf_directive_uppercase_b" in
510 *yes)
511 ;;
512 *)
513 AC_DEFINE([NEED_PRINTF_DIRECTIVE_UPPERCASE_B], [1],
514 [Define if the vasnprintf implementation needs special code for
515 the 'B' directive.])
516 ;;
517 esac
518])
519
520# Prerequisites of lib/vasnprintf.c including all extras for POSIX compliance
521# and GNU compatibility.
522AC_DEFUN([gl_PREREQ_VASNPRINTF_WITH_GNU_EXTRAS],
523[
524 gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS
525 AC_DEFINE([SUPPORT_GNU_PRINTF_DIRECTIVES], [1],
526 [Define if the vasnprintf implementation should support GNU compatible
527 printf directives.])
528 gl_PREREQ_VASNPRINTF_DIRECTIVE_UPPERCASE_B
529])
530
295# Prerequisites of lib/asnprintf.c. 531# Prerequisites of lib/asnprintf.c.
532# Prerequisites of lib/asnwprintf.c.
296AC_DEFUN([gl_PREREQ_ASNPRINTF], 533AC_DEFUN([gl_PREREQ_ASNPRINTF],
297[ 534[
298]) 535])