summaryrefslogtreecommitdiff
path: root/src/libunixonacid/openslurpclose_at.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libunixonacid/openslurpclose_at.c')
-rw-r--r--src/libunixonacid/openslurpclose_at.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/libunixonacid/openslurpclose_at.c b/src/libunixonacid/openslurpclose_at.c
new file mode 100644
index 0000000..cf2f8ee
--- /dev/null
+++ b/src/libunixonacid/openslurpclose_at.c
@@ -0,0 +1,21 @@
+/* ISC license. */
+
+#include <errno.h>
+#include <skalibs/stralloc.h>
+#include <skalibs/djbunix.h>
+#include <skalibs/unix-transactional.h>
+
+int openslurpclose_at (int dirfd, char const *fn, stralloc *sa)
+{
+ int fd = open_readatb(dirfd, fn) ;
+ if (fd < 0) return 0 ;
+ if (!slurp(sa, fd))
+ {
+ register int e = errno ;
+ fd_close(fd) ;
+ errno = e ;
+ return 0 ;
+ }
+ fd_close(fd) ;
+ return 1 ;
+}