From 06180d5fa909b927ffe70aee3dd2045317d6faba Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Mon, 19 Feb 2001 18:53:46 +0000 Subject: [PATCH] Added breadb() which acts just like bread(), but die()s if a partial record is read. This is mainly to avoid consistency checks in main code path. --- lib/fastbuf.c | 4 +++- lib/fastbuf.h | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/fastbuf.c b/lib/fastbuf.c index 5b394cf1..e9de62df 100644 --- a/lib/fastbuf.c +++ b/lib/fastbuf.c @@ -187,7 +187,7 @@ void bput5_slow(struct fastbuf *f, u64 o) #endif } -uns bread_slow(struct fastbuf *f, void *b, uns l) +uns bread_slow(struct fastbuf *f, void *b, uns l, uns check) { uns total = 0; while (l) @@ -209,6 +209,8 @@ uns bread_slow(struct fastbuf *f, void *b, uns l) l -= k; total += k; } + if (check && total && total != l) + die("breadb: short read"); return total; } diff --git a/lib/fastbuf.h b/lib/fastbuf.h index 01e7f60a..15bfed5a 100644 --- a/lib/fastbuf.h +++ b/lib/fastbuf.h @@ -268,7 +268,7 @@ static inline void bput5(struct fastbuf *f, u64 l) bput5_slow(f, l); } -uns bread_slow(struct fastbuf *f, void *b, uns l); +uns bread_slow(struct fastbuf *f, void *b, uns l, uns check); static inline uns bread(struct fastbuf *f, void *b, uns l) { if (f->bptr + l <= f->bstop) @@ -278,7 +278,19 @@ static inline uns bread(struct fastbuf *f, void *b, uns l) return l; } else - return bread_slow(f, b, l); + return bread_slow(f, b, l, 0); +} + +static inline uns breadb(struct fastbuf *f, void *b, uns l) +{ + if (f->bptr + l <= f->bstop) + { + memcpy(b, f->bptr, l); + f->bptr += l; + return l; + } + else + return bread_slow(f, b, l, 1); } void bwrite_slow(struct fastbuf *f, void *b, uns l); -- 2.39.2