1 /*
2 * stat() 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 <sys/syscall.h>
10 #include <unistd.h>
11 #include <sys/stat.h>
12 #include <bits/uClibc_arch_features.h>
13
14 #undef stat
15
16 #if defined __NR_fstatat64 && !defined __NR_stat && !defined(__UCLIBC_USE_TIME64__)
17 # include <fcntl.h>
18
stat(const char * file_name,struct stat * buf)19 int stat(const char *file_name, struct stat *buf)
20 {
21 return fstatat(AT_FDCWD, file_name, buf, 0);
22 }
23
24 #elif __WORDSIZE == 64 && defined __NR_newfstatat && !defined __ARCH_HAS_DEPRECATED_SYSCALLS__
25 # include <fcntl.h>
26
stat(const char * file_name,struct stat * buf)27 int stat(const char *file_name, struct stat *buf)
28 {
29 return fstatat64(AT_FDCWD, file_name, (struct stat64 *)buf, 0);
30 }
31 #elif __NR_statx && defined __UCLIBC_HAVE_STATX__
32 # include <fcntl.h>
33 # include <statx_cp.h>
34
stat(const char * file_name,struct stat * buf)35 int stat(const char *file_name, struct stat *buf)
36 {
37 struct statx tmp;
38 int rc = INLINE_SYSCALL (statx, 5, AT_FDCWD, file_name, AT_NO_AUTOMOUNT,
39 STATX_BASIC_STATS, &tmp);
40 if (rc == 0)
41 __cp_stat_statx ((struct stat *)buf, &tmp);
42
43 return rc;
44 }
45 #else
46 # include "xstatconv.h"
47
stat(const char * file_name,struct stat * buf)48 int stat(const char *file_name, struct stat *buf)
49 {
50 int result;
51 # ifdef __NR_stat64
52 /* normal stat call has limited values for various stat elements
53 * e.g. uid device major/minor etc.
54 * so we use 64 variant if available
55 * in order to get newer versions of stat elements
56 */
57 struct kernel_stat64 kbuf;
58 result = INLINE_SYSCALL(stat64, 2, file_name, &kbuf);
59 if (result == 0) {
60 __xstat32_conv(&kbuf, buf);
61 }
62 # else
63 struct kernel_stat kbuf;
64
65 result = INLINE_SYSCALL(stat, 2, file_name, &kbuf);
66 if (result == 0) {
67 __xstat_conv(&kbuf, buf);
68 }
69 # endif /* __NR_stat64 */
70 return result;
71 }
72 #endif /* __NR_fstat64 */
73 libc_hidden_def(stat)
74
75 #if ! defined __NR_stat64 && ! defined __NR_fstatat64 && ! defined __UCLIBC_HAVE_STATX__
76 strong_alias_untyped(stat,stat64)
77 libc_hidden_def(stat64)
78 #endif
79