[PATCH] Cygwin: pty: Treat CR/NL in accept_input() the same as in transfer_input()
Takashi Yano <[email protected]> Fri, 12 Jun 2026 21:47:21 +0900
| Newsgroups | gmane.os.cygwin.patches |
|---|---|
| Message-ID | <[email protected]> |
In transfer_input(), CR and NL in the data transferred to nat-pipe
is treated as follows:
1) If pseudo console is activated, convert NL to CR.
2) If pseudo console is disabled, convert CR to NL.
This conversion is necessary to ensure non-cygwin apps can handle
CR/NL as expected. Therefor, CR and NL should be treated as the
same way in accept_input() if the data is sent to nat-pipe.
Usually, when pseudo console is activated, the input data for non-
cygwin app is not treated by accept_input. However, accept_input()
handle the input data in pseudo console enabled mode, only in a
very short duration when pseudo console is about to setup, because
master::write() calls line_edit() in the pcon_start mode. If pseudo
console is disabled, accept_input() handles them, however usually
ICRNL flag is set, so line_edit() do this conversion. However, if
this flag is not set, the conversion added by this patch is needed
as well.
Fixes: f20641789427 ("Cygwin: pty: Reduce unecessary input transfer.")
Signed-off-by: Takashi Yano <[email protected]>
Reviewed-by:
---
winsup/cygwin/fhandler/pty.cc | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/winsup/cygwin/fhandler/pty.cc b/winsup/cygwin/fhandler/pty.cc
index ef79ea679..30918c2f3 100644
--- a/winsup/cygwin/fhandler/pty.cc
+++ b/winsup/cygwin/fhandler/pty.cc
@@ -690,6 +690,14 @@ fhandler_pty_master::accept_input ()
p = mbbuf;
bytes_left = nlen;
}
+
+ char *p0 = p;
+ if (get_ttyp ()->pcon_activated)
+ while ((p0 = (char *) memchr (p0, '\n', bytes_left - (p0 - p))))
+ *p0 = '\r';
+ else
+ while ((p0 = (char *) memchr (p0, '\r', bytes_left - (p0 - p))))
+ *p0 = '\n';
}
if (!bytes_left)
--
2.51.0