X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=ucw%2Ffb-grow.c;h=0898a1a4be68b6128796bdc866f0598f77024942;hb=06cac26f0d8895b5cb8fbe03ca96444dc4ac8d51;hp=19880ed36fd8f299559eae7479b1c5ba79b90097;hpb=903e6530eaa344851bf0aa6a9f270c205aa97300;p=libucw.git diff --git a/ucw/fb-grow.c b/ucw/fb-grow.c index 19880ed3..0898a1a4 100644 --- a/ucw/fb-grow.c +++ b/ucw/fb-grow.c @@ -7,9 +7,9 @@ * of the GNU Lesser General Public License. */ -#include "ucw/lib.h" -#include "ucw/fastbuf.h" -#include "ucw/mempool.h" +#include +#include +#include #include #include @@ -19,7 +19,7 @@ struct fb_gbuf { struct mempool *mp; byte *end; }; -#define FB_GBUF(f) ((struct fb_gbuf *)(f)->is_fastbuf) +#define FB_GBUF(f) ((struct fb_gbuf *)(f)) static int fbgrow_refill(struct fastbuf *b) { @@ -56,7 +56,7 @@ static int fbgrow_seek(struct fastbuf *b, ucw_off_t pos, int whence) if (whence == SEEK_END) pos += len; if (pos < 0 || pos > len) - bthrow(b, "fb.seek", "Seek out of range"); + bthrow(b, "seek", "Seek out of range"); b->bptr = b->buffer + pos; b->bstop = b->buffer; b->pos = 0; @@ -92,7 +92,7 @@ struct fastbuf *fbgrow_create_mp(struct mempool *mp, unsigned basic_size) b->spout = fbgrow_spout; b->seek = fbgrow_seek; b->can_overwrite_buffer = 1; - return fb_tie(b); + return b; } struct fastbuf *fbgrow_create(unsigned basic_size) @@ -111,6 +111,15 @@ void fbgrow_rewind(struct fastbuf *b) brewind(b); } +uns fbgrow_get_buf(struct fastbuf *b, byte **buf) +{ + byte *end = FB_GBUF(b)->end; + end = MAX(end, b->bptr); + if (buf) + *buf = b->buffer; + return end - b->buffer; +} + #ifdef TEST int main(void)