summaryrefslogtreecommitdiff
path: root/src/libstddjb/buffer_putall.c
blob: 16facc2a7e60ec1073622940483a2e0463c44d42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/* ISC license. */

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

int buffer_putall (buffer *b, char const *s, unsigned int len, unsigned int *written)
{
  if (*written > len) return (errno = EINVAL, 0) ;
  for (;;)
  {
    *written += buffer_putnoflush(b, s + *written, len - *written) ;
    if (*written >= len) return 1 ;
    buffer_flush(b) ;
    if (buffer_isfull(b)) return 0 ;
  }
}