aboutsummaryrefslogtreecommitdiffstats
path: root/src/libunixonacid/open3_at.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2025-06-30 22:04:01 +0000
committerLaurent Bercot <ska@appnovation.com>2025-06-30 22:04:01 +0000
commit17cfa0cb58bcfadb08b355eb5fd511ed6829ee5d (patch)
treec543b313369bb13e5a6a894c0c1b1fb408ef4586 /src/libunixonacid/open3_at.c
parentd4895d80b1b1af9086b08f7c6cb12f274baf2ddc (diff)
downloadskalibs-17cfa0cb58bcfadb08b355eb5fd511ed6829ee5d.tar.gz
Refactor _at functions, add symlink_at
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libunixonacid/open3_at.c')
-rw-r--r--src/libunixonacid/open3_at.c48
1 files changed, 22 insertions, 26 deletions
diff --git a/src/libunixonacid/open3_at.c b/src/libunixonacid/open3_at.c
index 742a579..a960339 100644
--- a/src/libunixonacid/open3_at.c
+++ b/src/libunixonacid/open3_at.c
@@ -25,38 +25,34 @@ int open3_at (int dirfd, char const *file, int flags, unsigned int mode)
#else
-#include <sys/stat.h>
-#include <errno.h>
-
#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
#include <skalibs/unix-transactional.h>
+#include "at-internal.h"
-int open3_at (int dirfd, char const *file, int flags, unsigned int mode)
+struct open3_s
{
- int fd ;
- int fdhere = open_read(".") ;
- if (fdhere < 0) return -1 ;
- if (fd_chdir(dirfd) < 0) goto errclose ;
- fd = open3(file, flags, mode) ;
- if (fd < 0)
- {
- int e = errno ;
- fd_chdir(fdhere) ;
- errno = e ;
- goto errclose ;
- }
- if (fd_chdir(fdhere) < 0)
- {
- fd_close(fd) ;
- goto errclose ;
- }
- fd_close(fdhere) ;
- return fd ;
+ char const *file ;
+ int flags ;
+ unsigned int mode ;
+} ;
- errclose:
- fd_close(fdhere) ;
- return -1 ;
+static int do_open3 (void *p)
+{
+ struct open3_s *b = p ;
+ return open3(b->file, b->flags, b->mode) ;
+}
+
+static void cancel_open3 (int fd, void *p)
+{
+ (void)p ;
+ fd_close(fd) ;
+}
+
+int open3_at (int dirfd, char const *file, int flags, unsigned int mode)
+{
+ struct open3_s args = { .file = file, .flags = flags, .mode = mode } ;
+ return emulate_at(dirfd, &do_open3, &cancel_open3, &args) ;
}
#endif