From 2b444219ce6ae0b0bb74b41cb02d6bc26d3f7ad1 Mon Sep 17 00:00:00 2001 From: Pavel Charvat Date: Mon, 18 Apr 2011 13:34:08 +0200 Subject: [PATCH] fb-grow: Added a function to read the whole buffer anytime. --- ucw/fastbuf.h | 1 + ucw/fb-grow.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/ucw/fastbuf.h b/ucw/fastbuf.h index dfd29d00..fc82a0e5 100644 --- a/ucw/fastbuf.h +++ b/ucw/fastbuf.h @@ -387,6 +387,7 @@ struct fastbuf *fbgrow_create(unsigned basic_size); /** Create the growing buffe struct fastbuf *fbgrow_create_mp(struct mempool *mp, unsigned basic_size); /** Create the growing buffer pre-allocated to @basic_size bytes. **/ void fbgrow_reset(struct fastbuf *b); /** Reset stream and prepare for writing. **/ void fbgrow_rewind(struct fastbuf *b); /** Prepare for reading (of already written data). **/ +uns fbgrow_read_all(struct fastbuf *b, byte **buf); /** Read the entire content of a growing fastbuf. Can be called in any state. **/ /*** * === Fastbuf on memory pools [[fbpool]] diff --git a/ucw/fb-grow.c b/ucw/fb-grow.c index 19880ed3..59eff2b7 100644 --- a/ucw/fb-grow.c +++ b/ucw/fb-grow.c @@ -111,6 +111,15 @@ void fbgrow_rewind(struct fastbuf *b) brewind(b); } +uns fbgrow_read_all(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) -- 2.39.2