diff options
Diffstat (limited to 'src/libstddjb/readnclose.c')
-rw-r--r-- | src/libstddjb/readnclose.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/libstddjb/readnclose.c b/src/libstddjb/readnclose.c new file mode 100644 index 0000000..28a3acb --- /dev/null +++ b/src/libstddjb/readnclose.c @@ -0,0 +1,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 ; +} |