From 032b853746aabb8c3b82af674fdc783b511569f2 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Sat, 4 Dec 2021 08:48:45 +0000 Subject: Add opendir_at, prepare for 2.11.1.0 Signed-off-by: Laurent Bercot --- src/include/skalibs/unix-transactional.h | 2 ++ src/libstddjb/fd_close.c | 4 ++-- src/libunixonacid/opendir_at.c | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 src/libunixonacid/opendir_at.c (limited to 'src') diff --git a/src/include/skalibs/unix-transactional.h b/src/include/skalibs/unix-transactional.h index a5e14b3..88d1838 100644 --- a/src/include/skalibs/unix-transactional.h +++ b/src/include/skalibs/unix-transactional.h @@ -8,6 +8,7 @@ #include #include +#include #include /* Transactional/reliable filesystem operations */ @@ -26,6 +27,7 @@ extern int open_truncat (int, char const *) ; extern int open_truncatb (int, char const *) ; extern int open_appendat (int, char const *) ; extern int open_appendatb (int, char const *) ; +extern DIR *opendir_at (int, char const *) ; extern int stat_at (int, char const *, struct stat *) ; extern int lstat_at (int, char const *, struct stat *) ; diff --git a/src/libstddjb/fd_close.c b/src/libstddjb/fd_close.c index a3c7880..dad6518 100644 --- a/src/libstddjb/fd_close.c +++ b/src/libstddjb/fd_close.c @@ -1,12 +1,12 @@ /* ISC license. */ -#include #include +#include #include void fd_close (int fd) { int e = errno ; - while (close(fd) < 0 && errno == EINTR) ; + close(fd) ; errno = e ; } diff --git a/src/libunixonacid/opendir_at.c b/src/libunixonacid/opendir_at.c new file mode 100644 index 0000000..bee971f --- /dev/null +++ b/src/libunixonacid/opendir_at.c @@ -0,0 +1,15 @@ +/* ISC license. */ + +#include +#include +#include + +DIR *opendir_at (int dfd, char const *name) +{ + DIR *dir ; + int fd = open_readatb(dfd, name) ; + if (fd < 0) return 0 ; + dir = fdopendir(fd) ; + if (!dir) fd_close(fd) ; + return dir ; +} -- cgit v1.2.3