1 /* xstat64 using Linux stat64 system call.
2    Copyright (C) 1991-2022 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4 
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9 
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14 
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, see
17    <https://www.gnu.org/licenses/>.  */
18 
19 #define __xstat __redirect___xstat
20 #include <sys/stat.h>
21 #undef __xstat
22 #include <fcntl.h>
23 #include <kernel_stat.h>
24 #include <sysdep.h>
25 #include <xstatconv.h>
26 #include <statx_cp.h>
27 #include <shlib-compat.h>
28 
29 #if LIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_33)
30 
31 /* Get information about the file NAME in BUF.  */
32 
33 int
___xstat64(int vers,const char * name,struct stat64 * buf)34 ___xstat64 (int vers, const char *name, struct stat64 *buf)
35 {
36 #if XSTAT_IS_XSTAT64
37 # ifdef __NR_stat64
38   /* 64-bit kABI outlier, e.g. sparc64.  */
39   if (vers == _STAT_VER_KERNEL)
40     return INLINE_SYSCALL_CALL (stat, name, buf);
41   else
42     {
43       struct stat64 st64;
44       int r = INLINE_SYSCALL_CALL (stat64, name, &st64);
45       return r ?: __xstat32_conv (vers, &st64, (struct stat *) buf);
46     }
47 # elif defined __NR_stat
48   /* Old 64-bit kABI, e.g. ia64, powerpc64*, s390x, and x86_64.  */
49   if (vers == _STAT_VER_KERNEL || vers == _STAT_VER_LINUX)
50     return INLINE_SYSCALL_CALL (stat, name, buf);
51 # elif defined __NR_newfstatat
52   /* New kABIs which uses generic 64-bit Linux ABI, e.g. aarch64, riscv64.  */
53   if (vers == _STAT_VER_KERNEL)
54     return INLINE_SYSCALL_CALL (newfstatat, AT_FDCWD, name, buf, 0);
55 # else
56   /* New 32-bit kABIs with only 64-bit time_t support, e.g. arc, riscv32.  */
57   if (vers == _STAT_VER_KERNEL)
58     {
59       struct statx tmp;
60       int r = INLINE_SYSCALL_CALL (statx, AT_FDCWD, name, AT_NO_AUTOMOUNT,
61 				   STATX_BASIC_STATS, &tmp);
62       if (r == 0)
63 	__cp_stat64_statx (buf, &tmp);
64       return r;
65      }
66 # endif
67 #else
68 # if STAT_IS_KERNEL_STAT
69   /* New kABIs which uses generic pre 64-bit time Linux ABI,
70      e.g. csky, nios2  */
71   if (vers == _STAT_VER_KERNEL)
72     return INLINE_SYSCALL_CALL (fstatat64, AT_FDCWD, name, buf, 0);
73 # else
74   /* Old kABIs with old non-LFS support, e.g. arm, i386, hppa, m68k,
75      microblaze, s390, sh, mips32, powerpc32, and sparc32.  */
76   return INLINE_SYSCALL_CALL (stat64, name, buf);
77 # endif /* STAT_IS_KERNEL_STAT  */
78 #endif /* XSTAT_IS_XSTAT64  */
79 
80   return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
81 }
82 
83 #if XSTAT_IS_XSTAT64
84 strong_alias (___xstat64, __xstat)
85 #endif
86 
87 #if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2)
88 versioned_symbol (libc, ___xstat64, __xstat64, GLIBC_2_2);
89 strong_alias (___xstat64, __old__xstat64)
90 compat_symbol (libc, __old__xstat64, __xstat64, GLIBC_2_1);
91 #else
92 strong_alias (___xstat64, __xstat64)
93 #endif
94 
95 
96 #endif /* LIB_COMPAT  */
97