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. |
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 | #include <sys/stat.h> |
20 | #include <kernel_stat.h> |
21 | #include <sysdep.h> |
22 | |
23 | #if !XSTAT_IS_XSTAT64 |
24 | # include <kstat_cp.h> |
25 | |
26 | int |
27 | __fstatat (int fd, const char *file, struct stat *buf, int flag) |
28 | { |
29 | struct __stat64_t64 st64; |
30 | int r = __fstatat64_time64 (fd, file, &st64, flag); |
31 | if (r == 0) |
32 | { |
33 | if (! in_ino_t_range (st64.st_ino) |
34 | || ! in_off_t_range (st64.st_size) |
35 | || ! in_blkcnt_t_range (st64.st_blocks) |
36 | || ! in_time_t_range (st64.st_atim.tv_sec) |
37 | || ! in_time_t_range (st64.st_mtim.tv_sec) |
38 | || ! in_time_t_range (st64.st_ctim.tv_sec)) |
39 | return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW); |
40 | |
41 | /* Clear internal pad and reserved fields. */ |
42 | memset (buf, 0, sizeof (*buf)); |
43 | |
44 | buf->st_dev = st64.st_dev; |
45 | buf->st_ino = st64.st_ino; |
46 | buf->st_mode = st64.st_mode; |
47 | buf->st_nlink = st64.st_nlink; |
48 | buf->st_uid = st64.st_uid; |
49 | buf->st_gid = st64.st_gid; |
50 | buf->st_rdev = st64.st_rdev; |
51 | buf->st_size = st64.st_size; |
52 | buf->st_blksize = st64.st_blksize; |
53 | buf->st_blocks = st64.st_blocks; |
54 | buf->st_atim = valid_timespec64_to_timespec (st64.st_atim); |
55 | buf->st_mtim = valid_timespec64_to_timespec (st64.st_mtim); |
56 | buf->st_ctim = valid_timespec64_to_timespec (st64.st_ctim); |
57 | } |
58 | return r; |
59 | } |
60 | |
61 | weak_alias (__fstatat, fstatat) |
62 | #endif |
63 | |