1/* Struct stat/stat64 to stat/stat64 conversion for Linux.
2 Copyright (C) 2020-2024 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 <stat_t64_cp.h>
20#include <string.h>
21#include <errno.h>
22#include <time.h>
23
24#if __TIMESIZE != 64
25int
26__cp_stat64_t64_stat64 (const struct __stat64_t64 *st64_t64,
27 struct stat64 *st64)
28{
29 if (! in_time_t_range (st64_t64->st_atim.tv_sec)
30 || ! in_time_t_range (st64_t64->st_mtim.tv_sec)
31 || ! in_time_t_range (st64_t64->st_ctim.tv_sec))
32 {
33 __set_errno (EOVERFLOW);
34 return -1;
35 }
36
37 /* Clear both pad and reserved fields. */
38 memset (st64, 0, sizeof (*st64));
39
40 st64->st_dev = st64_t64->st_dev,
41 st64->st_ino = st64_t64->st_ino;
42 st64->st_mode = st64_t64->st_mode;
43 st64->st_nlink = st64_t64->st_nlink;
44 st64->st_uid = st64_t64->st_uid;
45 st64->st_gid = st64_t64->st_gid;
46 st64->st_rdev = st64_t64->st_rdev;
47 st64->st_size = st64_t64->st_size;
48 st64->st_blksize = st64_t64->st_blksize;
49 st64->st_blocks = st64_t64->st_blocks;
50 st64->st_atim = valid_timespec64_to_timespec (st64_t64->st_atim);
51 st64->st_mtim = valid_timespec64_to_timespec (st64_t64->st_mtim);
52 st64->st_ctim = valid_timespec64_to_timespec (st64_t64->st_ctim);
53
54 return 0;
55}
56#endif
57

source code of glibc/sysdeps/unix/sysv/linux/stat_t64_cp.c