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

#include <errno.h>
#include <skalibs/buffer.h>
#include <skalibs/siovec.h>

int buffer_putvall (buffer *b, siovec_t const *v, unsigned int n, unsigned int *written)
{
  unsigned int len = siovec_len(v, n) ;
  unsigned int w = n ;
  siovec_t vv[n] ;
  if (*written > len) return (errno = EINVAL, 0) ;
  while (w--) vv[w] = v[w] ;
  w = *written ;
  for (;;)
  {
    siovec_seek(vv, n, w) ;
    w = buffer_putvnoflush(b, vv, n) ;
    *written += w ;
    if (*written >= len) return 1 ;
    buffer_flush(b) ;
    if (buffer_isfull(b)) return 0 ;
  }
}