Replace FSF snail mail address with URLs.
[glibc.git] / sysdeps / unix / bsd / bsdstat.h
blob635bbad1b2dc525c1f6f3cf6d4c4f39453be762d
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, see
16 <http://www.gnu.org/licenses/>. */
18 #include <errno.h>
19 #include <stddef.h>
20 #include <sys/types.h>
22 /* This will make it not define major, minor, makedev, and S_IF*. */
23 #undef __USE_BSD
24 #undef __USE_MISC
25 #include <sys/stat.h>
27 #undef stat
28 #undef fstat
30 #undef S_IRWXU
31 #undef S_IRUSR
32 #undef S_IWUSR
33 #undef S_IXUSR
34 #undef S_IRWXG
35 #undef S_IRGRP
36 #undef S_IWGRP
37 #undef S_IXGRP
38 #undef S_IRWXO
39 #undef S_IROTH
40 #undef S_IWOTH
41 #undef S_IXOTH
42 #undef S_ISBLK
43 #undef S_ISCHR
44 #undef S_ISDIR
45 #undef S_ISFIFO
46 #undef S_ISREG
47 #undef S_ISUID
48 #undef S_ISGID
49 #define stat system_stat
50 #define fstat system_fstat
51 #define KERNEL /* Try to avoid misc decls. */
52 #include "/usr/include/sys/stat.h"
53 #undef KERNEL
54 #undef stat
55 #undef fstat
57 #define member_same(statbufp, sysbufp, member) \
58 (offsetof(struct __stat, member) == offsetof(struct system_stat, member) && \
59 sizeof((statbufp)->member) == sizeof((sysbufp)->member))
60 #define need_stat_mapping(statbufp, sysbufp) \
61 (!(member_same(statbufp, sysbufp, st_dev) && \
62 member_same(statbufp, sysbufp, st_ino) && \
63 member_same(statbufp, sysbufp, st_mode) && \
64 member_same(statbufp, sysbufp, st_nlink) && \
65 member_same(statbufp, sysbufp, st_uid) && \
66 member_same(statbufp, sysbufp, st_gid) && \
67 member_same(statbufp, sysbufp, st_rdev) && \
68 member_same(statbufp, sysbufp, st_size) && \
69 member_same(statbufp, sysbufp, st_atime) && \
70 member_same(statbufp, sysbufp, st_mtime) && \
71 member_same(statbufp, sysbufp, st_ctime) && \
72 member_same(statbufp, sysbufp, st_blksize) && \
73 member_same(statbufp, sysbufp, st_blocks)))
75 /* Map a system `struct stat' to our `struct stat'. */
76 #ifdef __GNUC__
77 inline
78 #endif
79 static int
80 mapstat (sysbuf, statbuf)
81 const struct system_stat *sysbuf;
82 struct __stat *buf;
84 if (buf == NULL)
86 errno = EINVAL;
87 return -1;
90 if (!need_stat_mapping(buf, sysbuf))
91 /* Hopefully this will be optimized out. */
92 *buf = *(struct __stat *) sysbuf;
93 else
95 buf->st_dev = (dev_t) sysbuf->st_dev;
96 buf->st_ino = (ino_t) sysbuf->st_ino;
97 buf->st_mode = (mode_t) sysbuf->st_mode;
98 buf->st_nlink = (nlink_t) sysbuf->st_nlink;
99 buf->st_uid = (uid_t) sysbuf->st_uid;
100 buf->st_gid = (gid_t) sysbuf->st_gid;
101 buf->st_rdev = (dev_t) sysbuf->st_rdev;
102 buf->st_size = (size_t) sysbuf->st_size;
103 buf->st_atime = (time_t) sysbuf->st_atime;
104 buf->st_mtime = (time_t) sysbuf->st_mtime;
105 buf->st_ctime = (time_t) sysbuf->st_ctime;
106 buf->st_blksize = (size_t) sysbuf->st_blksize;
107 buf->st_blocks = (size_t) sysbuf->st_blocks;
110 return 0;