From: Bruno Haible Date: Mon, 12 Jun 2023 14:48:03 +0000 (+0200) Subject: vasnwprintf-posix: Work around a musl libc bug. X-Git-Tag: v1.0~1216 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=284bd54ebc28cd3b61596014adb3440ad2c65c2e;p=gnulib.git vasnwprintf-posix: Work around a musl libc bug. * m4/vasnprintf.m4 (gl_PREREQ_VASNWPRINTF): Test also whether swprintf in the C locale is free of encoding errors, and set NEED_WPRINTF_DIRECTIVE_C if not. * doc/posix-functions/swprintf.texi: Clarify the list of platforms for the %c problem. --- diff --git a/ChangeLog b/ChangeLog index 406170ce6d..aebce47f42 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2023-06-12 Bruno Haible + + vasnwprintf-posix: Work around a musl libc bug. + * m4/vasnprintf.m4 (gl_PREREQ_VASNWPRINTF): Test also whether swprintf + in the C locale is free of encoding errors, and set + NEED_WPRINTF_DIRECTIVE_C if not. + * doc/posix-functions/swprintf.texi: Clarify the list of platforms for + the %c problem. + 2023-06-12 Bruno Haible vasnwprintf: Fix some cross-compilation results. diff --git a/doc/posix-functions/swprintf.texi b/doc/posix-functions/swprintf.texi index 649b541ed0..68578e016b 100644 --- a/doc/posix-functions/swprintf.texi +++ b/doc/posix-functions/swprintf.texi @@ -72,7 +72,7 @@ instead. @item In the C or POSIX locales, the @code{%c} and @code{%s} conversions may fail on some platforms: -glibc 2.35. +glibc 2.35, musl libc 1.2.4, FreeBSD 13.2, NetBSD 9.3, OpenBSD 7.2, Cygwin 2.9.0. @item When formatting an integer with grouping flag, this function inserts thousands separators even in the "C" locale on some platforms: diff --git a/m4/vasnprintf.m4 b/m4/vasnprintf.m4 index 639b29a1f3..b733f9a848 100644 --- a/m4/vasnprintf.m4 +++ b/m4/vasnprintf.m4 @@ -1,4 +1,4 @@ -# vasnprintf.m4 serial 49 +# vasnprintf.m4 serial 50 dnl Copyright (C) 2002-2004, 2006-2023 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -107,13 +107,56 @@ AC_DEFUN_ONCE([gl_PREREQ_VASNWPRINTF], esac gl_MBRTOWC_C_LOCALE case "$gl_cv_func_mbrtowc_C_locale_sans_EILSEQ" in - *yes) ;; - *) - AC_DEFINE([NEED_WPRINTF_DIRECTIVE_C], [1], - [Define if the vasnwprintf implementation needs special code for - the 'c' directive.]) + *yes) + AC_CACHE_CHECK([whether swprintf in the C locale is free of encoding errors], + [gl_cv_func_swprintf_C_locale_sans_EILSEQ], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#ifndef __USE_MINGW_ANSI_STDIO +# define __USE_MINGW_ANSI_STDIO 1 +#endif +#include +#include +int main() +{ + int result = 0; + { /* This test fails on glibc 2.35, musl libc 1.2.4, FreeBSD 13.2, NetBSD 9.3, + OpenBSD 7.2, Cygwin 2.9.0. + Reported at . */ + wchar_t buf[12]; + int ret = swprintf (buf, 12, L"%c", '\377'); + if (ret < 0) + result |= 1; + } + return result; +}]])], + [gl_cv_func_swprintf_C_locale_sans_EILSEQ=yes], + [gl_cv_func_swprintf_C_locale_sans_EILSEQ=no], + [case "$host_os" in + # Guess no on glibc systems. + *-gnu* | gnu*) gl_cv_func_swprintf_C_locale_sans_EILSEQ="guessing yes";; + # Guess no on musl systems. + *-musl* | midipix*) gl_cv_func_swprintf_C_locale_sans_EILSEQ="guessing no";; + # If we don't know, obey --enable-cross-guesses. + *) gl_cv_func_swprintf_C_locale_sans_EILSEQ="$gl_cross_guess_normal";; + esac + ]) + ]) ;; esac + if case "$gl_cv_func_mbrtowc_C_locale_sans_EILSEQ" in + *yes) false ;; + *) true ;; + esac \ + || case "$gl_cv_func_swprintf_C_locale_sans_EILSEQ" in + *yes) false ;; + *) true ;; + esac; then + AC_DEFINE([NEED_WPRINTF_DIRECTIVE_C], [1], + [Define if the vasnwprintf implementation needs special code for + the 'c' directive.]) + fi gl_SWPRINTF_DIRECTIVE_LA case "$gl_cv_func_swprintf_directive_la" in *yes) ;;