1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

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.
This commit is contained in:
Martijn Dekker 2021-01-09 00:45:51 +00:00
parent 096f46eee5
commit e03c010c4d

View file

@ -2217,6 +2217,23 @@ iswalpha(wchar_t c)
typedef int (*Isw_f)(wchar_t); typedef int (*Isw_f)(wchar_t);
static int
wide_wctomb(char* u, wchar_t w)
{
int size = 0;
if (u)
{
size = wctomb(u, w);
if (size < 0)
{
*u = (char)(w & 0xff);
size = 1;
}
}
return size;
}
/* /*
* called when LC_CTYPE initialized or changes * called when LC_CTYPE initialized or changes
*/ */
@ -2261,7 +2278,7 @@ set_ctype(Lc_category_t* cp)
{ {
if (!(ast.mb_width = wcwidth)) if (!(ast.mb_width = wcwidth))
ast.mb_width = default_wcwidth; ast.mb_width = default_wcwidth;
ast.mb_conv = wctomb; ast.mb_conv = wide_wctomb;
#ifdef mb_state #ifdef mb_state
{ {
/* /*