+2023-06-12 Bruno Haible <bruno@clisp.org>
+
+ 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 <bruno@clisp.org>
vasnwprintf: Fix some cross-compilation results.
-# 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,
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 <stdio.h>
+#include <wchar.h>
+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 <https://www.openwall.com/lists/musl/2023/06/12/2>. */
+ 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) ;;