summaryrefslogtreecommitdiff
path: root/src/libstddjb/allreadwrite.c
blob: a811f6962f9fcd14ee39c3f4fca070bbb3121a51 (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>

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 <= 0)
    {
      if (!w) errno = 0 ;
      break ;
    }
    written += w ;
    buf += w ;
    len -= w ;
  }
  return written ;
}