Cygwin: pty: Drop handling for UTF-7 in convert_mb_str().

- Charset conversion for UTF-7, ISO-2022 and ISCII, which are not
  supported in cygwin, does not work properly as a result. At the
  expense of the above, the code has been simplified a bit.
This commit is contained in:
Takashi Yano 2020-09-12 00:37:26 +09:00 committed by Corinna Vinschen
parent f4a1b6ae18
commit 2ed80d04f4
1 changed files with 38 additions and 48 deletions

View File

@ -122,58 +122,48 @@ convert_mb_str (UINT cp_to, char *ptr_to, size_t *len_to,
UINT cp_from, const char *ptr_from, size_t len_from, UINT cp_from, const char *ptr_from, size_t len_from,
mbstate_t *mbp) mbstate_t *mbp)
{ {
size_t nlen;
tmp_pathbuf tp; tmp_pathbuf tp;
wchar_t *wbuf = tp.w_get (); wchar_t *wbuf = tp.w_get ();
int wlen = 0; int wlen = 0;
if (cp_from == CP_UTF7) char *tmpbuf = tp.c_get ();
/* MB_ERR_INVALID_CHARS does not work properly for UTF-7. memcpy (tmpbuf, mbp->__value.__wchb, mbp->__count);
Therefore, just convert string without checking */ if (mbp->__count + len_from > NT_MAX_PATH)
wlen = MultiByteToWideChar (cp_from, 0, ptr_from, len_from, len_from = NT_MAX_PATH - mbp->__count;
wbuf, NT_MAX_PATH); memcpy (tmpbuf + mbp->__count, ptr_from, len_from);
else int total_len = mbp->__count + len_from;
{ mbp->__count = 0;
char *tmpbuf = tp.c_get (); int mblen = 0;
memcpy (tmpbuf, mbp->__value.__wchb, mbp->__count); for (const char *p = tmpbuf; p < tmpbuf + total_len; p += mblen)
if (mbp->__count + len_from > NT_MAX_PATH) /* Max bytes in multibyte char supported is 4. */
len_from = NT_MAX_PATH - mbp->__count; for (mblen = 1; mblen <= 4; mblen ++)
memcpy (tmpbuf + mbp->__count, ptr_from, len_from); {
int total_len = mbp->__count + len_from; /* Try conversion */
mbp->__count = 0; int l = MultiByteToWideChar (cp_from, MB_ERR_INVALID_CHARS,
int mblen = 0; p, mblen,
for (const char *p = tmpbuf; p < tmpbuf + total_len; p += mblen) wbuf + wlen, NT_MAX_PATH - wlen);
/* Max bytes in multibyte char is 4. */ if (l)
for (mblen = 1; mblen <= 4; mblen ++) { /* Conversion Success */
{ wlen += l;
/* Try conversion */ break;
int l = MultiByteToWideChar (cp_from, MB_ERR_INVALID_CHARS,
p, mblen,
wbuf + wlen, NT_MAX_PATH - wlen);
if (l)
{ /* Conversion Success */
wlen += l;
break;
}
else if (mblen == 4)
{ /* Conversion Fail */
l = MultiByteToWideChar (cp_from, 0, p, 1,
wbuf + wlen, NT_MAX_PATH - wlen);
wlen += l;
mblen = 1;
break;
}
else if (p + mblen == tmpbuf + total_len)
{ /* Multibyte char incomplete */
memcpy (mbp->__value.__wchb, p, mblen);
mbp->__count = mblen;
break;
}
/* Retry conversion with extended length */
} }
} else if (mblen == 4)
nlen = WideCharToMultiByte (cp_to, 0, wbuf, wlen, { /* Conversion Fail */
ptr_to, *len_to, NULL, NULL); l = MultiByteToWideChar (cp_from, 0, p, 1,
*len_to = nlen; wbuf + wlen, NT_MAX_PATH - wlen);
wlen += l;
mblen = 1;
break;
}
else if (p + mblen == tmpbuf + total_len)
{ /* Multibyte char incomplete */
memcpy (mbp->__value.__wchb, p, mblen);
mbp->__count = mblen;
break;
}
/* Retry conversion with extended length */
}
*len_to = WideCharToMultiByte (cp_to, 0, wbuf, wlen,
ptr_to, *len_to, NULL, NULL);
} }
static bool static bool