]> mj.ucw.cz Git - libucw.git/commitdiff
fb-grow: Added a function to read the whole buffer anytime.
authorPavel Charvat <pchar@ucw.cz>
Mon, 18 Apr 2011 11:34:08 +0000 (13:34 +0200)
committerPavel Charvat <pchar@ucw.cz>
Mon, 18 Apr 2011 11:34:08 +0000 (13:34 +0200)
ucw/fastbuf.h
ucw/fb-grow.c

index dfd29d00a8d627c77f5a461a8b00fc69e4e9db57..fc82a0e5c277c5bc88991a117f8337289b7a7826 100644 (file)
@@ -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]]
index 19880ed36fd8f299559eae7479b1c5ba79b90097..59eff2b72ec44184c69a36a8a0da181d624f8a29 100644 (file)
@@ -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)