Back to index

glibc  2.9
bsdstat.h
Go to the documentation of this file.
00001 /* Copyright (C) 1991, 1997 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #include <errno.h>
00020 #include <stddef.h>
00021 #include <sys/types.h>
00022 
00023 /* This will make it not define major, minor, makedev, and S_IF*.  */
00024 #undef __USE_BSD
00025 #undef __USE_MISC
00026 #include <sys/stat.h>
00027 
00028 #undef stat
00029 #undef fstat
00030 
00031 #undef S_IRWXU
00032 #undef S_IRUSR
00033 #undef S_IWUSR
00034 #undef S_IXUSR
00035 #undef S_IRWXG
00036 #undef S_IRGRP
00037 #undef S_IWGRP
00038 #undef S_IXGRP
00039 #undef S_IRWXO
00040 #undef S_IROTH
00041 #undef S_IWOTH
00042 #undef S_IXOTH
00043 #undef S_ISBLK
00044 #undef S_ISCHR
00045 #undef S_ISDIR
00046 #undef S_ISFIFO
00047 #undef S_ISREG
00048 #undef S_ISUID
00049 #undef S_ISGID
00050 #define       stat   system_stat
00051 #define       fstat  system_fstat
00052 #define       KERNEL               /* Try to avoid misc decls.  */
00053 #include "/usr/include/sys/stat.h"
00054 #undef KERNEL
00055 #undef stat
00056 #undef fstat
00057 
00058 #define       member_same(statbufp, sysbufp, member) \
00059   (offsetof(struct __stat, member) == offsetof(struct system_stat, member) && \
00060    sizeof((statbufp)->member) == sizeof((sysbufp)->member))
00061 #define need_stat_mapping(statbufp, sysbufp)                                \
00062   (!(member_same(statbufp, sysbufp, st_dev) &&                              \
00063      member_same(statbufp, sysbufp, st_ino) &&                              \
00064      member_same(statbufp, sysbufp, st_mode) &&                             \
00065      member_same(statbufp, sysbufp, st_nlink) &&                     \
00066      member_same(statbufp, sysbufp, st_uid) &&                              \
00067      member_same(statbufp, sysbufp, st_gid) &&                              \
00068      member_same(statbufp, sysbufp, st_rdev) &&                             \
00069      member_same(statbufp, sysbufp, st_size) &&                             \
00070      member_same(statbufp, sysbufp, st_atime) &&                     \
00071      member_same(statbufp, sysbufp, st_mtime) &&                     \
00072      member_same(statbufp, sysbufp, st_ctime) &&                     \
00073      member_same(statbufp, sysbufp, st_blksize) &&                          \
00074      member_same(statbufp, sysbufp, st_blocks)))
00075 
00076 /* Map a system `struct stat' to our `struct stat'.  */
00077 #ifdef __GNUC__
00078 inline
00079 #endif
00080 static int
00081 mapstat (sysbuf, statbuf)
00082      const struct system_stat *sysbuf;
00083      struct __stat *buf;
00084 {
00085   if (buf == NULL)
00086     {
00087       errno = EINVAL;
00088       return -1;
00089     }
00090 
00091   if (!need_stat_mapping(buf, sysbuf))
00092     /* Hopefully this will be optimized out.  */
00093     *buf = *(struct __stat *) sysbuf;
00094   else
00095     {
00096       buf->st_dev = (dev_t) sysbuf->st_dev;
00097       buf->st_ino = (ino_t) sysbuf->st_ino;
00098       buf->st_mode = (mode_t) sysbuf->st_mode;
00099       buf->st_nlink = (nlink_t) sysbuf->st_nlink;
00100       buf->st_uid = (uid_t) sysbuf->st_uid;
00101       buf->st_gid = (gid_t) sysbuf->st_gid;
00102       buf->st_rdev = (dev_t) sysbuf->st_rdev;
00103       buf->st_size = (size_t) sysbuf->st_size;
00104       buf->st_atime = (time_t) sysbuf->st_atime;
00105       buf->st_mtime = (time_t) sysbuf->st_mtime;
00106       buf->st_ctime = (time_t) sysbuf->st_ctime;
00107       buf->st_blksize = (size_t) sysbuf->st_blksize;
00108       buf->st_blocks = (size_t) sysbuf->st_blocks;
00109     }
00110 
00111   return 0;
00112 }