diff options
Diffstat (limited to 'src/libstddjb/siovec_deal.c')
-rw-r--r-- | src/libstddjb/siovec_deal.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/libstddjb/siovec_deal.c b/src/libstddjb/siovec_deal.c index fffea92..3f802b9 100644 --- a/src/libstddjb/siovec_deal.c +++ b/src/libstddjb/siovec_deal.c @@ -1,24 +1,26 @@ /* ISC license. */ -#include <skalibs/bytestr.h> +#include <sys/types.h> +#include <sys/uio.h> +#include <string.h> #include <skalibs/siovec.h> -unsigned int siovec_deal (siovec_t const *vj, unsigned int nj, siovec_t const *vi, unsigned int ni) +size_t siovec_deal (struct iovec const *vj, unsigned int nj, struct iovec const *vi, unsigned int ni) { - unsigned int w = 0 ; + size_t w = 0 ; + size_t wi = 0 ; + size_t wj = 0 ; unsigned int i = 0 ; unsigned int j = 0 ; - unsigned int wi = 0 ; - unsigned int wj = 0 ; while (i < ni && j < nj) { - register unsigned int tor = vi[i].len - wi ; - register unsigned int tow = vj[j].len - wj ; - register unsigned int len = tor < tow ? tor : tow ; - byte_copy(vj[j].s + wj, len, vi[i].s + wi) ; + size_t tor = vi[i].iov_len - wi ; + size_t tow = vj[j].iov_len - wj ; + size_t len = tor < tow ? tor : tow ; + memmove((char *)vj[j].iov_base + wj, (char const *)vi[i].iov_base + wi, len) ; wi += len ; wj += len ; w += len ; - if (wi >= vi[i].len) { wi = 0 ; i++ ; } - if (wj >= vj[j].len) { wj = 0 ; j++ ; } + if (wi >= vi[i].iov_len) { wi = 0 ; i++ ; } + if (wj >= vj[j].iov_len) { wj = 0 ; j++ ; } } return w ; } |