summaryrefslogtreecommitdiffstats
path: root/util/iobuf.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>1998-05-04 20:49:26 +0200
committerWerner Koch <wk@gnupg.org>1998-05-04 20:49:26 +0200
commit42b03f6ebdda25a5b61db72cf9aecaaf6788de16 (patch)
treea36d2fe06b19dca6f64009010e2a731b45e6b886 /util/iobuf.c
parentfixed last passphrase bug (diff)
downloadgnupg2-42b03f6ebdda25a5b61db72cf9aecaaf6788de16.tar.xz
gnupg2-42b03f6ebdda25a5b61db72cf9aecaaf6788de16.zip
new releaseV0-2-17
Diffstat (limited to 'util/iobuf.c')
-rw-r--r--util/iobuf.c49
1 files changed, 39 insertions, 10 deletions
diff --git a/util/iobuf.c b/util/iobuf.c
index 3940f1034..1578d565b 100644
--- a/util/iobuf.c
+++ b/util/iobuf.c
@@ -728,15 +728,38 @@ iobuf_read(IOBUF a, byte *buf, unsigned buflen )
{
int c, n;
- for(n=0 ; n < buflen; n++, buf++ ) {
- if( (c = iobuf_readbyte(a)) == -1 ) {
- if( !n )
- return -1; /* eof */
- break;
+ if( a->unget.buf || a->nlimit ) {
+ /* handle special cases */
+ for(n=0 ; n < buflen; n++, buf++ ) {
+ if( (c = iobuf_readbyte(a)) == -1 ) {
+ if( !n )
+ return -1; /* eof */
+ break;
+ }
+ else
+ *buf = c;
}
- else
- *buf = c;
+ return n;
}
+
+ if( a->filter_eof ) {
+ if( DBG_IOBUF )
+ log_debug("iobuf-%d.%d: filter eof in iobuf_read\n", a->no, a->subno );
+ return -1;
+ }
+ n = 0;
+ do {
+ for( ; n < buflen && a->d.start < a->d.len; n++ )
+ *buf++ = a->d.buf[a->d.start++];
+ if( n < buflen ) {
+ if( (c=underflow(a)) == -1 ) {
+ a->nbytes += n;
+ return n? n : -1/*EOF*/;
+ }
+ *buf++ = c; n++;
+ }
+ } while( n < buflen );
+ a->nbytes += n;
return n;
}
@@ -782,12 +805,18 @@ iobuf_writebyte(IOBUF a, unsigned c)
int
iobuf_write(IOBUF a, byte *buf, unsigned buflen )
{
- for( ; buflen; buflen--, buf++ )
- if( iobuf_writebyte(a, *buf) )
- return -1;
+ do {
+ for( ; buflen && a->d.len < a->d.size; buflen--, buf++ )
+ a->d.buf[a->d.len++] = *buf;
+ if( buflen ) {
+ if( iobuf_flush(a) )
+ return -1;
+ }
+ } while( buflen );
return 0;
}
+
int
iobuf_writestr(IOBUF a, const char *buf )
{