siovec_scatter.c (429B)
1 /* ISC license. */ 2 3 #include <sys/uio.h> 4 #include <string.h> 5 #include <skalibs/siovec.h> 6 7 size_t siovec_scatter (struct iovec const *v, unsigned int n, char const *s, size_t len) 8 { 9 size_t w = 0 ; 10 unsigned int i = 0 ; 11 for (; i < n && w < len ; i++) 12 { 13 size_t chunklen = v[i].iov_len ; 14 if (w + chunklen > len) chunklen = len - w ; 15 memmove(v[i].iov_base, s + w, chunklen) ; 16 w += chunklen ; 17 } 18 return w ; 19 }