1 /* Convert between `struct stat' format, and `struct stat64' format.
2    Copyright (C) 2000-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 #include <errno.h>
20 #include <sys/stat.h>
21 
22 static inline int
stat64_conv(struct stat * buf,const struct stat64 * buf64)23 stat64_conv (struct stat *buf, const struct stat64 *buf64)
24 {
25   if (sizeof *buf == sizeof *buf64
26       && sizeof buf->st_ino == sizeof buf64->st_ino
27       && sizeof buf->st_size == sizeof buf64->st_size
28       && sizeof buf->st_blocks == sizeof buf64->st_blocks)
29     {
30       *buf = *(struct stat *) buf64;
31       return 0;
32     }
33 
34   buf->st_fstype = buf64->st_fstype;
35   buf->st_fsid = buf64->st_fsid;
36   buf->st_ino = buf64->st_ino;
37   buf->st_gen = buf64->st_gen;
38   buf->st_rdev = buf64->st_rdev;
39   buf->st_mode = buf64->st_mode;
40   buf->st_nlink = buf64->st_nlink;
41   buf->st_uid = buf64->st_uid;
42   buf->st_gid = buf64->st_gid;
43   buf->st_size = buf64->st_size;
44   buf->st_atim = buf64->st_atim;
45   buf->st_mtim = buf64->st_mtim;
46   buf->st_ctim = buf64->st_ctim;
47   buf->st_blksize = buf64->st_blksize;
48   buf->st_blocks = buf64->st_blocks;
49   buf->st_author = buf64->st_author;
50   buf->st_flags = buf64->st_flags;
51 
52   if ((sizeof buf->st_ino != sizeof buf64->st_ino
53        && buf->st_ino != buf64->st_ino)
54       || (sizeof buf->st_size != sizeof buf64->st_size
55 	  && buf->st_size != buf64->st_size)
56       || (sizeof buf->st_blocks != sizeof buf64->st_blocks
57 	  && buf->st_blocks != buf64->st_blocks))
58     {
59       __set_errno (EOVERFLOW);
60       return -1;
61     }
62 
63   return 0;
64 }
65