Imported Upstream version 1.1.11
[platform/upstream/cdrkit.git] / include / statdefs.h
1 /*
2  * This file has been modified for the cdrkit suite.
3  *
4  * The behaviour and appearence of the program code below can differ to a major
5  * extent from the version distributed by the original author(s).
6  *
7  * For details, see Changelog file distributed with the cdrkit package. If you
8  * received this file from another source then ask the distributing person for
9  * a log of modifications.
10  *
11  */
12
13 /* @(#)statdefs.h       1.9 03/06/15 Copyright 1998 J. Schilling */
14 /*
15  *      Definitions for stat() file mode
16  *
17  *      Copyright (c) 1998 J. Schilling
18  */
19 /*
20  * This program is free software; you can redistribute it and/or modify
21  * it under the terms of the GNU General Public License version 2
22  * as published by the Free Software Foundation.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License along with
30  * this program; see the file COPYING.  If not, write to the Free Software
31  * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32  */
33
34 #ifndef _STATDEFS_H
35 #define _STATDEFS_H
36
37 #ifndef _MCONFIG_H
38 #include <mconfig.h>
39 #endif
40
41 #ifndef _INCL_SYS_TYPES_H
42 #include <sys/types.h>          /* Needed for sys/stat.h                */
43 #define _INCL_SYS_TYPES_H
44 #endif
45 #ifndef _INCL_SYS_STAT_H
46 #include <sys/stat.h>           /* For S_IS* and S_IF*                  */
47 #define _INCL_SYS_STAT_H
48 #endif
49
50 /*
51  * Apollo Domain/OS has a broken sys/stat.h that defines
52  * S_IFIFO == S_IFSOCK and creates trouble if the constants
53  * are used as case labels.
54  */
55 #if S_IFIFO == S_IFSOCK
56 #       undef   S_IFSOCK
57 #endif
58
59 #ifdef  STAT_MACROS_BROKEN
60 #undef  S_ISFIFO                        /* Named pipe           */
61 #undef  S_ISCHR                         /* Character special    */
62 #undef  S_ISMPC                         /* UNUSED multiplexed c */
63 #undef  S_ISDIR                         /* Directory            */
64 #undef  S_ISNAM                         /* Named file (XENIX)   */
65 #undef  S_ISBLK                         /* Block special        */
66 #undef  S_ISMPB                         /* UNUSED multiplexed b */
67 #undef  S_ISREG                         /* Regular file         */
68 #undef  S_ISCNT                         /* Contiguous file      */
69 #undef  S_ISLNK                         /* Symbolic link        */
70 #undef  S_ISSHAD                        /* Solaris shadow inode */
71 #undef  S_ISSOCK                        /* UNIX domain socket   */
72 #undef  S_ISDOOR                        /* Solaris DOOR         */
73 #undef  S_ISWHT                         /* BSD whiteout         */
74 #undef  S_ISEVC                         /* UNOS eventcount      */
75 #endif
76
77 #ifndef S_ISFIFO                        /* 1 Named pipe         */
78 #       ifdef   S_IFIFO
79 #               define  S_ISFIFO(m)     (((m) & S_IFMT) == S_IFIFO)
80 #       else
81 #               define  S_ISFIFO(m)     (0)
82 #       endif
83 #endif
84 #ifndef S_ISCHR                         /* 2 Character special  */
85 #       ifdef   S_IFCHR
86 #               define  S_ISCHR(m)      (((m) & S_IFMT) == S_IFCHR)
87 #       else
88 #               define  S_ISCHR(m)      (0)
89 #       endif
90 #endif
91 #ifndef S_ISMPC                         /* 3 UNUSED multiplexed char    */
92 #       ifdef   S_IFMPC
93 #               define  S_ISMPC(m)      (((m) & S_IFMT) == S_IFMPC)
94 #       else
95 #               define  S_ISMPC(m)      (0)
96 #       endif
97 #endif
98 #ifndef S_ISDIR                         /* 4 Directory                  */
99 #       ifdef   S_IFDIR
100 #               define  S_ISDIR(m)      (((m) & S_IFMT) == S_IFDIR)
101 #       else
102 #               define  S_ISDIR(m)      (0)
103 #       endif
104 #endif
105 #ifndef S_ISNAM                         /* 5 Named file (XENIX)         */
106 #       ifdef   S_IFNAM
107 #               define  S_ISNAM(m)      (((m) & S_IFMT) == S_IFNAM)
108 #       else
109 #               define  S_ISNAM(m)      (0)
110 #       endif
111 #endif
112 #ifndef S_ISBLK                         /* 6 Block special              */
113 #       ifdef   S_IFBLK
114 #               define  S_ISBLK(m)      (((m) & S_IFMT) == S_IFBLK)
115 #       else
116 #               define  S_ISBLK(m)      (0)
117 #       endif
118 #endif
119 #ifndef S_ISMPB                         /* 7 UNUSED multiplexed block   */
120 #       ifdef   S_IFMPB
121 #               define  S_ISMPB(m)      (((m) & S_IFMT) == S_IFMPB)
122 #       else
123 #               define  S_ISMPB(m)      (0)
124 #       endif
125 #endif
126 #ifndef S_ISREG                         /* 8 Regular file               */
127 #       ifdef   S_IFREG
128 #               define  S_ISREG(m)      (((m) & S_IFMT) == S_IFREG)
129 #       else
130 #               define  S_ISREG(m)      (0)
131 #       endif
132 #endif
133 #ifndef S_ISCNT                         /* 9 Contiguous file            */
134 #       ifdef   S_IFCNT
135 #               define  S_ISCNT(m)      (((m) & S_IFMT) == S_IFCNT)
136 #       else
137 #               define  S_ISCNT(m)      (0)
138 #       endif
139 #endif
140 #ifndef S_ISLNK                         /* 10 Symbolic link             */
141 #       ifdef   S_IFLNK
142 #               define  S_ISLNK(m)      (((m) & S_IFMT) == S_IFLNK)
143 #       else
144 #               define  S_ISLNK(m)      (0)
145 #       endif
146 #endif
147 #ifndef S_ISSHAD                        /* 11 Solaris shadow inode      */
148 #       ifdef   S_IFSHAD
149 #               define  S_ISSHAD(m)     (((m) & S_IFMT) == S_IFSHAD)
150 #       else
151 #               define  S_ISSHAD(m)     (0)
152 #       endif
153 #endif
154 #ifndef S_ISSOCK                        /* 12 UNIX domain socket        */
155 #       ifdef   S_IFSOCK
156 #               define  S_ISSOCK(m)     (((m) & S_IFMT) == S_IFSOCK)
157 #       else
158 #               define  S_ISSOCK(m)     (0)
159 #       endif
160 #endif
161 #ifndef S_ISDOOR                        /* 13 Solaris DOOR              */
162 #       ifdef   S_IFDOOR
163 #               define  S_ISDOOR(m)     (((m) & S_IFMT) == S_IFDOOR)
164 #       else
165 #               define  S_ISDOOR(m)     (0)
166 #       endif
167 #endif
168 #ifndef S_ISWHT                         /* 14 BSD whiteout              */
169 #       ifdef   S_IFWHT
170 #               define  S_ISWHT(m)      (((m) & S_IFMT) == S_ISWHT)
171 #       else
172 #               define  S_ISWHT(m)      (0)
173 #       endif
174 #endif
175 #ifndef S_IFEVC                         /* 15 UNOS eventcount           */
176 #       ifdef   S_IFEVC
177 #               define  S_ISEVC(m)      (((m) & S_IFMT) == S_IFEVC)
178 #       else
179 #               define  S_ISEVC(m)      (0)
180 #       endif
181 #endif
182
183 #ifndef S_TYPEISMQ
184 /*
185  * XXX ??? where is a definition of a message queue ???
186  */
187 #               define  S_TYPEISMQ(_stbuf)      (0)
188 #endif
189 #ifndef S_TYPEISSEM
190 #       ifdef   S_INSEM
191 #               define  S_TYPEISSEM(_stbuf)     (S_ISNAM((_stbuf)->st_mode) && (_stbuf)->st_rdev == S_INSEM)
192 #       else
193 #               define  S_TYPEISSEM(_stbuf)     (0)
194 #       endif
195 #endif
196 #ifndef S_TYPEISSHM
197 #       ifdef   S_INSHD
198 #               define  S_TYPEISSHM(_stbuf)     (S_ISNAM((_stbuf)->st_mode) && (_stbuf)->st_rdev == S_INSHD)
199 #       else
200 #               define  S_TYPEISSHM(_stbuf)     (0)
201 #       endif
202 #endif
203
204 /*
205  * Mode permission bits.
206  * UNIX V.7 has only    S_ISUID/S_ISGID/S_ISVTX and S_IREAD/S_IWRITE/S_IEXEC
207  */
208 #ifndef S_ISUID                 /* Set-user-ID on execution */
209 #define S_ISUID 0               /* If it is not defined, it is not supported */
210 #endif
211 #ifndef S_ISGID                 /* Set-group-ID on execution */
212 #define S_ISGID 0               /* If it is not defined, it is not supported */
213 #endif
214 #ifndef S_ISVTX                 /* On directories, restricted deletion flag */
215 #define S_ISVTX 0               /* If it is not defined, it is not supported */
216 #endif
217
218 #ifndef S_IRUSR                 /* Read permission, owner */
219 #ifdef  S_IREAD
220 #define S_IRUSR S_IREAD         /* Needed on old UNIX systems */
221 #else
222 #define S_IRUSR 0400
223 #endif
224 #endif
225 #ifndef S_IWUSR                 /* Write permission, owner */
226 #ifdef  S_IWRITE
227 #define S_IWUSR S_IWRITE        /* Needed on old UNIX systems */
228 #else
229 #define S_IWUSR 0200
230 #endif
231 #endif
232 #ifndef S_IXUSR                 /* Execute/search permission, owner */
233 #ifdef  S_IEXEC
234 #define S_IXUSR S_IEXEC         /* Needed on old UNIX systems */
235 #else
236 #define S_IXUSR 0100
237 #endif
238 #endif
239 #ifndef S_IRGRP                 /* Read permission, group */
240 #ifdef  S_IREAD
241 #define S_IRGRP (S_IREAD >> 3)  /* Needed on old UNIX systems */
242 #else
243 #define S_IRGRP 040
244 #endif
245 #endif
246 #ifndef S_IWGRP                 /* Write permission, group */
247 #ifdef  S_IWRITE
248 #define S_IWGRP (S_IWRITE >> 3) /* Needed on old UNIX systems */
249 #else
250 #define S_IWGRP 020
251 #endif
252 #endif
253 #ifndef S_IXGRP                 /* Execute/search permission, group */
254 #ifdef  S_IEXEC
255 #define S_IXGRP (S_IEXEC >> 3)  /* Needed on old UNIX systems */
256 #else
257 #define S_IXGRP 010
258 #endif
259 #endif
260 #ifndef S_IROTH                 /* Read permission, others */
261 #ifdef  S_IREAD
262 #define S_IROTH (S_IREAD >> 6)  /* Needed on old UNIX systems */
263 #else
264 #define S_IROTH 004
265 #endif
266 #endif
267 #ifndef S_IWOTH                 /* Write permission, others */
268 #ifdef  S_IWRITE
269 #define S_IWOTH (S_IWRITE >> 6) /* Needed on old UNIX systems */
270 #else
271 #define S_IWOTH 002
272 #endif
273 #endif
274 #ifndef S_IXOTH                 /* Execute/search permission, others */
275 #ifdef  S_IEXEC
276 #define S_IXOTH (S_IEXEC >> 6)  /* Needed on old UNIX systems */
277 #else
278 #define S_IXOTH 001
279 #endif
280 #endif
281
282 #ifndef S_IRWXU                 /* Read, write, execute/search by owner */
283 #define S_IRWXU (S_IRUSR|S_IWUSR|S_IXUSR)
284 #endif
285 #ifndef S_IRWXG                 /* Read, write, execute/search by group */
286 #define S_IRWXG (S_IRGRP|S_IWGRP|S_IXGRP)
287 #endif
288 #ifndef S_IRWXO                 /* Read, write, execute/search by others */
289 #define S_IRWXO (S_IROTH|S_IWOTH|S_IXOTH)
290 #endif
291
292 /*
293  * SCO UnixWare has st_atim.st__tim.tv_nsec but the st_atim.tv_nsec tests also
294  * succeeds. If we use st_atim.tv_nsec on UnixWare, we get a warning about
295  * illegal structure usage. For this reason, our code needs to have
296  * #ifdef HAVE_ST__TIM before #ifdef HAVE_ST_NSEC.
297  */
298 #if     defined(HAVE_ST_ATIMENSEC)
299
300 #define stat_ansecs(s)          ((s)->st_atimensec)
301 #define stat_mnsecs(s)          ((s)->st_mtimensec)
302 #define stat_cnsecs(s)          ((s)->st_ctimensec)
303
304 #define _FOUND_STAT_NSECS_
305 #endif
306
307 #if     defined(HAVE_ST_SPARE1) && !defined(_FOUND_STAT_NSECS_)
308
309 #define stat_ansecs(s)          ((s)->st_spare1 * 1000)
310 #define stat_mnsecs(s)          ((s)->st_spare2 * 1000)
311 #define stat_cnsecs(s)          ((s)->st_spare3 * 1000)
312
313 #define _FOUND_STAT_USECS_
314 #define _FOUND_STAT_NSECS_
315 #endif
316
317 #if     defined(HAVE_ST__TIM) && !defined(_FOUND_STAT_NSECS_)
318
319 #define stat_ansecs(s)          ((s)->st_atim.st__tim.tv_nsec)
320 #define stat_mnsecs(s)          ((s)->st_mtim.st__tim.tv_nsec)
321 #define stat_cnsecs(s)          ((s)->st_ctim.st__tim.tv_nsec)
322
323 #define _FOUND_STAT_NSECS_
324 #endif
325
326 #if     defined(HAVE_ST_NSEC) && !defined(_FOUND_STAT_NSECS_)
327
328 #define stat_ansecs(s)          ((s)->st_atim.tv_nsec)
329 #define stat_mnsecs(s)          ((s)->st_mtim.tv_nsec)
330 #define stat_cnsecs(s)          ((s)->st_ctim.tv_nsec)
331
332 #define _FOUND_STAT_NSECS_
333 #endif
334
335 #if     defined(HAVE_ST_ATIMESPEC) && !defined(_FOUND_STAT_NSECS_)
336
337 #define stat_ansecs(s)          ((s)->st_atimespec.tv_nsec)
338 #define stat_mnsecs(s)          ((s)->st_mtimespec.tv_nsec)
339 #define stat_cnsecs(s)          ((s)->st_ctimespec.tv_nsec)
340
341 #define _FOUND_STAT_NSECS_
342 #endif
343
344 #if     !defined(_FOUND_STAT_NSECS_)
345 #define stat_ansecs(s)          (0)
346 #define stat_mnsecs(s)          (0)
347 #define stat_cnsecs(s)          (0)
348 #endif
349
350 #endif  /* _STATDEFS_H */