Cygwin: glob: perform correct utf-32 -> multibyte conversion
g_Ctoc, converting the UTF-32 filenames to multibyte, still used UTF-16 to multibyte conversion. Introduce a wirtomb helper and fix that. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
parent
4349a1e4db
commit
f3f20038c4
|
@ -1024,7 +1024,7 @@ g_Ctoc(const Char *str, char *buf, size_t len)
|
|||
|
||||
memset(&mbs, 0, sizeof(mbs));
|
||||
while (len >= (size_t) MB_CUR_MAX) {
|
||||
clen = wcrtomb(buf, *str, &mbs);
|
||||
clen = wirtomb(buf, *str, &mbs);
|
||||
if (clen == (size_t)-1)
|
||||
return (1);
|
||||
if (*str == L'\0')
|
||||
|
|
|
@ -44,6 +44,10 @@ extern wctomb_f __utf8_wctomb;
|
|||
for surrogate pairs, plus a wchar_t NUL. */
|
||||
void wcintowcs (wchar_t *, wint_t *, size_t);
|
||||
|
||||
/* replacement function for wcrtomb, converting a UTF-32 char to a
|
||||
multibyte string. */
|
||||
size_t wirtomb (char *, wint_t, mbstate_t *);
|
||||
|
||||
/* replacement function for mbrtowc, returning a wint_t representing
|
||||
a UTF-32 value. Defined in strfuncs.cc */
|
||||
extern size_t mbrtowi (wint_t *, const char *, size_t, mbstate_t *);
|
||||
|
|
|
@ -129,6 +129,25 @@ wcintowcs (wchar_t *dest, wint_t *src, size_t len)
|
|||
*dest = '\0';
|
||||
}
|
||||
|
||||
/* replacement function for wcrtomb, converting a UTF-32 char to a
|
||||
multibyte string. */
|
||||
extern "C" size_t
|
||||
wirtomb (char *s, wint_t wi, mbstate_t *ps)
|
||||
{
|
||||
wchar_t wc[3] = { (wchar_t) wi, '\0', '\0' };
|
||||
const wchar_t *wcp = wc;
|
||||
size_t nwc = 1;
|
||||
|
||||
if (wi >= 0x10000)
|
||||
{
|
||||
wi -= 0x10000;
|
||||
wc[0] = (wi >> 10) + 0xd800;
|
||||
wc[1] = (wi & 0x3ff) + 0xdc00;
|
||||
nwc = 2;
|
||||
}
|
||||
return wcsnrtombs (s, &wcp, nwc, SIZE_MAX, ps);
|
||||
}
|
||||
|
||||
/* replacement function for mbrtowc, returning a wint_t representing
|
||||
a UTF-32 value. */
|
||||
extern "C" size_t
|
||||
|
|
Loading…
Reference in New Issue