summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/common/fstatat.c
diff options
context:
space:
mode:
authorYann Sionneau <ysionneau@kalray.eu>2023-09-14 16:29:41 +0200
committerWaldemar Brodkorb <wbx@openadk.org>2023-09-14 16:46:52 +0200
commitf61a240363a173982809f1448450a77207286e3c (patch)
tree07122ff945fd2faffeffd18d1d17ceaaa21ddef4 /libc/sysdeps/linux/common/fstatat.c
parent95e38b378480b7935238b8b2b2712f76211f4fea (diff)
fstatat: add wrapper that uses statx for non-legacy arch
Add fstatat wrapper that uses statx for non-legacy arch. This allows non-legacy arch to opt-out from defining the old stat* syscalls by not defining __ARCH_WANT_NEW_STAT in their arch/xxx/include/asm/unistd.h Signed-off-by: Yann Sionneau <ysionneau@kalray.eu>
Diffstat (limited to 'libc/sysdeps/linux/common/fstatat.c')
-rw-r--r--libc/sysdeps/linux/common/fstatat.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/libc/sysdeps/linux/common/fstatat.c b/libc/sysdeps/linux/common/fstatat.c
index 13673d76c..db4a8327f 100644
--- a/libc/sysdeps/linux/common/fstatat.c
+++ b/libc/sysdeps/linux/common/fstatat.c
@@ -31,5 +31,44 @@ int fstatat(int fd, const char *file, struct stat *buf, int flag)
}
libc_hidden_def(fstatat)
#else
+
+#if defined(__NR_statx)
+#include <sys/sysmacros.h> // for makedev
+
+int fstatat(int fd, const char *file, struct stat *buf, int flag)
+{
+ int ret;
+ struct statx tmp;
+
+ ret = INLINE_SYSCALL(statx, 5, fd, file, flag,
+ STATX_BASIC_STATS, &tmp);
+ if (ret != 0)
+ return ret;
+
+ *buf = (struct stat) {
+ .st_dev = makedev(tmp.stx_dev_major, tmp.stx_dev_minor),
+ .st_ino = tmp.stx_ino,
+ .st_mode = tmp.stx_mode,
+ .st_nlink = tmp.stx_nlink,
+ .st_uid = tmp.stx_uid,
+ .st_gid = tmp.stx_gid,
+ .st_rdev = makedev(tmp.stx_rdev_major, tmp.stx_rdev_minor),
+ .st_size = tmp.stx_size,
+ .st_blksize = tmp.stx_blksize,
+ .st_blocks = tmp.stx_blocks,
+ .st_atim.tv_sec = tmp.stx_atime.tv_sec,
+ .st_atim.tv_nsec = tmp.stx_atime.tv_nsec,
+ .st_mtim.tv_sec = tmp.stx_mtime.tv_sec,
+ .st_mtim.tv_nsec = tmp.stx_mtime.tv_nsec,
+ .st_ctim.tv_sec = tmp.stx_ctime.tv_sec,
+ .st_ctim.tv_nsec = tmp.stx_ctime.tv_nsec,
+ };
+
+ return ret;
+}
+libc_hidden_def(fstatat)
+
+#endif
+
/* should add emulation with fstat() and /proc/self/fd/ ... */
#endif