From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id D93613858D39; Fri, 4 Mar 2022 15:50:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D93613858D39 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Takashi Yano To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/cygwin-3_3-branch] Cygwin: pty: Take account of CR+NL line feed in input. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/cygwin-3_3-branch X-Git-Oldrev: 09a54135cecacc2fcdc844fcf12a73c8191439e0 X-Git-Newrev: 21649fe6a126d9ee3a4a4d049e5742f3ab69c273 Message-Id: <20220304155002.D93613858D39@sourceware.org> Date: Fri, 4 Mar 2022 15:50:02 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Mar 2022 15:50:03 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D21649fe6a12= 6d9ee3a4a4d049e5742f3ab69c273 commit 21649fe6a126d9ee3a4a4d049e5742f3ab69c273 Author: Takashi Yano Date: Fri Mar 4 23:57:12 2022 +0900 Cygwin: pty: Take account of CR+NL line feed in input. =20 - Currently, individual CR or NL is treated as line feed in accept_input() and transfer_input(). This patch takes account of CR+NL as well. Diff: --- winsup/cygwin/fhandler_tty.cc | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index a97460660..f78dc7617 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -582,16 +582,21 @@ fhandler_pty_master::accept_input () paranoid_printf ("about to write %u chars to slave", bytes_left); /* Write line by line for transfer input. */ char *p0 =3D p; - char *p1 =3D p; + char *p_cr =3D (char *) memchr (p0, '\r', bytes_left - (p0 - p)); + char *p_nl =3D (char *) memchr (p0, '\n', bytes_left - (p0 - p)); DWORD n; - while ((p1 =3D (char *) memchr (p0, '\n', bytes_left - (p0 - p))) - || (p1 =3D (char *) memchr (p0, '\r', bytes_left - (p0 - p)))) + while (p_cr || p_nl) { + char *p1 =3D + p_cr ? (p_nl ? ((p_cr + 1 =3D=3D p_nl) + ? p_nl : min(p_cr, p_nl)) : p_cr) : p_nl; n =3D p1 - p0 + 1; rc =3D WriteFile (write_to, p0, n, &n, NULL); if (rc) written +=3D n; p0 =3D p1 + 1; + p_cr =3D (char *) memchr (p0, '\r', bytes_left - (p0 - p)); + p_nl =3D (char *) memchr (p0, '\n', bytes_left - (p0 - p)); } if (rc && (n =3D bytes_left - (p0 - p))) { @@ -3973,16 +3978,20 @@ fhandler_pty_slave::transfer_input (tty::xfer_dir d= ir, HANDLE from, tty *ttyp, } /* Call WriteFile() line by line */ char *p0 =3D ptr; - char *p_cr, *p_nl; - while ((p_cr =3D (char *) memchr (p0, '\r', len - (p0 - ptr))) - || (p_nl =3D (char *) memchr (p0, '\n', len - (p0 - ptr)))) + char *p_cr =3D (char *) memchr (p0, '\r', len - (p0 - ptr)); + char *p_nl =3D (char *) memchr (p0, '\n', len - (p0 - ptr)); + while (p_cr || p_nl) { - char *p1 =3D p_cr ? (p_nl ? min (p_cr, p_nl) : p_cr) : p_nl; + char *p1 =3D + p_cr ? (p_nl ? ((p_cr + 1 =3D=3D p_nl) + ? p_nl : min(p_cr, p_nl)) : p_cr) : p_nl; *p1 =3D '\n'; n =3D p1 - p0 + 1; if (n && WriteFile (to, p0, n, &n, NULL) && n) transfered =3D true; p0 =3D p1 + 1; + p_cr =3D (char *) memchr (p0, '\r', len - (p0 - ptr)); + p_nl =3D (char *) memchr (p0, '\n', len - (p0 - ptr)); } n =3D len - (p0 - ptr); if (n && WriteFile (to, p0, n, &n, NULL) && n)