X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Ffastbuf.h;h=219fec19a7fd07852a86a560c67900c060f623b1;hb=4394a6c303de4d94972f9a7b37a52f6cd799690c;hp=25c11d70e0d2aaed6bf38b13cdd41b2d29ebd189;hpb=1bb2d616aa5dc0613cd357a2352abe4470c36342;p=libucw.git diff --git a/lib/fastbuf.h b/lib/fastbuf.h index 25c11d70..219fec19 100644 --- a/lib/fastbuf.h +++ b/lib/fastbuf.h @@ -1,5 +1,5 @@ /* - * Sherlock Library -- Fast Buffered I/O + * UCW Library -- Fast Buffered I/O * * (c) 1997--2004 Martin Mares * (c) 2004 Robert Spalek @@ -8,8 +8,8 @@ * of the GNU Lesser General Public License. */ -#ifndef _SHERLOCK_FASTBUF_H -#define _SHERLOCK_FASTBUF_H +#ifndef _UCW_FASTBUF_H +#define _UCW_FASTBUF_H #ifndef EOF #include @@ -109,6 +109,12 @@ fbbuf_count_written(struct fastbuf *f) return f->bptr - f->bstop; } +/* FastIO on recyclable growing buffers */ + +struct fastbuf *fbgrow_create(unsigned basic_size); +void fbgrow_reset(struct fastbuf *b); /* Reset stream and prepare for writing */ +void fbgrow_rewind(struct fastbuf *b); /* Prepare for reading */ + /* Configuring stream parameters */ int bconfig(struct fastbuf *f, uns type, int data); @@ -122,7 +128,6 @@ 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); -void bskip(struct fastbuf *f, uns len); sh_off_t bfilesize(struct fastbuf *f); static inline sh_off_t btell(struct fastbuf *f) @@ -346,6 +351,18 @@ bbcopy(struct fastbuf *f, struct fastbuf *t, uns l) bbcopy_slow(f, t, l); } +int bskip_slow(struct fastbuf *f, uns len); +static inline int bskip(struct fastbuf *f, uns len) +{ + if (bavailr(f) >= len) + { + f->bptr += len; + return 1; + } + else + return bskip_slow(f, len); +} + /* I/O on addr_int_t */ #ifdef CPU_64BIT_POINTERS @@ -362,7 +379,10 @@ static inline uns bdirect_read_prepare(struct fastbuf *f, byte **buf) { if (f->bptr == f->bstop && !f->refill(f)) - return 0; + { + *buf = NULL; // This is not needed, but it helps to get rid of spurious warnings + return 0; + } *buf = f->bptr; return bavailr(f); } @@ -397,7 +417,7 @@ bdirect_write_commit(struct fastbuf *f, byte *pos) /* Formatted output */ -int bprintf(struct fastbuf *b, byte *msg, ...); -int vbprintf(struct fastbuf *b, byte *msg, va_list args); +int bprintf(struct fastbuf *b, char *msg, ...) FORMAT_CHECK(printf,2,3); +int vbprintf(struct fastbuf *b, char *msg, va_list args); #endif