]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
read_all: return 0 when EOF occurs after 0 bytes
authorEgor Chelak <egor.chelak@gmail.com>
Fri, 6 Nov 2020 19:09:14 +0000 (21:09 +0200)
committerEgor Chelak <egor.chelak@gmail.com>
Mon, 9 Nov 2020 05:19:51 +0000 (07:19 +0200)
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>
include/all-io.h

index 98745802c9089cd62d1d8691d038e5f8d1e8a436..2c367a42d85044a50b1221455900031c8f7b1b15 100644 (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;