From: Martin Mares Date: Fri, 16 Jan 2004 14:16:00 +0000 (+0000) Subject: The combination of bflush() with bsetpos() to the beginning is a very X-Git-Tag: holmes-import~1137 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=dfbf964395a2d01f4089138b4d9ecdd204a7e8c7;p=libucw.git The combination of bflush() with bsetpos() to the beginning is a very common idiom. Make it a library function brewind(). --- 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) {