X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstdio%2Ffread.c;h=a2116da61370bd829c634353ad6f6fa6732d0d8b;hb=1d5750b95c06913a1f18a995481276d698d20fae;hp=c461256c3b0de4d6af84c0df426710fa121ddc06;hpb=c6d441e3a246370d9c459396ec22b096db93850e;p=musl diff --git a/src/stdio/fread.c b/src/stdio/fread.c index c461256c..a2116da6 100644 --- a/src/stdio/fread.c +++ b/src/stdio/fread.c @@ -7,13 +7,13 @@ size_t fread(void *restrict destv, size_t size, size_t nmemb, FILE *restrict f) { unsigned char *dest = destv; size_t len = size*nmemb, l = len, k; - - /* Never touch the file if length is zero.. */ - if (!l) return 0; + if (!size) nmemb = 0; FLOCK(f); - if (f->rend - f->rpos > 0) { + f->mode |= f->mode-1; + + if (f->rpos != f->rend) { /* First exhaust the buffer. */ k = MIN(f->rend - f->rpos, l); memcpy(dest, f->rpos, k); @@ -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; }