buffer_getvall.c (697B)
1 /* ISC license. */ 2 3 #include <sys/uio.h> 4 #include <errno.h> 5 #include <skalibs/allreadwrite.h> 6 #include <skalibs/buffer.h> 7 #include <skalibs/siovec.h> 8 9 int buffer_getvall (buffer *b, struct iovec const *v, unsigned int n, size_t *written) 10 { 11 size_t len = siovec_len(v, n) ; 12 struct iovec vv[n ? n : 1] ; 13 if (*written > len) return (errno = EINVAL, -1) ; 14 { 15 unsigned int i = n ; 16 while (i--) vv[i] = v[i] ; 17 } 18 siovec_seek(vv, n, *written) ; 19 for (;;) 20 { 21 ssize_t r ; 22 size_t w = buffer_getvnofill(b, vv, n) ; 23 *written += w ; 24 if (*written >= len) break ; 25 siovec_seek(vv, n, w) ; 26 r = sanitize_read(buffer_fill(b)) ; 27 if (r <= 0) return r ; 28 } 29 return 1 ; 30 }