1 /* stat-related macros 2 3 Copyright (C) 1993, 1994, 2001, 2002, 2004 Free Software Foundation, Inc. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2, or (at your option) 8 any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software Foundation, 17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 18 19 /* Written by Paul Eggert and Jim Meyering. */ 20 21 #ifndef STAT_MACROS_H 22 # define STAT_MACROS_H 1 23 24 # if ! defined S_ISREG && ! defined S_IFREG 25 # error "you must include <sys/stat.h> before including this file" 26 # endif 27 28 # ifndef S_IFMT 29 # define S_IFMT 0170000 30 # endif 31 32 # if STAT_MACROS_BROKEN 33 # undef S_ISBLK 34 # undef S_ISCHR 35 # undef S_ISDIR 36 # undef S_ISDOOR 37 # undef S_ISFIFO 38 # undef S_ISLNK 39 # undef S_ISNAM 40 # undef S_ISMPB 41 # undef S_ISMPC 42 # undef S_ISNWK 43 # undef S_ISREG 44 # undef S_ISSOCK 45 # endif 46 47 48 # ifndef S_ISBLK 49 # ifdef S_IFBLK 50 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) 51 # else 52 # define S_ISBLK(m) 0 53 # endif 54 # endif 55 56 # ifndef S_ISCHR 57 # ifdef S_IFCHR 58 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) 59 # else 60 # define S_ISCHR(m) 0 61 # endif 62 # endif 63 64 # ifndef S_ISDIR 65 # ifdef S_IFDIR 66 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) 67 # else 68 # define S_ISDIR(m) 0 69 # endif 70 # endif 71 72 # ifndef S_ISDOOR /* Solaris 2.5 and up */ 73 # ifdef S_IFDOOR 74 # define S_ISDOOR(m) (((m) & S_IFMT) == S_IFDOOR) 75 # else 76 # define S_ISDOOR(m) 0 77 # endif 78 # endif 79 80 # ifndef S_ISFIFO 81 # ifdef S_IFIFO 82 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) 83 # else 84 # define S_ISFIFO(m) 0 85 # endif 86 # endif 87 88 # ifndef S_ISLNK 89 # ifdef S_IFLNK 90 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) 91 # else 92 # define S_ISLNK(m) 0 93 # endif 94 # endif 95 96 # ifndef S_ISMPB /* V7 */ 97 # ifdef S_IFMPB 98 # define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB) 99 # define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC) 100 # else 101 # define S_ISMPB(m) 0 102 # define S_ISMPC(m) 0 103 # endif 104 # endif 105 106 # ifndef S_ISNAM /* Xenix */ 107 # ifdef S_IFNAM 108 # define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM) 109 # else 110 # define S_ISNAM(m) 0 111 # endif 112 # endif 113 114 # ifndef S_ISNWK /* HP/UX */ 115 # ifdef S_IFNWK 116 # define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK) 117 # else 118 # define S_ISNWK(m) 0 119 # endif 120 # endif 121 122 # ifndef S_ISREG 123 # ifdef S_IFREG 124 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) 125 # else 126 # define S_ISREG(m) 0 127 # endif 128 # endif 129 130 # ifndef S_ISSOCK 131 # ifdef S_IFSOCK 132 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) 133 # else 134 # define S_ISSOCK(m) 0 135 # endif 136 # endif 137 138 139 # ifndef S_TYPEISMQ 140 # define S_TYPEISMQ(p) 0 141 # endif 142 143 # ifndef S_TYPEISTMO 144 # define S_TYPEISTMO(p) 0 145 # endif 146 147 148 # ifndef S_TYPEISSEM 149 # ifdef S_INSEM 150 # define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM) 151 # else 152 # define S_TYPEISSEM(p) 0 153 # endif 154 # endif 155 156 # ifndef S_TYPEISSHM 157 # ifdef S_INSHD 158 # define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD) 159 # else 160 # define S_TYPEISSHM(p) 0 161 # endif 162 # endif 163 164 /* contiguous */ 165 # ifndef S_ISCTG 166 # define S_ISCTG(p) 0 167 # endif 168 169 /* Cray DMF (data migration facility): off line, with data */ 170 # ifndef S_ISOFD 171 # define S_ISOFD(p) 0 172 # endif 173 174 /* Cray DMF (data migration facility): off line, with no data */ 175 # ifndef S_ISOFL 176 # define S_ISOFL(p) 0 177 # endif 178 179 /* If any of the following are undefined, 180 define them to their de facto standard values. */ 181 # if !S_ISUID 182 # define S_ISUID 04000 183 # endif 184 # if !S_ISGID 185 # define S_ISGID 02000 186 # endif 187 188 /* S_ISVTX is a common extension to POSIX. */ 189 # ifndef S_ISVTX 190 # define S_ISVTX 01000 191 # endif 192 193 # if !S_IRUSR && S_IREAD 194 # define S_IRUSR S_IREAD 195 # endif 196 # if !S_IRUSR 197 # define S_IRUSR 00400 198 # endif 199 # if !S_IRGRP 200 # define S_IRGRP (S_IRUSR >> 3) 201 # endif 202 # if !S_IROTH 203 # define S_IROTH (S_IRUSR >> 6) 204 # endif 205 206 # if !S_IWUSR && S_IWRITE 207 # define S_IWUSR S_IWRITE 208 # endif 209 # if !S_IWUSR 210 # define S_IWUSR 00200 211 # endif 212 # if !S_IWGRP 213 # define S_IWGRP (S_IWUSR >> 3) 214 # endif 215 # if !S_IWOTH 216 # define S_IWOTH (S_IWUSR >> 6) 217 # endif 218 219 # if !S_IXUSR && S_IEXEC 220 # define S_IXUSR S_IEXEC 221 # endif 222 # if !S_IXUSR 223 # define S_IXUSR 00100 224 # endif 225 # if !S_IXGRP 226 # define S_IXGRP (S_IXUSR >> 3) 227 # endif 228 # if !S_IXOTH 229 # define S_IXOTH (S_IXUSR >> 6) 230 # endif 231 232 # if !S_IRWXU 233 # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR) 234 # endif 235 # if !S_IRWXG 236 # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP) 237 # endif 238 # if !S_IRWXO 239 # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH) 240 # endif 241 242 /* S_IXUGO is a common extension to POSIX. */ 243 # if !S_IXUGO 244 # define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH) 245 # endif 246 247 # ifndef S_IRWXUGO 248 # define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO) 249 # endif 250 251 /* All the mode bits that can be affected by chmod. */ 252 # define CHMOD_MODE_BITS \ 253 (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) 254 255 #endif /* STAT_MACROS_H */ 256