From: Fredrik Tolf Date: Mon, 16 May 2016 02:31:03 +0000 (+0200) Subject: lib: Added bufio I/O-less copy function. X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=99a520b62935330a92ca30534b899423c0a28240;p=ashd.git lib: Added bufio I/O-less copy function. --- diff --git a/lib/bufio.c b/lib/bufio.c index 1929d31..c08e9dd 100644 --- a/lib/bufio.c +++ b/lib/bufio.c @@ -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); +} diff --git a/lib/bufio.h b/lib/bufio.h index 7e8b9de..5874577 100644 --- a/lib/bufio.h +++ b/lib/bufio.h @@ -36,5 +36,6 @@ ssize_t biowrite(struct bufio *bio, const void *data, size_t len); ssize_t biowritesome(struct bufio *bio, const void *data, size_t len); int bioprintf(struct bufio *bio, const char *format, ...); ssize_t biocopysome(struct bufio *dst, struct bufio *src); +ssize_t biocopybuf(struct bufio *dst, struct bufio *src); #endif