aboutsummaryrefslogtreecommitdiffstats
path: root/util/iobuf.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/iobuf.c')
-rw-r--r--util/iobuf.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/util/iobuf.c b/util/iobuf.c
index 72a14f503..d429d4c1e 100644
--- a/util/iobuf.c
+++ b/util/iobuf.c
@@ -700,6 +700,15 @@ iobuf_readbyte(IOBUF a)
{
int c;
+ /* nlimit does not work together with unget */
+ /* nbytes is also not valid! */
+ if( a->unget.buf ) {
+ if( a->unget.start < a->unget.len )
+ return a->unget.buf[a->unget.start++];
+ m_free(a->unget.buf);
+ a->unget.buf = NULL;
+ }
+
if( a->nlimit && a->nbytes >= a->nlimit )
return -1; /* forced EOF */
@@ -770,6 +779,27 @@ iobuf_temp_to_buffer( IOBUF a, byte *buffer, size_t buflen )
return n;
}
+/****************
+ * unget the contents of the temp io stream to A and close temp
+ * Could be optimized!!
+ */
+void
+iobuf_unget_and_close_temp( IOBUF a, IOBUF temp )
+{
+ if( a->unget.buf ) {
+ if( a->unget.start < a->unget.len )
+ log_fatal("cannot do any more ungets on this buffer\n");
+ /* not yet cleaned up; do it now */
+ m_free(a->unget.buf);
+ a->unget.buf = NULL;
+ }
+ a->unget.size = temp->d.len;
+ a->unget.buf = m_alloc( a->unget.size );
+ a->unget.len = temp->d.len;
+ memcpy( a->unget.buf, temp->d.buf, a->unget.len );
+ iobuf_close(temp);
+}
+
/****************
* Set a limit, how much bytes may be read from the input stream A.