summaryrefslogtreecommitdiff
path: root/src/libstddjb/readnclose.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2022-06-08 09:48:11 +0000
committerLaurent Bercot <ska@appnovation.com>2022-06-08 09:48:11 +0000
commitc4e81d83b248aa356849fc6a31920c177b5df999 (patch)
tree7b7516686db13bfb3643c0965fded313ea7240a9 /src/libstddjb/readnclose.c
parent6d419ff3e5a0e645e8fe9635d6ca139d5b7e3e7a (diff)
downloadskalibs-c4e81d83b248aa356849fc6a31920c177b5df999.tar.xz
Clean up / homogenize openreadnclose() family
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libstddjb/readnclose.c')
-rw-r--r--src/libstddjb/readnclose.c18
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 ;
+}