summaryrefslogtreecommitdiff
path: root/src/libstddjb/readnclose.c
blob: 28a3acbba2f403fbdd806d9f2c554d0f5a2e187f (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/djbunix.h>

ssize_t readnclose (int fd, char *s, size_t n)
{
  int e = errno ;
  size_t r ;
  errno = 0 ;
  r = allread(fd, s, n) ;
  fd_close(fd) ;
  if (errno) return -1 ;
  errno = e ;
  return r ;
}