consistently return number of bytes read from stdio read backend
authorRich Felker <dalias@aerifal.cx>
Sat, 24 Feb 2018 15:51:16 +0000 (10:51 -0500)
committerRich Felker <dalias@aerifal.cx>
Sat, 24 Feb 2018 15:51:16 +0000 (10:51 -0500)
the stdio FILE read backend's return type is size_t, not ssize_t, and
all of the special (non-fd-backed) FILE types already return the
number of bytes read (zero) on error or eof. only __stdio_read leaked
a syscall error return into its return value.

fread had a workaround for this behavior going all the way back to the
original check-in. remove the workaround since it's no longer needed.

src/stdio/__stdio_read.c
src/stdio/fread.c

index af50508..909c36a 100644 (file)
@@ -12,7 +12,7 @@ size_t __stdio_read(FILE *f, unsigned char *buf, size_t len)
        cnt = syscall(SYS_readv, f->fd, iov, 2);
        if (cnt <= 0) {
                f->flags |= cnt ? F_ERR : F_EOF;
-               return cnt;
+               return 0;
        }
        if (cnt <= iov[0].iov_len) return cnt;
        cnt -= iov[0].iov_len;
index aef75f7..733d371 100644 (file)
@@ -25,7 +25,7 @@ size_t fread(void *restrict destv, size_t size, size_t nmemb, FILE *restrict f)
        /* Read the remainder directly */
        for (; l; l-=k, dest+=k) {
                k = __toread(f) ? 0 : f->read(f, dest, l);
-               if (k+1<=1) {
+               if (!k) {
                        FUNLOCK(f);
                        return (len-l)/size;
                }