public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Cygwin: pty: Drop handling for UTF-7 in convert_mb_str().
@ 2020-09-11 18:14 Corinna Vinschen
  0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2020-09-11 18:14 UTC (permalink / raw)
  To: cygwin-cvs

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=2ed80d04f4211571c9f8805d19d13b9a548ab4eb

commit 2ed80d04f4211571c9f8805d19d13b9a548ab4eb
Author: Takashi Yano <takashi.yano@nifty.ne.jp>
Date:   Sat Sep 12 00:37:26 2020 +0900

    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.

Diff:
---
 winsup/cygwin/fhandler_tty.cc | 86 +++++++++++++++++++------------------------
 1 file changed, 38 insertions(+), 48 deletions(-)

diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 95b28c3da..8910af1e7 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -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,
 		mbstate_t *mbp)
 {
-  size_t nlen;
   tmp_pathbuf tp;
   wchar_t *wbuf = tp.w_get ();
   int wlen = 0;
-  if (cp_from == CP_UTF7)
-    /* MB_ERR_INVALID_CHARS does not work properly for UTF-7.
-       Therefore, just convert string without checking */
-    wlen = MultiByteToWideChar (cp_from, 0, ptr_from, len_from,
-				wbuf, NT_MAX_PATH);
-  else
-    {
-      char *tmpbuf = tp.c_get ();
-      memcpy (tmpbuf, mbp->__value.__wchb, mbp->__count);
-      if (mbp->__count + len_from > NT_MAX_PATH)
-	len_from = NT_MAX_PATH - mbp->__count;
-      memcpy (tmpbuf + mbp->__count, ptr_from, len_from);
-      int total_len = mbp->__count + len_from;
-      mbp->__count = 0;
-      int mblen = 0;
-      for (const char *p = tmpbuf; p < tmpbuf + total_len; p += mblen)
-	/* Max bytes in multibyte char is 4. */
-	for (mblen = 1; mblen <= 4; mblen ++)
-	  {
-	    /* Try conversion */
-	    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 */
+  char *tmpbuf = tp.c_get ();
+  memcpy (tmpbuf, mbp->__value.__wchb, mbp->__count);
+  if (mbp->__count + len_from > NT_MAX_PATH)
+    len_from = NT_MAX_PATH - mbp->__count;
+  memcpy (tmpbuf + mbp->__count, ptr_from, len_from);
+  int total_len = mbp->__count + len_from;
+  mbp->__count = 0;
+  int mblen = 0;
+  for (const char *p = tmpbuf; p < tmpbuf + total_len; p += mblen)
+    /* Max bytes in multibyte char supported is 4. */
+    for (mblen = 1; mblen <= 4; mblen ++)
+      {
+	/* Try conversion */
+	int l = MultiByteToWideChar (cp_from, MB_ERR_INVALID_CHARS,
+				     p, mblen,
+				     wbuf + wlen, NT_MAX_PATH - wlen);
+	if (l)
+	  { /* Conversion Success */
+	    wlen += l;
+	    break;
 	  }
-    }
-  nlen = WideCharToMultiByte (cp_to, 0, wbuf, wlen,
-			      ptr_to, *len_to, NULL, NULL);
-  *len_to = nlen;
+	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 */
+      }
+  *len_to = WideCharToMultiByte (cp_to, 0, wbuf, wlen,
+				 ptr_to, *len_to, NULL, NULL);
 }
 
 static bool


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-09-11 18:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-11 18:14 [newlib-cygwin] Cygwin: pty: Drop handling for UTF-7 in convert_mb_str() Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).