X-Git-Url: http://dolda2000.com/gitweb/?p=ashd.git;a=blobdiff_plain;f=lib%2Fbufio.c;h=c08e9dd9a96f18ec2c1c974ec37697f597580e75;hp=fe5d005a9a922a4a15427e47c5d9e8e493926bc7;hb=99a520b62935330a92ca30534b899423c0a28240;hpb=ba2bdc3d5ffd134ac468696b9fcdbc18ffc07270 diff --git a/lib/bufio.c b/lib/bufio.c index fe5d005..c08e9dd 100644 --- a/lib/bufio.c +++ b/lib/bufio.c @@ -267,8 +267,14 @@ ssize_t biowritesome(struct bufio *bio, const void *data, size_t len) ret = min(len, bio->wbuf.s - bio->wbuf.d); memcpy(bio->wbuf.b + bio->wbuf.d, data, ret); bio->wbuf.d += ret; - if((bioflushsome(bio) < 0) && (ret == 0)) - return(-1); + if(bioflushsome(bio) < 0) { + if(ret == 0) + return(-1); + if(ret < bio->wbuf.d - bio->wh) { /* Should never be false */ + bio->wbuf.d -= ret; + return(-1); + } + } return(ret); } @@ -303,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); +}