bump version for 1.0.49 release
[uclibc-ng.git] / libc / sysdeps / linux / common / fstatat.c
blob14b118cc0ef34c6e40e59a49356e055948568bc3
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"
12 #include <bits/uClibc_arch_features.h>
14 /* 64bit ports tend to favor newfstatat() */
15 #if __WORDSIZE == 64 && defined __NR_newfstatat
16 # define __NR_fstatat64 __NR_newfstatat
17 #endif
19 #if defined(__NR_fstatat64) && !defined(__UCLIBC_USE_TIME64__)
20 int fstatat(int fd, const char *file, struct stat *buf, int flag)
22 int ret;
23 # ifdef __ARCH_HAS_DEPRECATED_SYSCALLS__
24 struct kernel_stat64 kbuf;
25 ret = INLINE_SYSCALL(fstatat64, 4, fd, file, &kbuf, flag);
26 if (ret == 0)
27 __xstat32_conv(&kbuf, buf);
28 # else
29 ret = INLINE_SYSCALL(fstatat64, 4, fd, file, buf, flag);
30 # endif /* __ARCH_HAS_DEPRECATED_SYSCALLS__ */
31 return ret;
33 libc_hidden_def(fstatat)
34 #else
36 #if defined(__NR_statx) && defined __UCLIBC_HAVE_STATX__
37 #include <sys/sysmacros.h> // for makedev
39 int fstatat(int fd, const char *file, struct stat *buf, int flag)
41 int ret;
42 struct statx tmp;
44 ret = INLINE_SYSCALL(statx, 5, fd, file, flag,
45 STATX_BASIC_STATS, &tmp);
46 if (ret != 0)
47 return ret;
49 *buf = (struct stat) {
50 .st_dev = makedev(tmp.stx_dev_major, tmp.stx_dev_minor),
51 .st_ino = tmp.stx_ino,
52 .st_mode = tmp.stx_mode,
53 .st_nlink = tmp.stx_nlink,
54 .st_uid = tmp.stx_uid,
55 .st_gid = tmp.stx_gid,
56 .st_rdev = makedev(tmp.stx_rdev_major, tmp.stx_rdev_minor),
57 .st_size = tmp.stx_size,
58 .st_blksize = tmp.stx_blksize,
59 .st_blocks = tmp.stx_blocks,
60 .st_atim.tv_sec = tmp.stx_atime.tv_sec,
61 .st_atim.tv_nsec = tmp.stx_atime.tv_nsec,
62 .st_mtim.tv_sec = tmp.stx_mtime.tv_sec,
63 .st_mtim.tv_nsec = tmp.stx_mtime.tv_nsec,
64 .st_ctim.tv_sec = tmp.stx_ctime.tv_sec,
65 .st_ctim.tv_nsec = tmp.stx_ctime.tv_nsec,
68 return ret;
70 libc_hidden_def(fstatat)
72 #endif
74 /* should add emulation with fstat() and /proc/self/fd/ ... */
75 #endif