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

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

int buffer_getall (buffer_ref b, char *buf, unsigned int len, unsigned int *w)
{
  if (*w > len) return (errno = EINVAL, -1) ;
  *w += buffer_getnofill(b, buf + *w, len - *w) ;
  while (*w < len)
  {
    register int r = sanitize_read(buffer_fill(b)) ;
    if (r <= 0) return r ;
    *w += buffer_getnofill(b, buf + *w, len - *w) ;
  }
  return 1 ;
}