summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/common/fstatat64.c
blob: 739e84081e167e6cf0e385867114ed904443abd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 * fstatat64() for uClibc
 *
 * Copyright (C) 2009 Analog Devices Inc.
 *
 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
 */

#include <_lfs_64.h>
#include <bits/wordsize.h>
#include <sys/syscall.h>
#include <linux/version.h>

#if defined __mips__
# include <sgidefs.h>
#endif

/* 64bit ports tend to favor newfstatat() */
#if __WORDSIZE == 64 && defined __NR_newfstatat
# define __NR_fstatat64 __NR_newfstatat
#endif
/* mips N32 ABI use newfstatat(), too */
#if defined __mips__ && _MIPS_SIM == _ABIN32
# define __NR_fstatat64 __NR_newfstatat
#endif

#if defined(__NR_fstatat64) && (!defined(__UCLIBC_USE_TIME64__)  || LINUX_VERSION_CODE <= KERNEL_VERSION(5,1,0))
# include <sys/stat.h>
# include "xstatconv.h"
int fstatat64(int fd, const char *file, struct stat64 *buf, int flag)
{
# ifdef __ARCH_HAS_DEPRECATED_SYSCALLS__
	int ret;
	struct kernel_stat64 kbuf;

	ret = INLINE_SYSCALL(fstatat64, 4, fd, file, &kbuf, flag);
	if (ret == 0)
		__xstat64_conv(&kbuf, buf);

	return ret;
# else
	return INLINE_SYSCALL(fstatat64, 4, fd, file, buf, flag);
# endif
}
libc_hidden_def(fstatat64)
#else

#if defined(__NR_statx) && defined(__UCLIBC_HAVE_STATX__)
# include <sys/stat.h>
# include <statx_cp.h>
# include <fcntl.h> // for AT_NO_AUTOMOUNT

int fstatat64(int fd, const char *file, struct stat64 *buf, int flag)
{
	struct statx tmp;

	int r = INLINE_SYSCALL(statx, 5, fd, file, AT_NO_AUTOMOUNT | flag,
			       STATX_BASIC_STATS, &tmp);

	if (r == 0)
		__cp_stat64_statx ((struct stat64 *)buf, &tmp);

	return r;
}
libc_hidden_def(fstatat64)
#endif

/* should add emulation with fstat64() and /proc/self/fd/ ... */
#endif