summaryrefslogtreecommitdiff
path: root/src/libstddjb/allreadwritev.c
blob: 28695a137bc159b7a91f6511a3581ec72a6e4b92 (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 <errno.h>
#include <skalibs/allreadwrite.h>
#include <skalibs/siovec.h>

unsigned int allreadwritev (iovfunc_t_ref op, int fd, siovec_t const *v, unsigned int vlen)
{
  register unsigned int written = 0 ;
  siovec_t vv[vlen] ;
  for (; written < vlen ; written++) vv[written] = v[written] ;
  written = 0 ;
  while (siovec_len(vv, vlen))
  {
    register int w = (*op)(fd, vv, vlen) ;
    if (w <= 0) break ;
    w = siovec_seek(vv, vlen, w) ;
    written += w ;
  }
  return written ;
}