Re: [PATCH] Cygwin: pty: Treat CR/NL in accept_input() the same as in transfer_input()

Mark Geisert <[email protected]> Tue, 23 Jun 2026 00:41:11 -0700
Newsgroups gmane.os.cygwin.patches
Message-ID <[email protected]>
Hi Takashi,

On 6/12/2026 5:47 AM, Takashi Yano wrote:
> 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.

The above block is fine.

> 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.

This block I'm having a bit of trouble to follow.  Can you possibly 
reword to describe it in more orderly fashion?

> 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)

The code of the patch looks LGTM.  Let me know what you think about my 
comments when you can.

..mark