1 /* Copyright (C) 1991, 1997 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 #include <sys/types.h>
23 /* This will make it not define major, minor, makedev, and S_IF*. */
50 #define stat system_stat
51 #define fstat system_fstat
52 #define KERNEL /* Try to avoid misc decls. */
53 #include "/usr/include/sys/stat.h"
58 #define member_same(statbufp, sysbufp, member) \
59 (offsetof(struct __stat, member) == offsetof(struct system_stat, member) && \
60 sizeof((statbufp)->member) == sizeof((sysbufp)->member))
61 #define need_stat_mapping(statbufp, sysbufp) \
62 (!(member_same(statbufp, sysbufp, st_dev) && \
63 member_same(statbufp, sysbufp, st_ino) && \
64 member_same(statbufp, sysbufp, st_mode) && \
65 member_same(statbufp, sysbufp, st_nlink) && \
66 member_same(statbufp, sysbufp, st_uid) && \
67 member_same(statbufp, sysbufp, st_gid) && \
68 member_same(statbufp, sysbufp, st_rdev) && \
69 member_same(statbufp, sysbufp, st_size) && \
70 member_same(statbufp, sysbufp, st_atime) && \
71 member_same(statbufp, sysbufp, st_mtime) && \
72 member_same(statbufp, sysbufp, st_ctime) && \
73 member_same(statbufp, sysbufp, st_blksize) && \
74 member_same(statbufp, sysbufp, st_blocks)))
76 /* Map a system `struct stat' to our `struct stat'. */
81 mapstat (sysbuf
, statbuf
)
82 const struct system_stat
*sysbuf
;
91 if (!need_stat_mapping(buf
, sysbuf
))
92 /* Hopefully this will be optimized out. */
93 *buf
= *(struct __stat
*) sysbuf
;
96 buf
->st_dev
= (dev_t
) sysbuf
->st_dev
;
97 buf
->st_ino
= (ino_t
) sysbuf
->st_ino
;
98 buf
->st_mode
= (mode_t
) sysbuf
->st_mode
;
99 buf
->st_nlink
= (nlink_t
) sysbuf
->st_nlink
;
100 buf
->st_uid
= (uid_t
) sysbuf
->st_uid
;
101 buf
->st_gid
= (gid_t
) sysbuf
->st_gid
;
102 buf
->st_rdev
= (dev_t
) sysbuf
->st_rdev
;
103 buf
->st_size
= (size_t) sysbuf
->st_size
;
104 buf
->st_atime
= (time_t) sysbuf
->st_atime
;
105 buf
->st_mtime
= (time_t) sysbuf
->st_mtime
;
106 buf
->st_ctime
= (time_t) sysbuf
->st_ctime
;
107 buf
->st_blksize
= (size_t) sysbuf
->st_blksize
;
108 buf
->st_blocks
= (size_t) sysbuf
->st_blocks
;