X-Git-Url: http://www.dolda2000.com/gitweb/?a=blobdiff_plain;f=lib%2Fbufio.c;h=11d8c04252d373d4f2df8604e82adfeedc20722b;hb=595adb9922885c2a05bc6917ee8f8f02f496e618;hp=1929d31620c4f19885c714b68592d01cfd159ab1;hpb=8e01353ea837db6f80a154fafe9dea697ce03410;p=ashd.git diff --git a/lib/bufio.c b/lib/bufio.c index 1929d31..11d8c04 100644 --- a/lib/bufio.c +++ b/lib/bufio.c @@ -289,11 +289,11 @@ int bioprintf(struct bufio *bio, const char *format, ...) va_start(args, format); ret = vsnprintf(bio->wbuf.b + bio->wbuf.d, bio->wbuf.s - bio->wbuf.d, format, args); va_end(args); - if(ret <= bio->wbuf.s - bio->wbuf.d) { + if(ret < bio->wbuf.s - bio->wbuf.d) { bio->wbuf.d += ret; return(0); } - if(biowensure(bio, ret) < 0) + if(biowensure(bio, ret + 1) < 0) return(-1); } } @@ -309,3 +309,21 @@ ssize_t biocopysome(struct bufio *dst, struct bufio *src) src->rh += ret; return(ret); } + +ssize_t biocopybuf(struct bufio *dst, struct bufio *src) +{ + ssize_t ret; + + sizebuf(dst->wbuf, dst->bufhint); + if(dst->wbuf.d == dst->wbuf.s) { + if(dst->wh > 0) { + memmove(dst->wbuf.b, dst->wbuf.b + dst->wh, dst->wbuf.d -= dst->wh); + dst->wh = 0; + } + } + ret = min(src->rbuf.d - src->rh, dst->wbuf.s - dst->wbuf.d); + memcpy(dst->wbuf.b + dst->wbuf.d, src->rbuf.b + src->rh, ret); + src->rh += ret; + dst->wbuf.d += ret; + return(ret); +}