read_all: return 0 when EOF occurs after 0 bytes

Originally it would return -1 (without setting errno) if the fd was
already at EOF when you called read_all.

This is already fixed in sendfile_all.

Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
This commit is contained in:
Egor Chelak 2020-11-06 21:09:14 +02:00
parent 7951164c1f
commit 418eb09482
1 changed files with 4 additions and 2 deletions

View File

@ -67,13 +67,15 @@ static inline ssize_t read_all(int fd, char *buf, size_t count)
memset(buf, 0, count);
while (count > 0) {
ret = read(fd, buf, count);
if (ret <= 0) {
if (ret < 0 && (errno == EAGAIN || errno == EINTR) && (tries++ < 5)) {
if (ret < 0) {
if ((errno == EAGAIN || errno == EINTR) && (tries++ < 5)) {
xusleep(250000);
continue;
}
return c ? c : -1;
}
if (ret == 0)
return c;
tries = 0;
count -= ret;
buf += ret;