readnclose.c (295B)
1 /* ISC license. */ 2 3 #include <errno.h> 4 5 #include <skalibs/allreadwrite.h> 6 #include <skalibs/djbunix.h> 7 8 ssize_t readnclose (int fd, char *s, size_t n) 9 { 10 int e = errno ; 11 size_t r ; 12 errno = 0 ; 13 r = allread(fd, s, n) ; 14 fd_close(fd) ; 15 if (errno) return -1 ; 16 errno = e ; 17 return r ; 18 }