From dfbf964395a2d01f4089138b4d9ecdd204a7e8c7 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 16 Jan 2004 14:16:00 +0000 Subject: [PATCH] The combination of bflush() with bsetpos() to the beginning is a very common idiom. Make it a library function brewind(). --- lib/fastbuf.c | 9 ++++++++- lib/fastbuf.h | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/fastbuf.c b/lib/fastbuf.c index 0929f101..bf887a18 100644 --- a/lib/fastbuf.c +++ b/lib/fastbuf.c @@ -1,7 +1,7 @@ /* * Sherlock Library -- Fast Buffered I/O * - * (c) 1997--2000 Martin Mares + * (c) 1997--2004 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -335,3 +335,10 @@ bconfig(struct fastbuf *f, uns item, int value) { return f->config ? f->config(f, item, value) : -1; } + +void +brewind(struct fastbuf *f) +{ + bflush(f); + bsetpos(f, 0); +} diff --git a/lib/fastbuf.h b/lib/fastbuf.h index 266ea220..7d4ac407 100644 --- a/lib/fastbuf.h +++ b/lib/fastbuf.h @@ -1,7 +1,7 @@ /* * Sherlock Library -- Fast Buffered I/O * - * (c) 1997--2002 Martin Mares + * (c) 1997--2004 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -108,6 +108,7 @@ void bclose(struct fastbuf *f); void bflush(struct fastbuf *f); void bseek(struct fastbuf *f, sh_off_t pos, int whence); void bsetpos(struct fastbuf *f, sh_off_t pos); +void brewind(struct fastbuf *f); static inline sh_off_t btell(struct fastbuf *f) { -- 2.39.5