siovec_seek.c (496B)
1 /* ISC license. */ 2 3 #include <sys/uio.h> 4 #include <skalibs/bytestr.h> 5 #include <skalibs/siovec.h> 6 7 size_t siovec_seek (struct iovec *v, unsigned int n, size_t len) 8 { 9 size_t w = 0 ; 10 unsigned int i = 0 ; 11 for (; i < n ; i++) 12 { 13 if (len < v[i].iov_len) break ; 14 w += v[i].iov_len ; 15 len -= v[i].iov_len ; 16 v[i].iov_base = 0 ; 17 v[i].iov_len = 0 ; 18 } 19 if (i < n) 20 { 21 v[i].iov_base = (char *)v[i].iov_base + len ; 22 v[i].iov_len -= len ; 23 w += len ; 24 } 25 return w ; 26 }