diff options
Diffstat (limited to 'gl/m4/vasnprintf.m4')
| -rw-r--r-- | gl/m4/vasnprintf.m4 | 207 |
1 files changed, 195 insertions, 12 deletions
diff --git a/gl/m4/vasnprintf.m4 b/gl/m4/vasnprintf.m4 index 6361c843..1ea2055e 100644 --- a/gl/m4/vasnprintf.m4 +++ b/gl/m4/vasnprintf.m4 | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | # vasnprintf.m4 serial 38 | 1 | # vasnprintf.m4 |
| 2 | dnl Copyright (C) 2002-2004, 2006-2023 Free Software Foundation, Inc. | 2 | # serial 52 |
| 3 | dnl Copyright (C) 2002-2004, 2006-2024 Free Software Foundation, Inc. | ||
| 3 | dnl This file is free software; the Free Software Foundation | 4 | dnl This file is free software; the Free Software Foundation |
| 4 | dnl gives unlimited permission to copy and/or distribute it, | 5 | dnl gives unlimited permission to copy and/or distribute it, |
| 5 | dnl with or without modifications, as long as this notice is preserved. | 6 | dnl with or without modifications, as long as this notice is preserved. |
| @@ -29,6 +30,15 @@ AC_DEFUN([gl_REPLACE_VASNPRINTF], | |||
| 29 | gl_PREREQ_ASNPRINTF | 30 | gl_PREREQ_ASNPRINTF |
| 30 | ]) | 31 | ]) |
| 31 | 32 | ||
| 33 | AC_DEFUN([gl_FUNC_VASNWPRINTF], | ||
| 34 | [ | ||
| 35 | AC_LIBOBJ([printf-args]) | ||
| 36 | gl_PREREQ_PRINTF_ARGS | ||
| 37 | gl_PREREQ_PRINTF_PARSE | ||
| 38 | gl_PREREQ_VASNWPRINTF | ||
| 39 | gl_PREREQ_ASNPRINTF | ||
| 40 | ]) | ||
| 41 | |||
| 32 | # Prerequisites of lib/printf-args.h, lib/printf-args.c. | 42 | # Prerequisites of lib/printf-args.h, lib/printf-args.c. |
| 33 | AC_DEFUN([gl_PREREQ_PRINTF_ARGS], | 43 | AC_DEFUN([gl_PREREQ_PRINTF_ARGS], |
| 34 | [ | 44 | [ |
| @@ -37,6 +47,7 @@ AC_DEFUN([gl_PREREQ_PRINTF_ARGS], | |||
| 37 | ]) | 47 | ]) |
| 38 | 48 | ||
| 39 | # Prerequisites of lib/printf-parse.h, lib/printf-parse.c. | 49 | # Prerequisites of lib/printf-parse.h, lib/printf-parse.c. |
| 50 | # Prerequisites of lib/wprintf-parse.h, lib/wprintf-parse.c. | ||
| 40 | AC_DEFUN([gl_PREREQ_PRINTF_PARSE], | 51 | AC_DEFUN([gl_PREREQ_PRINTF_PARSE], |
| 41 | [ | 52 | [ |
| 42 | AC_REQUIRE([gl_FEATURES_H]) | 53 | AC_REQUIRE([gl_FEATURES_H]) |
| @@ -50,19 +61,13 @@ AC_DEFUN([gl_PREREQ_PRINTF_PARSE], | |||
| 50 | AC_REQUIRE([gt_AC_TYPE_INTMAX_T]) | 61 | AC_REQUIRE([gt_AC_TYPE_INTMAX_T]) |
| 51 | ]) | 62 | ]) |
| 52 | 63 | ||
| 53 | # Prerequisites of lib/vasnprintf.c. | 64 | # Prerequisites of lib/vasnprintf.c if !WIDE_CHAR_VERSION. |
| 54 | AC_DEFUN_ONCE([gl_PREREQ_VASNPRINTF], | 65 | AC_DEFUN_ONCE([gl_PREREQ_VASNPRINTF], |
| 55 | [ | 66 | [ |
| 56 | AC_REQUIRE([AC_FUNC_ALLOCA]) | 67 | 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 | 68 | 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). | 69 | dnl is defined as a weak alias of snprintf; we prefer to use the latter). |
| 62 | AC_CHECK_DECLS([_snprintf], , , [[#include <stdio.h>]]) | 70 | 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 | 71 | dnl We can avoid a lot of code by assuming that snprintf's return value |
| 67 | dnl conforms to ISO C99. So check that. | 72 | dnl conforms to ISO C99. So check that. |
| 68 | AC_REQUIRE([gl_SNPRINTF_RETVAL_C99]) | 73 | AC_REQUIRE([gl_SNPRINTF_RETVAL_C99]) |
| @@ -84,6 +89,108 @@ AC_DEFUN_ONCE([gl_PREREQ_VASNPRINTF], | |||
| 84 | terminated.]) | 89 | terminated.]) |
| 85 | ;; | 90 | ;; |
| 86 | esac | 91 | esac |
| 92 | gl_PREREQ_VASNXPRINTF | ||
| 93 | ]) | ||
| 94 | |||
| 95 | # Prerequisites of lib/vasnwprintf.c. | ||
| 96 | AC_DEFUN_ONCE([gl_PREREQ_VASNWPRINTF], | ||
| 97 | [ | ||
| 98 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | ||
| 99 | AC_CHECK_FUNCS_ONCE([swprintf wcsnlen mbrtowc]) | ||
| 100 | AC_CHECK_DECLS([_snwprintf], , , [[#include <stdio.h>]]) | ||
| 101 | AC_CHECK_DECLS([wcsnlen], , , [[#include <wchar.h>]]) | ||
| 102 | gl_SWPRINTF_WORKS | ||
| 103 | case "$gl_cv_func_swprintf_works" in | ||
| 104 | *yes) | ||
| 105 | AC_DEFINE([HAVE_WORKING_SWPRINTF], [1], | ||
| 106 | [Define if the swprintf function works correctly when it produces output | ||
| 107 | that contains null wide characters.]) | ||
| 108 | ;; | ||
| 109 | esac | ||
| 110 | gl_MBRTOWC_C_LOCALE | ||
| 111 | case "$gl_cv_func_mbrtowc_C_locale_sans_EILSEQ" in | ||
| 112 | *yes) | ||
| 113 | AC_CACHE_CHECK([whether swprintf in the C locale is free of encoding errors], | ||
| 114 | [gl_cv_func_swprintf_C_locale_sans_EILSEQ], | ||
| 115 | [ | ||
| 116 | AC_RUN_IFELSE( | ||
| 117 | [AC_LANG_SOURCE([[ | ||
| 118 | #ifndef __USE_MINGW_ANSI_STDIO | ||
| 119 | # define __USE_MINGW_ANSI_STDIO 1 | ||
| 120 | #endif | ||
| 121 | #include <stdio.h> | ||
| 122 | #include <wchar.h> | ||
| 123 | int main() | ||
| 124 | { | ||
| 125 | int result = 0; | ||
| 126 | { /* This test fails on glibc 2.35, musl libc 1.2.4, FreeBSD 13.2, NetBSD 9.3, | ||
| 127 | OpenBSD 7.2, Cygwin 2.9.0. | ||
| 128 | Reported at <https://www.openwall.com/lists/musl/2023/06/12/2>. */ | ||
| 129 | wchar_t buf[12]; | ||
| 130 | int ret = swprintf (buf, 12, L"%c", '\377'); | ||
| 131 | if (ret < 0) | ||
| 132 | result |= 1; | ||
| 133 | } | ||
| 134 | return result; | ||
| 135 | }]])], | ||
| 136 | [gl_cv_func_swprintf_C_locale_sans_EILSEQ=yes], | ||
| 137 | [gl_cv_func_swprintf_C_locale_sans_EILSEQ=no], | ||
| 138 | [case "$host_os" in | ||
| 139 | # Guess no on glibc systems. | ||
| 140 | *-gnu* | gnu*) gl_cv_func_swprintf_C_locale_sans_EILSEQ="guessing yes";; | ||
| 141 | # Guess no on musl systems. | ||
| 142 | *-musl* | midipix*) gl_cv_func_swprintf_C_locale_sans_EILSEQ="guessing no";; | ||
| 143 | # If we don't know, obey --enable-cross-guesses. | ||
| 144 | *) gl_cv_func_swprintf_C_locale_sans_EILSEQ="$gl_cross_guess_normal";; | ||
| 145 | esac | ||
| 146 | ]) | ||
| 147 | ]) | ||
| 148 | ;; | ||
| 149 | esac | ||
| 150 | if case "$gl_cv_func_mbrtowc_C_locale_sans_EILSEQ" in | ||
| 151 | *yes) false ;; | ||
| 152 | *) true ;; | ||
| 153 | esac \ | ||
| 154 | || case "$gl_cv_func_swprintf_C_locale_sans_EILSEQ" in | ||
| 155 | *yes) false ;; | ||
| 156 | *) true ;; | ||
| 157 | esac; then | ||
| 158 | AC_DEFINE([NEED_WPRINTF_DIRECTIVE_C], [1], | ||
| 159 | [Define if the vasnwprintf implementation needs special code for | ||
| 160 | the 'c' directive.]) | ||
| 161 | fi | ||
| 162 | gl_SWPRINTF_DIRECTIVE_LA | ||
| 163 | case "$gl_cv_func_swprintf_directive_la" in | ||
| 164 | *yes) ;; | ||
| 165 | *) | ||
| 166 | AC_DEFINE([NEED_WPRINTF_DIRECTIVE_LA], [1], | ||
| 167 | [Define if the vasnwprintf implementation needs special code for | ||
| 168 | the 'a' directive with 'long double' arguments.]) | ||
| 169 | ;; | ||
| 170 | esac | ||
| 171 | gl_SWPRINTF_DIRECTIVE_LC | ||
| 172 | case "$gl_cv_func_swprintf_directive_lc" in | ||
| 173 | *yes) ;; | ||
| 174 | *) | ||
| 175 | AC_DEFINE([NEED_WPRINTF_DIRECTIVE_LC], [1], | ||
| 176 | [Define if the vasnwprintf implementation needs special code for | ||
| 177 | the 'lc' directive.]) | ||
| 178 | ;; | ||
| 179 | esac | ||
| 180 | gl_MUSL_LIBC | ||
| 181 | gl_PREREQ_VASNXPRINTF | ||
| 182 | ]) | ||
| 183 | |||
| 184 | # Common prerequisites of lib/vasnprintf.c and lib/vasnwprintf.c. | ||
| 185 | AC_DEFUN_ONCE([gl_PREREQ_VASNXPRINTF], | ||
| 186 | [ | ||
| 187 | AC_REQUIRE([AC_FUNC_ALLOCA]) | ||
| 188 | AC_REQUIRE([gt_TYPE_WCHAR_T]) | ||
| 189 | AC_REQUIRE([gt_TYPE_WINT_T]) | ||
| 190 | AC_CHECK_FUNCS([wcslen]) | ||
| 191 | dnl Knowing DBL_EXPBIT0_WORD and DBL_EXPBIT0_BIT enables an optimization | ||
| 192 | dnl in the code for NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE. | ||
| 193 | AC_REQUIRE([gl_DOUBLE_EXPONENT_LOCATION]) | ||
| 87 | ]) | 194 | ]) |
| 88 | 195 | ||
| 89 | # Extra prerequisites of lib/vasnprintf.c for supporting 'long double' | 196 | # Extra prerequisites of lib/vasnprintf.c for supporting 'long double' |
| @@ -152,7 +259,22 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_A], | |||
| 152 | AC_DEFINE([NEED_PRINTF_DIRECTIVE_A], [1], | 259 | AC_DEFINE([NEED_PRINTF_DIRECTIVE_A], [1], |
| 153 | [Define if the vasnprintf implementation needs special code for | 260 | [Define if the vasnprintf implementation needs special code for |
| 154 | the 'a' and 'A' directives.]) | 261 | the 'a' and 'A' directives.]) |
| 155 | AC_CHECK_FUNCS([nl_langinfo]) | 262 | gl_CHECK_FUNCS_ANDROID([nl_langinfo], [[#include <langinfo.h>]]) |
| 263 | ;; | ||
| 264 | esac | ||
| 265 | ]) | ||
| 266 | |||
| 267 | # Extra prerequisites of lib/vasnprintf.c for supporting the 'b' directive. | ||
| 268 | AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_B], | ||
| 269 | [ | ||
| 270 | AC_REQUIRE([gl_PRINTF_DIRECTIVE_B]) | ||
| 271 | case "$gl_cv_func_printf_directive_b" in | ||
| 272 | *yes) | ||
| 273 | ;; | ||
| 274 | *) | ||
| 275 | AC_DEFINE([NEED_PRINTF_DIRECTIVE_B], [1], | ||
| 276 | [Define if the vasnprintf implementation needs special code for | ||
| 277 | the 'b' directive.]) | ||
| 156 | ;; | 278 | ;; |
| 157 | esac | 279 | esac |
| 158 | ]) | 280 | ]) |
| @@ -187,6 +309,21 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_LS], | |||
| 187 | esac | 309 | esac |
| 188 | ]) | 310 | ]) |
| 189 | 311 | ||
| 312 | # Extra prerequisites of lib/vasnprintf.c for supporting the 'lc' directive. | ||
| 313 | AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_LC], | ||
| 314 | [ | ||
| 315 | AC_REQUIRE([gl_PRINTF_DIRECTIVE_LC]) | ||
| 316 | case "$gl_cv_func_printf_directive_lc" in | ||
| 317 | *yes) | ||
| 318 | ;; | ||
| 319 | *) | ||
| 320 | AC_DEFINE([NEED_PRINTF_DIRECTIVE_LC], [1], | ||
| 321 | [Define if the vasnprintf implementation needs special code for | ||
| 322 | the 'lc' directive.]) | ||
| 323 | ;; | ||
| 324 | esac | ||
| 325 | ]) | ||
| 326 | |||
| 190 | # Extra prerequisites of lib/vasnprintf.c for supporting the ' flag. | 327 | # Extra prerequisites of lib/vasnprintf.c for supporting the ' flag. |
| 191 | AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_GROUPING], | 328 | AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_GROUPING], |
| 192 | [ | 329 | [ |
| @@ -232,6 +369,22 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_ZERO], | |||
| 232 | esac | 369 | esac |
| 233 | ]) | 370 | ]) |
| 234 | 371 | ||
| 372 | # Extra prerequisites of lib/vasnprintf.c for supporting the # flag with a | ||
| 373 | # zero precision and a zero value in the 'x' and 'X' directives. | ||
| 374 | AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_ALT_PRECISION_ZERO], | ||
| 375 | [ | ||
| 376 | AC_REQUIRE([gl_PRINTF_FLAG_ALT_PRECISION_ZERO]) | ||
| 377 | case "$gl_cv_func_printf_flag_alt_precision_zero" in | ||
| 378 | *yes) | ||
| 379 | ;; | ||
| 380 | *) | ||
| 381 | AC_DEFINE([NEED_PRINTF_FLAG_ALT_PRECISION_ZERO], [1], | ||
| 382 | [Define if the vasnprintf implementation needs special code for the | ||
| 383 | # flag with a zero precision and a zero value in the 'x' and 'X' directives.]) | ||
| 384 | ;; | ||
| 385 | esac | ||
| 386 | ]) | ||
| 387 | |||
| 235 | # Extra prerequisites of lib/vasnprintf.c for supporting large precisions. | 388 | # Extra prerequisites of lib/vasnprintf.c for supporting large precisions. |
| 236 | AC_DEFUN([gl_PREREQ_VASNPRINTF_PRECISION], | 389 | AC_DEFUN([gl_PREREQ_VASNPRINTF_PRECISION], |
| 237 | [ | 390 | [ |
| @@ -276,23 +429,53 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF_ENOMEM], | |||
| 276 | ]) | 429 | ]) |
| 277 | 430 | ||
| 278 | # Prerequisites of lib/vasnprintf.c including all extras for POSIX compliance. | 431 | # Prerequisites of lib/vasnprintf.c including all extras for POSIX compliance. |
| 279 | AC_DEFUN([gl_PREREQ_VASNPRINTF_WITH_EXTRAS], | 432 | AC_DEFUN([gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS], |
| 280 | [ | 433 | [ |
| 281 | AC_REQUIRE([gl_PREREQ_VASNPRINTF]) | 434 | AC_REQUIRE([gl_PREREQ_VASNPRINTF]) |
| 282 | gl_PREREQ_VASNPRINTF_LONG_DOUBLE | 435 | gl_PREREQ_VASNPRINTF_LONG_DOUBLE |
| 283 | gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE | 436 | gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE |
| 284 | gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE | 437 | gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE |
| 285 | gl_PREREQ_VASNPRINTF_DIRECTIVE_A | 438 | gl_PREREQ_VASNPRINTF_DIRECTIVE_A |
| 439 | gl_PREREQ_VASNPRINTF_DIRECTIVE_B | ||
| 286 | gl_PREREQ_VASNPRINTF_DIRECTIVE_F | 440 | gl_PREREQ_VASNPRINTF_DIRECTIVE_F |
| 287 | gl_PREREQ_VASNPRINTF_DIRECTIVE_LS | 441 | gl_PREREQ_VASNPRINTF_DIRECTIVE_LS |
| 442 | gl_PREREQ_VASNPRINTF_DIRECTIVE_LC | ||
| 288 | gl_PREREQ_VASNPRINTF_FLAG_GROUPING | 443 | gl_PREREQ_VASNPRINTF_FLAG_GROUPING |
| 289 | gl_PREREQ_VASNPRINTF_FLAG_LEFTADJUST | 444 | gl_PREREQ_VASNPRINTF_FLAG_LEFTADJUST |
| 290 | gl_PREREQ_VASNPRINTF_FLAG_ZERO | 445 | gl_PREREQ_VASNPRINTF_FLAG_ZERO |
| 446 | gl_PREREQ_VASNPRINTF_FLAG_ALT_PRECISION_ZERO | ||
| 291 | gl_PREREQ_VASNPRINTF_PRECISION | 447 | gl_PREREQ_VASNPRINTF_PRECISION |
| 292 | gl_PREREQ_VASNPRINTF_ENOMEM | 448 | gl_PREREQ_VASNPRINTF_ENOMEM |
| 293 | ]) | 449 | ]) |
| 294 | 450 | ||
| 451 | # Extra prerequisites of lib/vasnprintf.c for supporting the 'B' directive. | ||
| 452 | AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_UPPERCASE_B], | ||
| 453 | [ | ||
| 454 | AC_REQUIRE([gl_PRINTF_DIRECTIVE_UPPERCASE_B]) | ||
| 455 | case "$gl_cv_func_printf_directive_uppercase_b" in | ||
| 456 | *yes) | ||
| 457 | ;; | ||
| 458 | *) | ||
| 459 | AC_DEFINE([NEED_PRINTF_DIRECTIVE_UPPERCASE_B], [1], | ||
| 460 | [Define if the vasnprintf implementation needs special code for | ||
| 461 | the 'B' directive.]) | ||
| 462 | ;; | ||
| 463 | esac | ||
| 464 | ]) | ||
| 465 | |||
| 466 | # Prerequisites of lib/vasnprintf.c including all extras for POSIX compliance | ||
| 467 | # and GNU compatibility. | ||
| 468 | AC_DEFUN([gl_PREREQ_VASNPRINTF_WITH_GNU_EXTRAS], | ||
| 469 | [ | ||
| 470 | gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS | ||
| 471 | AC_DEFINE([SUPPORT_GNU_PRINTF_DIRECTIVES], [1], | ||
| 472 | [Define if the vasnprintf implementation should support GNU compatible | ||
| 473 | printf directives.]) | ||
| 474 | gl_PREREQ_VASNPRINTF_DIRECTIVE_UPPERCASE_B | ||
| 475 | ]) | ||
| 476 | |||
| 295 | # Prerequisites of lib/asnprintf.c. | 477 | # Prerequisites of lib/asnprintf.c. |
| 478 | # Prerequisites of lib/asnwprintf.c. | ||
| 296 | AC_DEFUN([gl_PREREQ_ASNPRINTF], | 479 | AC_DEFUN([gl_PREREQ_ASNPRINTF], |
| 297 | [ | 480 | [ |
| 298 | ]) | 481 | ]) |
