summaryrefslogtreecommitdiffstats
path: root/common/iobuf.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2006-09-27 15:58:13 +0200
committerWerner Koch <wk@gnupg.org>2006-09-27 15:58:13 +0200
commit3377456252699c6db60de0ca90b8950584ccc8fa (patch)
treeb8b0c8112acbd34ab4039885b318b6228bc4c6fb /common/iobuf.c
parentlet cmd learn also return KEYPAIRINFO (diff)
downloadgnupg2-3377456252699c6db60de0ca90b8950584ccc8fa.tar.xz
gnupg2-3377456252699c6db60de0ca90b8950584ccc8fa.zip
Add missing file and other changes.
Diffstat (limited to 'common/iobuf.c')
-rw-r--r--common/iobuf.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/common/iobuf.c b/common/iobuf.c
index 8100883e3..9b13f8b02 100644
--- a/common/iobuf.c
+++ b/common/iobuf.c
@@ -1037,6 +1037,7 @@ iobuf_close (iobuf_t a)
{
memset (a->d.buf, 0, a->d.size); /* erase the buffer */
xfree (a->d.buf);
+ xfree (a->unget.buf);
}
xfree (a);
}
@@ -1538,6 +1539,7 @@ pop_filter (iobuf_t a, int (*f) (void *opaque, int control,
b = a->chain;
assert (b);
xfree (a->d.buf);
+ xfree (a->unget.buf);
xfree (a->real_fname);
memcpy (a, b, sizeof *a);
xfree (b);
@@ -1579,6 +1581,7 @@ pop_filter (iobuf_t a, int (*f) (void *opaque, int control,
*/
b = a->chain;
xfree (a->d.buf);
+ xfree (a->unget.buf);
xfree (a->real_fname);
memcpy (a, b, sizeof *a);
xfree (b);
@@ -1621,6 +1624,7 @@ underflow (iobuf_t a)
log_debug ("iobuf-%d.%d: pop `%s' in underflow\n",
a->no, a->subno, a->desc);
xfree (a->d.buf);
+ xfree (a->unget.buf);
xfree (a->real_fname);
memcpy (a, b, sizeof *a);
xfree (b);
@@ -1695,6 +1699,7 @@ underflow (iobuf_t a)
log_debug ("iobuf-%d.%d: pop `%s' in underflow (!len)\n",
a->no, a->subno, a->desc);
xfree (a->d.buf);
+ xfree (a->unget.buf);
xfree (a->real_fname);
memcpy (a, b, sizeof *a);
xfree (b);
@@ -1859,6 +1864,31 @@ iobuf_read (iobuf_t a, void *buffer, unsigned int buflen)
}
+
+/* This is a verly limited unget fucntion for an iobuf. It does only
+ work in certain cases and should be used with care. */
+void
+iobuf_unread (iobuf_t a, const unsigned char *buf, unsigned int buflen)
+{
+ unsigned int new_len;
+
+ if (!buflen)
+ return;
+
+ /* 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.
* NOTE: This only works in special cases.