aboutsummaryrefslogtreecommitdiffstats
path: root/src/libunixonacid/stat_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/stat_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/stat_at.c')
-rw-r--r--src/libunixonacid/stat_at.c61
1 files changed, 30 insertions, 31 deletions
diff --git a/src/libunixonacid/stat_at.c b/src/libunixonacid/stat_at.c
index e4040d5..57aa8dd 100644
--- a/src/libunixonacid/stat_at.c
+++ b/src/libunixonacid/stat_at.c
@@ -8,10 +8,11 @@
#define _ATFILE_SOURCE
#endif
+#include <skalibs/bsdsnowflake.h>
#include <skalibs/nonposix.h>
-#include <sys/stat.h>
+#include <skalibs/stat.h>
#include <skalibs/fcntl.h>
#include <skalibs/unix-transactional.h>
@@ -27,52 +28,50 @@ int lstat_at (int dirfd, char const *file, struct stat *st)
#else
- /* OpenBSD plz. lstat() is POSIX. */
+#include <skalibs/bsdsnowflake.h>
#include <skalibs/nonposix.h>
-#include <sys/stat.h>
#include <errno.h>
+#include <skalibs/stat.h>
#include <skalibs/fcntl.h>
-#include <skalibs/djbunix.h>
#include <skalibs/unix-transactional.h>
+#include "at-internal.h"
-static int fstat_at (int dirfd, char const *file, struct stat *st, int (*dostat)(char const *, struct stat *))
+struct stat_s
{
- int r ;
- int fdhere = open_read(".") ;
- if (fdhere < 0) return -1 ;
- if (fd_chdir(dirfd) < 0)
- {
- fd_close(fdhere) ;
- return -1 ;
- }
- r = (*dostat)(file, st) ;
- if (r < 0)
- {
- int e = errno ;
- fd_chdir(fdhere) ;
- fd_close(fdhere) ;
- errno = e ;
- return -1 ;
- }
- if (fd_chdir(fdhere) < 0)
- {
- fd_close(fdhere) ;
- return -1 ;
- }
- fd_close(fdhere) ;
- return r ;
+ char const *file ;
+ struct stat *st ;
+} ;
+
+static int do_stat (void *p)
+{
+ struct stat_s *b = p ;
+ return stat(b->file, b->st) ;
+}
+
+static int do_lstat (void *p)
+{
+ struct stat_s *b = p ;
+ return lstat(b->file, b->st) ;
+}
+
+static void cancel_stat (int r, void *p)
+{
+ (void)r ;
+ (void)p ;
}
int stat_at (int dirfd, char const *file, struct stat *st)
{
- return fstat_at(dirfd, file, st, &stat) ;
+ struct stat_s args = { .file = file, .st = st } ;
+ return emulate_at(dirfd, &do_stat, &cancel_stat, &args) ;
}
int lstat_at (int dirfd, char const *file, struct stat *st)
{
- return fstat_at(dirfd, file, st, &lstat) ;
+ struct stat_s args = { .file = file, .st = st } ;
+ return emulate_at(dirfd, &do_lstat, &cancel_stat, &args) ;
}
#endif