Yes, there should be "<=". I just tested return values of UCRT's wctob in "C" locale for input in range [128,255] and it seems to do the same thing as btowc.
For other locales it does best-fit conversion (when it can't convert losslessly), this why I come up with using 20127, so we would perform best-fit conversion in "C" locale. I was wrong. We could you either 28591 or range check just like in btowc. Which one would you prefer? - Kirill Makurin ________________________________ From: LIU Hao Sent: Saturday, June 7, 2025 12:39 AM To: Kirill Makurin; mingw-w64-public Subject: Re: [Mingw-w64-public] Inconsistent behavior of btowc with "C" locale 在 2025-6-6 20:31, Kirill Makurin 写道: > diff --git a/mingw-w64-crt/misc/btowc.c b/mingw-w64-crt/misc/btowc.c > index c8fbd8e74..e203bbc44 100644 > --- a/mingw-w64-crt/misc/btowc.c > +++ b/mingw-w64-crt/misc/btowc.c > @@ -15,14 +15,18 @@ wint_t btowc (int c) > ... ... > + unsigned cp = ___lc_codepage_func(); > + > + /* "C" locale */ > + if (cp == 0) > + return (unsigned) c < 0xFF ? c : WEOF; I think you meant `(unsigned) c <= 0xFF` here? > diff --git a/mingw-w64-crt/misc/wctob.c b/mingw-w64-crt/misc/wctob.c > index 995f6db6e..eddf9d20b 100644 > --- a/mingw-w64-crt/misc/wctob.c > +++ b/mingw-w64-crt/misc/wctob.c > @@ -14,16 +14,22 @@ > ... ... > + /* "C" locale, use code page 20127 (ASCII) for conversion */ > + if (cp == 0) > + cp = 20127; > + 20127 produces 7-bit results which is not the inverse of `btowc()`. How about 28591? 28591 iso-8859-1 ISO 8859-1 Latin 1; Western European (ISO) -- Best regards, LIU Hao _______________________________________________ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public