]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/fstatat64.c
1 /* Get file status. Linux version.
2 Copyright (C) 2020-2021 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
19 #define __fstatat __redirect___fstatat
20 #define fstatat __redirect_fstatat
24 #include <kernel_stat.h>
29 #include <stat_t64_cp.h>
32 __fstatat64_time64 (int fd
, const char *file
, struct __stat64_t64
*buf
,
37 #if (__WORDSIZE == 32 \
38 && (!defined __SYSCALL_WORDSIZE || __SYSCALL_WORDSIZE == 32))
39 /* 32-bit kABI with default 64-bit time_t, e.g. arc, riscv32. Also
40 64-bit time_t support is done through statx syscall. */
42 r
= INTERNAL_SYSCALL_CALL (statx
, fd
, file
, AT_NO_AUTOMOUNT
| flag
,
43 STATX_BASIC_STATS
, &tmp
);
46 __cp_stat64_t64_statx (buf
, &tmp
);
50 return INLINE_SYSCALL_ERROR_RETURN_VALUE (-r
);
54 # ifdef __NR_newfstatat
55 /* 64-bit kABI, e.g. aarch64, ia64, powerpc64*, s390x, riscv64, and
57 r
= INTERNAL_SYSCALL_CALL (newfstatat
, fd
, file
, buf
, flag
);
58 # elif defined __NR_fstatat64
59 # if STAT64_IS_KERNEL_STAT64
60 /* 64-bit kABI outlier, e.g. alpha */
61 r
= INTERNAL_SYSCALL_CALL (fstatat64
, fd
, file
, buf
, flag
);
63 /* 64-bit kABI outlier, e.g. sparc64. */
64 struct kernel_stat64 kst64
;
65 r
= INTERNAL_SYSCALL_CALL (fstatat64
, fd
, file
, &kst64
, flag
);
67 __cp_stat64_kstat64 (buf
, &kst64
);
71 # ifdef __NR_fstatat64
72 /* All kABIs with non-LFS support and with old 32-bit time_t support
73 e.g. arm, csky, i386, hppa, m68k, microblaze, nios2, sh, powerpc32,
76 r
= INTERNAL_SYSCALL_CALL (fstatat64
, fd
, file
, &st64
, flag
);
79 /* Clear both pad and reserved fields. */
80 memset (buf
, 0, sizeof (*buf
));
82 buf
->st_dev
= st64
.st_dev
,
83 buf
->st_ino
= st64
.st_ino
;
84 buf
->st_mode
= st64
.st_mode
;
85 buf
->st_nlink
= st64
.st_nlink
;
86 buf
->st_uid
= st64
.st_uid
;
87 buf
->st_gid
= st64
.st_gid
;
88 buf
->st_rdev
= st64
.st_rdev
;
89 buf
->st_size
= st64
.st_size
;
90 buf
->st_blksize
= st64
.st_blksize
;
91 buf
->st_blocks
= st64
.st_blocks
;
92 buf
->st_atim
= valid_timespec_to_timespec64 (st64
.st_atim
);
93 buf
->st_mtim
= valid_timespec_to_timespec64 (st64
.st_mtim
);
94 buf
->st_ctim
= valid_timespec_to_timespec64 (st64
.st_ctim
);
97 /* 64-bit kabi outlier, e.g. mips64 and mips64-n32. */
98 struct kernel_stat kst
;
99 r
= INTERNAL_SYSCALL_CALL (newfstatat
, fd
, file
, &kst
, flag
);
101 __cp_kstat_stat64_t64 (&kst
, buf
);
105 return INTERNAL_SYSCALL_ERROR_P (r
)
106 ? INLINE_SYSCALL_ERROR_RETURN_VALUE (-r
)
110 hidden_def (__fstatat64_time64
)
113 __fstatat64 (int fd
, const char *file
, struct stat64
*buf
, int flags
)
115 struct __stat64_t64 st_t64
;
116 return __fstatat64_time64 (fd
, file
, &st_t64
, flags
)
117 ?: __cp_stat64_t64_stat64 (&st_t64
, buf
);
124 hidden_def (__fstatat64
)
125 weak_alias (__fstatat64
, fstatat64
)
128 strong_alias (__fstatat64
, __fstatat
)
129 weak_alias (__fstatat64
, fstatat
)
130 strong_alias (__fstatat64
, __GI___fstatat
);