1 /*
2 * fstat() for uClibc
3 *
4 * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
5 *
6 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
7 */
8
9 #include <features.h>
10 #include <unistd.h>
11 #include <sys/stat.h>
12 #include <sys/syscall.h>
13 #include <bits/uClibc_arch_features.h>
14
15 #include "xstatconv.h"
16
17 #if defined __NR_fstat64 && !defined __NR_fstat && !defined(__UCLIBC_USE_TIME64__)
fstat(int fd,struct stat * buf)18 int fstat(int fd, struct stat *buf)
19 {
20 return INLINE_SYSCALL(fstat64, 2, fd, buf);
21 }
22 libc_hidden_def(fstat)
23
24 #elif __WORDSIZE == 64 && defined __NR_newfstatat && !defined __ARCH_HAS_DEPRECATED_SYSCALLS__
25 #include <fcntl.h>
26
27 int fstat(int fd, struct stat *buf)
28 {
29 return INLINE_SYSCALL(fstat, 2, fd, buf);
30 }
31 libc_hidden_def(fstat)
32
33 #elif defined __NR_statx && defined __UCLIBC_HAVE_STATX__
34 # include <fcntl.h>
35 # include <statx_cp.h>
36
37 int fstat(int fd, struct stat *buf)
38 {
39 struct statx tmp;
40 int rc = INLINE_SYSCALL (statx, 5, fd, "", AT_EMPTY_PATH,
41 STATX_BASIC_STATS, &tmp);
42 if (rc == 0)
43 __cp_stat_statx ((struct stat *)buf, &tmp);
44
45 return rc;
46 }
47 libc_hidden_def(fstat)
48
49 #elif defined __NR_fstat
50 int fstat(int fd, struct stat *buf)
51 {
52 int result;
53 # ifdef __NR_fstat64
54 /* normal stat call has limited values for various stat elements
55 * e.g. uid device major/minor etc.
56 * so we use 64 variant if available
57 * in order to get newer versions of stat elements
58 */
59 struct kernel_stat64 kbuf;
60 result = INLINE_SYSCALL(fstat64, 2, fd, &kbuf);
61 if (result == 0) {
62 __xstat32_conv(&kbuf, buf);
63 }
64 # else
65 struct kernel_stat kbuf;
66
67 result = INLINE_SYSCALL(fstat, 2, fd, &kbuf);
68 if (result == 0) {
69 __xstat_conv(&kbuf, buf);
70 }
71 # endif
72 return result;
73 }
74 libc_hidden_def(fstat)
75 #endif
76
77 # if ! defined __NR_fstat64 && ! defined __UCLIBC_HAVE_STATX__
78 strong_alias_untyped(fstat,fstat64)
79 libc_hidden_def(fstat64)
80 #endif
81