Fix IO error handling in non-interactive reader

This used to use fread(2) which returns size_t, but read(2) returns
an ssize_t of -1 on error.

Fixes #6990
This commit is contained in:
Johannes Altmanninger 2020-05-10 22:29:14 +02:00
parent 30a8345a11
commit 83c657c010

View File

@ -3762,13 +3762,14 @@ static int read_ni(parser_t &parser, int fd, const io_chain_t &io) {
std::string fd_contents;
for (;;) {
char buff[4096];
size_t amt = read(fd, buff, sizeof buff);
ssize_t amt = read(fd, buff, sizeof buff);
if (amt > 0) {
fd_contents.append(buff, amt);
} else if (amt == 0) {
// EOF.
break;
} else {
assert(amt == -1);
int err = errno;
if (err == EINTR) {
continue;