fstatat: add wrapper that uses statx for non-legacy arch
[uclibc-ng.git] / libc / sysdeps / linux / common / fstatat.c
blobdb4a8327f49377c700770f671d0d463a2ad66a92
1 /*
2 * fstatat() for uClibc
4 * Copyright (C) 2009 Analog Devices Inc.
6 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
7 */
9 #include <sys/syscall.h>
10 #include <sys/stat.h>
11 #include "xstatconv.h"
13 /* 64bit ports tend to favor newfstatat() */
14 #if __WORDSIZE == 64 && defined __NR_newfstatat
15 # define __NR_fstatat64 __NR_newfstatat
16 #endif
18 #ifdef __NR_fstatat64
19 int fstatat(int fd, const char *file, struct stat *buf, int flag)
21 int ret;
22 # ifdef __ARCH_HAS_DEPRECATED_SYSCALLS__
23 struct kernel_stat64 kbuf;
24 ret = INLINE_SYSCALL(fstatat64, 4, fd, file, &kbuf, flag);
25 if (ret == 0)
26 __xstat32_conv(&kbuf, buf);
27 # else
28 ret = INLINE_SYSCALL(fstatat64, 4, fd, file, buf, flag);
29 # endif /* __ARCH_HAS_DEPRECATED_SYSCALLS__ */
30 return ret;
32 libc_hidden_def(fstatat)
33 #else
35 #if defined(__NR_statx)
36 #include <sys/sysmacros.h> // for makedev
38 int fstatat(int fd, const char *file, struct stat *buf, int flag)
40 int ret;
41 struct statx tmp;
43 ret = INLINE_SYSCALL(statx, 5, fd, file, flag,
44 STATX_BASIC_STATS, &tmp);
45 if (ret != 0)
46 return ret;
48 *buf = (struct stat) {
49 .st_dev = makedev(tmp.stx_dev_major, tmp.stx_dev_minor),
50 .st_ino = tmp.stx_ino,
51 .st_mode = tmp.stx_mode,
52 .st_nlink = tmp.stx_nlink,
53 .st_uid = tmp.stx_uid,
54 .st_gid = tmp.stx_gid,
55 .st_rdev = makedev(tmp.stx_rdev_major, tmp.stx_rdev_minor),
56 .st_size = tmp.stx_size,
57 .st_blksize = tmp.stx_blksize,
58 .st_blocks = tmp.stx_blocks,
59 .st_atim.tv_sec = tmp.stx_atime.tv_sec,
60 .st_atim.tv_nsec = tmp.stx_atime.tv_nsec,
61 .st_mtim.tv_sec = tmp.stx_mtime.tv_sec,
62 .st_mtim.tv_nsec = tmp.stx_mtime.tv_nsec,
63 .st_ctim.tv_sec = tmp.stx_ctime.tv_sec,
64 .st_ctim.tv_nsec = tmp.stx_ctime.tv_nsec,
67 return ret;
69 libc_hidden_def(fstatat)
71 #endif
73 /* should add emulation with fstat() and /proc/self/fd/ ... */
74 #endif