diff options
| author | Laurent Bercot <ska-skaware@skarnet.org> | 2025-06-30 22:04:01 +0000 |
|---|---|---|
| committer | Laurent Bercot <ska@appnovation.com> | 2025-06-30 22:04:01 +0000 |
| commit | 17cfa0cb58bcfadb08b355eb5fd511ed6829ee5d (patch) | |
| tree | c543b313369bb13e5a6a894c0c1b1fb408ef4586 /src/libunixonacid/open2_at.c | |
| parent | d4895d80b1b1af9086b08f7c6cb12f274baf2ddc (diff) | |
| download | skalibs-17cfa0cb58bcfadb08b355eb5fd511ed6829ee5d.tar.gz | |
Refactor _at functions, add symlink_at
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libunixonacid/open2_at.c')
| -rw-r--r-- | src/libunixonacid/open2_at.c | 48 |
1 files changed, 22 insertions, 26 deletions
diff --git a/src/libunixonacid/open2_at.c b/src/libunixonacid/open2_at.c index d96c0b7..3afc4fb 100644 --- a/src/libunixonacid/open2_at.c +++ b/src/libunixonacid/open2_at.c @@ -12,6 +12,7 @@ #include <errno.h> +#include <skalibs/stat.h> #include <skalibs/fcntl.h> #include <skalibs/unix-transactional.h> @@ -25,38 +26,33 @@ int open2_at (int dirfd, char const *file, int flags) #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 open2_at (int dirfd, char const *file, int flags) +struct open2_s { - int fd ; - int fdhere = open_read(".") ; - if (fdhere < 0) return -1 ; - if (fd_chdir(dirfd) < 0) goto errclose ; - fd = open2(file, flags) ; - 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 ; +} ; - errclose: - fd_close(fdhere) ; - return -1 ; +static int do_open2 (void *p) +{ + struct open2_s *b = p ; + return open2(b->file, b->flags) ; +} + +static void cancel_open2 (int fd, void *p) +{ + (void)p ; + fd_close(fd) ; +} + +int open2_at (int dirfd, char const *file, int flags) +{ + struct open2_s args = { .file = file, .flags = flags } ; + return emulate_at(dirfd, &do_open2, &cancel_open2, &args) ; } #endif |
