From 636cfb70b094e959e73ec6120390bfedb0b94afc Mon Sep 17 00:00:00 2001 From: leitner Date: Tue, 9 Aug 2005 11:04:44 +0000 Subject: [PATCH] make sure buffer_get tries to get all the bytes it was asked for --- buffer/buffer_get.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/buffer/buffer_get.c b/buffer/buffer_get.c index 6f35cba..c9bcec4 100644 --- a/buffer/buffer_get.c +++ b/buffer/buffer_get.c @@ -2,11 +2,18 @@ #include "buffer.h" int buffer_get(buffer* b,char* x,unsigned long int len) { + unsigned long done; int blen; - if ((blen=buffer_feed(b))<0) return blen; - if ((unsigned long int) blen>=len) - blen=len; - byte_copy(x,blen,b->x+b->p); - b->p+=blen; - return blen; + done=0; + while (len) { + if ((blen=buffer_feed(b))<=0) return blen; + if ((unsigned long int) blen>=len) + blen=len; + byte_copy(x,blen,b->x+b->p); + b->p+=blen; + len-=blen; + x+=blen; + done+=blen; + } + return done; }