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

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

size_t allreadwrite (iofunc_t_ref op, int fd, char *buf, size_t len)
{
  size_t written = 0 ;
  while (len)
  {
    ssize_t w = (*op)(fd, buf, len) ;
    if (w <= 0)
    {
      if (!w) errno = 0 ;
      break ;
    }
    written += w ;
    buf += w ;
    len -= w ;
  }
  return written ;
}