summaryrefslogtreecommitdiff
path: root/src/libstddjb/allreadwritev.c
blob: 41d6eefcf761262844e3a8730e3e05e2d431a061 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* ISC license. */

#include <sys/uio.h>
#include <skalibs/siovec.h>
#include <skalibs/allreadwrite.h>

size_t allreadwritev (iov_func_ref op, int fd, struct iovec const *v, unsigned int vlen)
{
  size_t written = 0 ;
  struct iovec vv[vlen ? vlen : 1] ;
  unsigned int i = vlen ;
  while (i--) vv[i] = v[i] ;
  while (siovec_len(vv, vlen))
  {
    ssize_t w = (*op)(fd, vv, vlen) ;
    if (w <= 0) break ;
    w = siovec_seek(vv, vlen, w) ;
    written += w ;
  }
  return written ;
}