Skip to content

Commit e03c010

Browse files
committed
Fix for non-UTF-8 wide charsets (Solaris patch 050-CR7065478)
This upstreams a Solaris patch: https://github.com/oracle/solaris-userland/blob/master/components/ksh93/patches/050-CR7065478.patch src/lib/libast/comp/setlocale.c: - Add wide_wctomb() wrapper for wctomb(3). It changes an invalid character (wctomb returns -1) to a single byte with length 1. - set_ctype(): Use wide_wctomb() instead of wctomb(3) as the conversion discipline function (ast.mb_conv). Effectively this means there are no invalid characters. Perhaps this is necessary for compatibility with ASCII. Sadly, no public info available.
1 parent 096f46e commit e03c010

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/lib/libast/comp/setlocale.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2217,6 +2217,23 @@ iswalpha(wchar_t c)
22172217

22182218
typedef int (*Isw_f)(wchar_t);
22192219

2220+
static int
2221+
wide_wctomb(char* u, wchar_t w)
2222+
{
2223+
int size = 0;
2224+
2225+
if (u)
2226+
{
2227+
size = wctomb(u, w);
2228+
if (size < 0)
2229+
{
2230+
*u = (char)(w & 0xff);
2231+
size = 1;
2232+
}
2233+
}
2234+
return size;
2235+
}
2236+
22202237
/*
22212238
* called when LC_CTYPE initialized or changes
22222239
*/
@@ -2261,7 +2278,7 @@ set_ctype(Lc_category_t* cp)
22612278
{
22622279
if (!(ast.mb_width = wcwidth))
22632280
ast.mb_width = default_wcwidth;
2264-
ast.mb_conv = wctomb;
2281+
ast.mb_conv = wide_wctomb;
22652282
#ifdef mb_state
22662283
{
22672284
/*

0 commit comments

Comments
 (0)