skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

buffer_getall.c (410B)


      1 /* ISC license. */
      2 
      3 #include <errno.h>
      4 #include <skalibs/allreadwrite.h>
      5 #include <skalibs/buffer.h>
      6 
      7 int buffer_getall (buffer *b, char *buf, size_t len, size_t *w)
      8 {
      9   if (*w > len) return (errno = EINVAL, -1) ;
     10   for (;;)
     11   {
     12     ssize_t r ;
     13     *w += buffer_getnofill(b, buf + *w, len - *w) ;
     14     if (*w >= len) break ;
     15     r = sanitize_read(buffer_fill(b)) ;
     16     if (r <= 0) return r ;
     17   }
     18   return 1 ;
     19 }