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; }