Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/winsup
diff options
context:
space:
mode:
authorTakashi Yano <takashi.yano@nifty.ne.jp>2016-06-06 16:09:34 +0300
committerCorinna Vinschen <corinna@vinschen.de>2016-06-06 16:10:25 +0300
commit7239bb7b3ded5ab961dc56dc346d8ab83660ba29 (patch)
tree388d442fa8e1995260eb1d2cbd922dce2f25ee41 /winsup
parent97349b78701e973a2ecfebc520a92a1ab87778e0 (diff)
Return at most one line of input in canonical mode
'man termios' says: "A read(2) returns at most one line of input" in canonical mode. On cygwin 2.5.1, read(2) returns all data in buffer if the buffer size specified is large enough. This behaviour is correct in noncanonical mode, but is not correct in canonical mode. While checking this problem, I found a bug of tcflush(). tcflush() flushes only partial data in the buffer. The patch also fixes this bug. The patch has also been tested against the problem reported in https://cygwin.com/ml/cygwin/2016-05/msg00318.html. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diffstat (limited to 'winsup')
-rw-r--r--winsup/cygwin/fhandler_tty.cc11
1 files changed, 5 insertions, 6 deletions
diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 6c00d6112..733644fdd 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -756,10 +756,6 @@ fhandler_pty_slave::read (void *ptr, size_t& len)
goto out;
}
- /* On first peek determine no. of bytes to flush. */
- if (!ptr && len == UINT_MAX)
- len = (size_t) bytes_in_pipe;
-
if (ptr && !bytes_in_pipe && !vmin && !time_to_wait)
{
ReleaseMutex (input_mutex);
@@ -767,7 +763,9 @@ fhandler_pty_slave::read (void *ptr, size_t& len)
return;
}
- readlen = MIN (bytes_in_pipe, MIN (len, sizeof (buf)));
+ readlen = bytes_in_pipe ? MIN (len, sizeof (buf)) : 0;
+ if (get_ttyp ()->ti.c_lflag & ICANON && ptr)
+ readlen = MIN (bytes_in_pipe, readlen);
#if 0
/* Why on earth is the read length reduced to vmin, even if more bytes
@@ -804,7 +802,8 @@ fhandler_pty_slave::read (void *ptr, size_t& len)
}
if (n)
{
- len -= n;
+ if (!(!ptr && len == UINT_MAX)) /* not tcflush() */
+ len -= n;
totalread += n;
if (ptr)
{