Update.
[glibc.git] / sysdeps / unix / bsd / bsdstat.h
blob45b68b98c613ad7194556140920dd329e648e9c1
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. */
19 #include "ansidecl.h"
20 #include <errno.h>
21 #include <stddef.h>
22 #include <sys/types.h>
24 /* This will make it not define major, minor, makedev, and S_IF*. */
25 #undef __USE_BSD
26 #undef __USE_MISC
27 #include <sys/stat.h>
29 #undef stat
30 #undef fstat
32 #undef S_IRWXU
33 #undef S_IRUSR
34 #undef S_IWUSR
35 #undef S_IXUSR
36 #undef S_IRWXG
37 #undef S_IRGRP
38 #undef S_IWGRP
39 #undef S_IXGRP
40 #undef S_IRWXO
41 #undef S_IROTH
42 #undef S_IWOTH
43 #undef S_IXOTH
44 #undef S_ISBLK
45 #undef S_ISCHR
46 #undef S_ISDIR
47 #undef S_ISFIFO
48 #undef S_ISREG
49 #undef S_ISUID
50 #undef S_ISGID
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"
55 #undef KERNEL
56 #undef stat
57 #undef fstat
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'. */
78 #ifdef __GNUC__
79 inline
80 #endif
81 static int
82 DEFUN(mapstat, (sysbuf, statbuf),
83 CONST struct system_stat *sysbuf AND 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;