siovec_deal.c (678B)
1 /* ISC license. */ 2 3 #include <sys/uio.h> 4 #include <string.h> 5 #include <skalibs/siovec.h> 6 7 size_t siovec_deal (struct iovec const *vj, unsigned int nj, struct iovec const *vi, unsigned int ni) 8 { 9 size_t w = 0 ; 10 size_t wi = 0 ; 11 size_t wj = 0 ; 12 unsigned int i = 0 ; 13 unsigned int j = 0 ; 14 while (i < ni && j < nj) 15 { 16 size_t tor = vi[i].iov_len - wi ; 17 size_t tow = vj[j].iov_len - wj ; 18 size_t len = tor < tow ? tor : tow ; 19 memmove((char *)vj[j].iov_base + wj, (char const *)vi[i].iov_base + wi, len) ; 20 wi += len ; wj += len ; w += len ; 21 if (wi >= vi[i].iov_len) { wi = 0 ; i++ ; } 22 if (wj >= vj[j].iov_len) { wj = 0 ; j++ ; } 23 } 24 return w ; 25 }