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

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

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