work around a nasty bug in linux readv syscall
authorRich Felker <dalias@aerifal.cx>
Sat, 9 Apr 2011 05:17:55 +0000 (01:17 -0400)
committerRich Felker <dalias@aerifal.cx>
Sat, 9 Apr 2011 05:17:55 +0000 (01:17 -0400)
according to posix, readv "shall be equivalent to read(), except..."
that it places the data into the buffers specified by the iov array.
however on linux, when reading from a terminal, each iov element
behaves almost like a separate read. this means that if the first iov
exactly satisfied the request (e.g. a length-one read of '\n') and the
second iov is nonzero length, the syscall will block again after
getting the blank line from the terminal until another line is read.
simply put, entering a single blank line becomes impossible.

the solution, fortunately, is simple. whenever the buffer size is
nonzero, reduce the length of the requested read by one byte and let
the last byte go through the buffer. this way, readv will already be
in the second (and last) iov, and won't re-block on the second iov.


No differences found