[PATCH] Cygwin: console: Ignore 0x00 on write().

Takashi Yano takashi.yano@nifty.ne.jp
Thu Feb 20 11:52:00 GMT 2020


- In xterm compatible mode, 0x00 on write() behaves incompatible
  with real xterm. In xterm, 0x00 completely ignored. Therefore,
  0x00 is ignored by console with this patch.
---
 winsup/cygwin/fhandler_console.cc | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc
index 66e645aa1..705ce696e 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -1794,6 +1794,16 @@ bool fhandler_console::write_console (PWCHAR buf, DWORD len, DWORD& done)
 	  len -= 4;
 	}
     }
+  /* Workaround for ^@ (0x00) handling in xterm compatible mode. */
+  if (wincap.has_con_24bit_colors () && !con_is_legacy)
+    {
+      WCHAR *p = buf;
+      while ((p = wmemchr (p, L'\0', len - (p - buf))))
+	{
+	  memmove (p, p+1, (len - (p+1 - buf))*sizeof (WCHAR));
+	  len --;
+	}
+    }
 
   if (con.iso_2022_G1
 	? con.vt100_graphics_mode_G1
-- 
2.21.0



More information about the Cygwin-patches mailing list