1 /* Copyright (C) 1991 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 Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 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 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
22 #include <sys/types.h>
24 /* This will make it not define major, minor, makedev, and S_IF*. */
51 #define stat system_stat
52 #define fstat system_fstat
53 #define KERNEL /* Try to avoid misc decls. */
54 #include "/usr/include/sys/stat.h"
59 #define member_same(statbufp, sysbufp, member) \
60 (offsetof(struct __stat, member) == offsetof(struct system_stat, member) && \
61 sizeof((statbufp)->member) == sizeof((sysbufp)->member))
62 #define need_stat_mapping(statbufp, sysbufp) \
63 (!(member_same(statbufp, sysbufp, st_dev) && \
64 member_same(statbufp, sysbufp, st_ino) && \
65 member_same(statbufp, sysbufp, st_mode) && \
66 member_same(statbufp, sysbufp, st_nlink) && \
67 member_same(statbufp, sysbufp, st_uid) && \
68 member_same(statbufp, sysbufp, st_gid) && \
69 member_same(statbufp, sysbufp, st_rdev) && \
70 member_same(statbufp, sysbufp, st_size) && \
71 member_same(statbufp, sysbufp, st_atime) && \
72 member_same(statbufp, sysbufp, st_mtime) && \
73 member_same(statbufp, sysbufp, st_ctime) && \
74 member_same(statbufp, sysbufp, st_blksize) && \
75 member_same(statbufp, sysbufp, st_blocks)))
77 /* Map a system `struct stat' to our `struct stat'. */
82 DEFUN(mapstat
, (sysbuf
, statbuf
),
83 CONST
struct system_stat
*sysbuf AND
struct __stat
*buf
)
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
;