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; std::string fd_contents;
for (;;) { for (;;) {
char buff[4096]; char buff[4096];
size_t amt = read(fd, buff, sizeof buff); ssize_t amt = read(fd, buff, sizeof buff);
if (amt > 0) { if (amt > 0) {
fd_contents.append(buff, amt); fd_contents.append(buff, amt);
} else if (amt == 0) { } else if (amt == 0) {
// EOF. // EOF.
break; break;
} else { } else {
assert(amt == -1);
int err = errno; int err = errno;
if (err == EINTR) { if (err == EINTR) {
continue; continue;