I did: > * lib/mbrtowc.c (rpl_mbrtowc) [MBRTOWC_IN_C_LOCALE_MAYBE_EILSEQ]: In the > C locale, map 0x80..0xFF to 0xDF80..0xDFFF instead of 0x0080..0x00FF. > * lib/wcrtomb.c: Include hard-locale.h, <locale.h>. > (wcrtomb) [MBRTOWC_IN_C_LOCALE_MAYBE_EILSEQ]: In the C locale, map > 0xDF80..0xDFFF to 0x80..0xFF.
This causes test failures among the *c32* functions. Fixed as follows: 2026-09-20 Bruno Haible <[email protected]> mbrtoc32, c32rtomb: Make consistent with mbrtowc on glibc (regr. today). * lib/mbrtoc32.c (mbrtoc32): In the C locale, map 0x80..0xFF to U+DF80..U+DFFF instead of U+0080..U+00FF. * lib/c32rtomb.c (c32rtomb): In the C locale, map U+DF80..U+DFFF to 0x80..0xFF. diff --git a/lib/c32rtomb.c b/lib/c32rtomb.c index 9da0abb6be..1503fe2bc0 100644 --- a/lib/c32rtomb.c +++ b/lib/c32rtomb.c @@ -54,6 +54,7 @@ c32rtomb (char *s, char32_t wc, mbstate_t *ps) # endif # if MBRTOC32_IN_C_LOCALE_MAYBE_LIKE_ISO_8859 /* OpenBSD */ \ + || MBRTOC32_IN_C_LOCALE_MAYBE_EILSEQ /* glibc */ \ || !_GL_WCHAR_T_IS_UCS4 /* NetBSD ≥ 11 */ if ((wc >= 0xDF80 && wc <= 0xDFFF) && !hard_locale (LC_CTYPE)) { @@ -64,16 +65,6 @@ c32rtomb (char *s, char32_t wc, mbstate_t *ps) } # endif -# if MBRTOC32_IN_C_LOCALE_MAYBE_EILSEQ - if ((wc >= 0x0080 && wc <= 0x00FF) && !hard_locale (LC_CTYPE)) - { - /* In the "C" locale, map the code points U+0080..U+00FF back to the bytes - 0x80..0xFF, for consistency with the mbrtoc32 and btoc32 functions. */ - s[0] = (unsigned char) wc; - return 1; - } -# endif - return c32rtomb (s, wc, ps); #elif !GNULIB_defined_mbstate_t && _GL_SMALL_WCHAR_T /* Cygwin, mingw, MSVC */ diff --git a/lib/mbrtoc32.c b/lib/mbrtoc32.c index 00de09a258..57d7fc2fca 100644 --- a/lib/mbrtoc32.c +++ b/lib/mbrtoc32.c @@ -304,11 +304,11 @@ mbrtoc32 (char32_t *pwc, const char *s, size_t n, mbstate_t *ps) abort (); # endif -# if MBRTOC32_IN_C_LOCALE_MAYBE_EILSEQ +# if MBRTOC32_IN_C_LOCALE_MAYBE_EILSEQ /* glibc */ if ((size_t) -2 <= ret && n != 0 && ! hard_locale (LC_CTYPE)) { if (pwc != NULL) - *pwc = (unsigned char) *s; + *pwc = 0xDF00 + (unsigned char) *s; return 1; } # endif
