diff options
author | Karl Williamson <khw@cpan.org> | 2021-09-13 14:05:02 -0600 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2023-02-08 15:57:31 +0800 |
commit | a435da2b160255de4884b0d007ef0d9d93ec203b (patch) | |
tree | 4a84570f6ca9331d7f58b72e7bdb77df287f6db6 /cygwin | |
parent | ac4290d01742ee1228041e7467ed23414ebfbafc (diff) | |
download | perl-a435da2b160255de4884b0d007ef0d9d93ec203b.tar.gz |
cygwin.c: Change wide_to_utf8() to call utf16_to_utf8()
The latter function is in the core, and doesn't require the locale to be
changed, unlike before.
Diffstat (limited to 'cygwin')
-rw-r--r-- | cygwin/cygwin.c | 22 |
1 files changed, 5 insertions, 17 deletions
diff --git a/cygwin/cygwin.c b/cygwin/cygwin.c index afdb27b315..da62c95162 100644 --- a/cygwin/cygwin.c +++ b/cygwin/cygwin.c @@ -163,26 +163,14 @@ char* wide_to_utf8(const wchar_t *wbuf) { dTHX; - char *buf; - int wlen = 0; - char *oldlocale; - - /* Here and elsewhere in this file, we have a critical section to prevent - * another thread from changing the locale out from under us. XXX But why - * not just use uvchr_to_utf8? */ - SETLOCALE_LOCK; + const Size_t wlen = (wcslen(wbuf) + 1) * sizeof(wchar_t); - oldlocale = setlocale(LC_CTYPE, NULL); - setlocale(LC_CTYPE, "utf-8"); + /* Max expansion factor is 3/2 */ + Size_t blen = wlen * 3 / 2; - wlen = wcsrtombs(NULL, (const wchar_t **)&wbuf, wlen, NULL); - buf = (char *) safemalloc(wlen+1); - wcsrtombs(buf, (const wchar_t **)&wbuf, wlen, NULL); + char *buf = (char *) safemalloc(blen); - if (oldlocale) setlocale(LC_CTYPE, oldlocale); - else setlocale(LC_CTYPE, "C"); - - SETLOCALE_UNLOCK; + utf16_to_utf8((U8 *) wbuf, buf, wlen, &blen); return buf; } |