From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 88615 invoked by alias); 18 Feb 2020 10:42:03 -0000 Mailing-List: contact cygwin-cvs-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: cygwin-cvs-owner@cygwin.com Received: (qmail 88567 invoked by uid 9078); 18 Feb 2020 10:42:02 -0000 Date: Tue, 18 Feb 2020 10:42:00 -0000 Message-ID: <20200218104202.88566.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: console: Fix ioctl() FIONREAD. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: 592b03b3ba0d51b1d3edda6302f324ecd53c83eb X-Git-Newrev: 321d79abd3240008ae09e3021b312126058d9416 X-SW-Source: 2020-q1/txt/msg00071.txt https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=321d79abd3240008ae09e3021b312126058d9416 commit 321d79abd3240008ae09e3021b312126058d9416 Author: Takashi Yano Date: Tue Feb 18 13:05:07 2020 +0900 Cygwin: console: Fix ioctl() FIONREAD. - ioctl() FIONREAD for console does not return correct value since commit cfb517f39a8bcf2d995a732d250563917600408a. This patch fixes the issue. Diff: --- winsup/cygwin/fhandler_console.cc | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc index 9bfee64..ce19a81 100644 --- a/winsup/cygwin/fhandler_console.cc +++ b/winsup/cygwin/fhandler_console.cc @@ -1230,10 +1230,39 @@ fhandler_console::ioctl (unsigned int cmd, void *arg) release_output_mutex (); return -1; } - while (n-- > 0) - if (inp[n].EventType == KEY_EVENT && inp[n].Event.KeyEvent.bKeyDown) - ++ret; - *(int *) arg = ret; + bool saw_eol = false; + for (DWORD i=0; iti.c_lflag & ICANON) && + len == 1 && CCEQ (get_ttyp ()->ti.c_cc[VEOF], mbs[0])) + { + saw_eol = true; + break; + } + ret += len; + const char eols[] = { + '\n', + '\r', + (char) get_ttyp ()->ti.c_cc[VEOL], + (char) get_ttyp ()->ti.c_cc[VEOL2] + }; + if ((get_ttyp ()->ti.c_lflag & ICANON) && + len == 1 && memchr (eols, mbs[0], sizeof (eols))) + { + saw_eol = true; + break; + } + } + if ((get_ttyp ()->ti.c_lflag & ICANON) && !saw_eol) + *(int *) arg = 0; + else + *(int *) arg = ret; release_output_mutex (); return 0; }