[PATCH 2/3] Implement iobuf_unread

Florian Weimer fweimer at bfk.de
Mon Sep 25 11:56:17 CEST 2006


---
 include/iobuf.h |    1 +
 util/iobuf.c    |   19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/include/iobuf.h b/include/iobuf.h
index 4df9ab7..f810fa7 100644
--- a/include/iobuf.h
+++ b/include/iobuf.h
@@ -115,6 +115,7 @@ int   iobuf_seek( IOBUF a, off_t newpos 
 
 int  iobuf_readbyte(IOBUF a);
 int  iobuf_read(IOBUF a, byte *buf, unsigned buflen );
+void iobuf_unread(IOBUF a, const byte *buf, unsigned buflen );
 unsigned iobuf_read_line( IOBUF a, byte **addr_of_buffer,
 			  unsigned *length_of_buffer, unsigned *max_length );
 int  iobuf_peek(IOBUF a, byte *buf, unsigned buflen );
diff --git a/util/iobuf.c b/util/iobuf.c
index f6e817c..c7c1fa4 100644
--- a/util/iobuf.c
+++ b/util/iobuf.c
@@ -1714,6 +1714,25 @@ iobuf_read(IOBUF a, byte *buf, unsigned 
     return n;
 }
 
+void
+iobuf_unread(IOBUF a, const byte *buf, unsigned buflen )
+{
+    unsigned new_len;
+
+    /* We always relocate the buffer, which is not optimal.  However,
+       the code is easier to read this way, and it is not on the fast
+       path. */
+
+    if( !a->unget.buf )
+	a->unget.size = a->unget.start = a->unget.len = 0;
+
+    new_len = a->unget.len + buflen;
+    a->unget.buf = xrealloc(a->unget.buf, new_len);
+    memcpy(a->unget.buf + a->unget.len, buf, buflen);
+    a->unget.len = new_len;
+    a->nofast |= 2;
+}
+
 
 /****************
  * Have a look at the iobuf.
-- 
1.4.2.1





More information about the Gnupg-devel mailing list