From 33392850a6fdcfcf2a274e3ff16dbf1fe1bd84f3 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sun, 7 Jan 2001 14:58:11 +0000 Subject: [PATCH] bread() now returns the number of bytes read instead of dying when the file is too short. Need to be taken care of when porting old Sherlock code. --- lib/fastbuf.c | 7 +++++-- lib/fastbuf.h | 7 ++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/fastbuf.c b/lib/fastbuf.c index 0939b6d5..1a145784 100644 --- a/lib/fastbuf.c +++ b/lib/fastbuf.c @@ -184,8 +184,9 @@ void bput5_slow(struct fastbuf *f, u64 o) #endif } -void bread_slow(struct fastbuf *f, void *b, uns l) +uns bread_slow(struct fastbuf *f, void *b, uns l) { + uns total = 0; while (l) { uns k = f->bstop - f->bptr; @@ -195,7 +196,7 @@ void bread_slow(struct fastbuf *f, void *b, uns l) f->refill(f); k = f->bstop - f->bptr; if (!k) - die("bread on %s: file exhausted", f->name); + break; } if (k > l) k = l; @@ -203,7 +204,9 @@ void bread_slow(struct fastbuf *f, void *b, uns l) f->bptr += k; b = (byte *)b + k; l -= k; + total += k; } + return total; } void bwrite_slow(struct fastbuf *f, void *b, uns l) diff --git a/lib/fastbuf.h b/lib/fastbuf.h index c62ed4cd..e215b3ca 100644 --- a/lib/fastbuf.h +++ b/lib/fastbuf.h @@ -264,16 +264,17 @@ static inline void bput5(struct fastbuf *f, u64 l) bput5_slow(f, l); } -void bread_slow(struct fastbuf *f, void *b, uns l); -static inline void bread(struct fastbuf *f, void *b, uns l) +uns bread_slow(struct fastbuf *f, void *b, uns l); +static inline uns bread(struct fastbuf *f, void *b, uns l) { if (f->bptr + l <= f->bstop) { memcpy(b, f->bptr, l); f->bptr += l; + return l; } else - bread_slow(f, b, l); + return bread_slow(f, b, l); } void bwrite_slow(struct fastbuf *f, void *b, uns l); -- 2.39.2