2.9
[glibc/nacl-glibc.git] / sysdeps / unix / bsd / bsdstat.h
blobf1e38c0153227954fb524af3965717930dd9e81b
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
17 02111-1307 USA. */
19 #include <errno.h>
20 #include <stddef.h>
21 #include <sys/types.h>
23 /* This will make it not define major, minor, makedev, and S_IF*. */
24 #undef __USE_BSD
25 #undef __USE_MISC
26 #include <sys/stat.h>
28 #undef stat
29 #undef fstat
31 #undef S_IRWXU
32 #undef S_IRUSR
33 #undef S_IWUSR
34 #undef S_IXUSR
35 #undef S_IRWXG
36 #undef S_IRGRP
37 #undef S_IWGRP
38 #undef S_IXGRP
39 #undef S_IRWXO
40 #undef S_IROTH
41 #undef S_IWOTH
42 #undef S_IXOTH
43 #undef S_ISBLK
44 #undef S_ISCHR
45 #undef S_ISDIR
46 #undef S_ISFIFO
47 #undef S_ISREG
48 #undef S_ISUID
49 #undef S_ISGID
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"
54 #undef KERNEL
55 #undef stat
56 #undef fstat
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'. */
77 #ifdef __GNUC__
78 inline
79 #endif
80 static int
81 mapstat (sysbuf, statbuf)
82 const struct system_stat *sysbuf;
83 struct __stat *buf;
85 if (buf == NULL)
87 errno = EINVAL;
88 return -1;
91 if (!need_stat_mapping(buf, sysbuf))
92 /* Hopefully this will be optimized out. */
93 *buf = *(struct __stat *) sysbuf;
94 else
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;
111 return 0;