Skip to content

Commit

Permalink
cygwin use fcns
Browse files Browse the repository at this point in the history
  • Loading branch information
khwilliamson committed May 9, 2021
1 parent 7a7684c commit 6094d18
Showing 1 changed file with 2 additions and 43 deletions.
45 changes: 2 additions & 43 deletions cygwin/cygwin.c
Expand Up @@ -160,54 +160,13 @@ do_spawn (char *cmd)
char*
wide_to_utf8(const wchar_t *wbuf)
{
char *buf;
int wlen = 0;
const char *oldlocale;
dTHX;

/* 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? */
oldlocale = Perl_setlocale(LC_CTYPE, NULL);
Perl_setlocale(LC_CTYPE, "utf-8");

/* uvchr_to_utf8(buf, chr) or Encoding::_bytes_to_utf8(sv, "UCS-2BE"); */
LC_CTYPE_LOCK;
wlen = wcsrtombs(NULL, (const wchar_t **)&wbuf, wlen, NULL);
LC_CTYPE_UNLOCK;
buf = (char *) safemalloc(wlen+1);
LC_CTYPE_LOCK;
wcsrtombs(buf, (const wchar_t **)&wbuf, wlen, NULL);
LC_CTYPE_UNLOCK;

if (oldlocale) Perl_setlocale(LC_CTYPE, oldlocale);
else Perl_setlocale(LC_CTYPE, "C");

return buf;
return Perl_Win_wstring_to_utf8_string(wbuf);
}

wchar_t*
utf8_to_wide(const char *buf)
{
wchar_t *wbuf;
mbstate_t mbs;
const char *oldlocale;
int wlen = sizeof(wchar_t)*strlen(buf);
dTHX;

oldlocale = Perl_setlocale(LC_CTYPE, NULL);

Perl_setlocale(LC_CTYPE, "utf-8");
wbuf = (wchar_t *) safemalloc(wlen);
/* utf8_to_uvchr_buf(pathname, pathname + wlen, wpath) or Encoding::_utf8_to_bytes(sv, "UCS-2BE"); */
LC_CTYPE_LOCK;
wlen = mbsrtowcs(wbuf, (const char**)&buf, wlen, &mbs);
LC_CTYPE_UNLOCK;

if (oldlocale) Perl_setlocale(LC_CTYPE, oldlocale);
else Perl_setlocale(LC_CTYPE, "C");

return wbuf;
return Perl_Win_utf8_string_to_wstring(buf);
}
#endif /* cygwin 1.7 */

Expand Down

0 comments on commit 6094d18

Please sign in to comment.