Fix logic bug introduced on 2007-05-06.
[gnulib.git] / lib / sys_stat_.h
1 /* Provide a more complete sys/stat header file.
2    Copyright (C) 2006, 2007 Free Software Foundation, Inc.
3
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2, or (at your option)
7    any later version.
8
9    This program 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
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software Foundation,
16    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
17
18 /* Written by Eric Blake, Paul Eggert, and Jim Meyering.  */
19
20 #ifndef _GL_SYS_STAT_H
21 #define _GL_SYS_STAT_H
22
23 /* This file is supposed to be used on platforms where <sys/stat.h> is
24    incomplete.  It is intended to provide definitions and prototypes
25    needed by an application.  Start with what the system provides.  */
26
27 #if @HAVE_INCLUDE_NEXT@
28 # include_next <sys/stat.h>
29 #else
30 # include @ABSOLUTE_SYS_STAT_H@
31 #endif
32
33 #ifndef S_IFMT
34 # define S_IFMT 0170000
35 #endif
36
37 #if STAT_MACROS_BROKEN
38 # undef S_ISBLK
39 # undef S_ISCHR
40 # undef S_ISDIR
41 # undef S_ISFIFO
42 # undef S_ISLNK
43 # undef S_ISNAM
44 # undef S_ISMPB
45 # undef S_ISMPC
46 # undef S_ISNWK
47 # undef S_ISREG
48 # undef S_ISSOCK
49 #endif
50
51 #ifndef S_ISBLK
52 # ifdef S_IFBLK
53 #  define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
54 # else
55 #  define S_ISBLK(m) 0
56 # endif
57 #endif
58
59 #ifndef S_ISCHR
60 # ifdef S_IFCHR
61 #  define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
62 # else
63 #  define S_ISCHR(m) 0
64 # endif
65 #endif
66
67 #ifndef S_ISDIR
68 # ifdef S_IFDIR
69 #  define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
70 # else
71 #  define S_ISDIR(m) 0
72 # endif
73 #endif
74
75 #ifndef S_ISDOOR /* Solaris 2.5 and up */
76 # define S_ISDOOR(m) 0
77 #endif
78
79 #ifndef S_ISFIFO
80 # ifdef S_IFIFO
81 #  define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
82 # else
83 #  define S_ISFIFO(m) 0
84 # endif
85 #endif
86
87 #ifndef S_ISLNK
88 # ifdef S_IFLNK
89 #  define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
90 # else
91 #  define S_ISLNK(m) 0
92 # endif
93 #endif
94
95 #ifndef S_ISMPB /* V7 */
96 # ifdef S_IFMPB
97 #  define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
98 #  define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
99 # else
100 #  define S_ISMPB(m) 0
101 #  define S_ISMPC(m) 0
102 # endif
103 #endif
104
105 #ifndef S_ISNAM /* 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
113 #ifndef S_ISNWK /* HP/UX */
114 # ifdef S_IFNWK
115 #  define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
116 # else
117 #  define S_ISNWK(m) 0
118 # endif
119 #endif
120
121 #ifndef S_ISPORT /* Solaris 10 and up */
122 # define S_ISPORT(m) 0
123 #endif
124
125 #ifndef S_ISREG
126 # ifdef S_IFREG
127 #  define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
128 # else
129 #  define S_ISREG(m) 0
130 # endif
131 #endif
132
133 #ifndef S_ISSOCK
134 # ifdef S_IFSOCK
135 #  define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
136 # else
137 #  define S_ISSOCK(m) 0
138 # endif
139 #endif
140
141
142 #ifndef S_TYPEISMQ
143 # define S_TYPEISMQ(p) 0
144 #endif
145
146 #ifndef S_TYPEISTMO
147 # define S_TYPEISTMO(p) 0
148 #endif
149
150
151 #ifndef S_TYPEISSEM
152 # ifdef S_INSEM
153 #  define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
154 # else
155 #  define S_TYPEISSEM(p) 0
156 # endif
157 #endif
158
159 #ifndef S_TYPEISSHM
160 # ifdef S_INSHD
161 #  define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
162 # else
163 #  define S_TYPEISSHM(p) 0
164 # endif
165 #endif
166
167 /* high performance ("contiguous data") */
168 #ifndef S_ISCTG
169 # define S_ISCTG(p) 0
170 #endif
171
172 /* Cray DMF (data migration facility): off line, with data  */
173 #ifndef S_ISOFD
174 # define S_ISOFD(p) 0
175 #endif
176
177 /* Cray DMF (data migration facility): off line, with no data  */
178 #ifndef S_ISOFL
179 # define S_ISOFL(p) 0
180 #endif
181
182 /* 4.4BSD whiteout */
183 #ifndef S_ISWHT
184 # define S_ISWHT(m) 0
185 #endif
186
187 /* If any of the following are undefined,
188    define them to their de facto standard values.  */
189 #if !S_ISUID
190 # define S_ISUID 04000
191 #endif
192 #if !S_ISGID
193 # define S_ISGID 02000
194 #endif
195
196 /* S_ISVTX is a common extension to POSIX.  */
197 #ifndef S_ISVTX
198 # define S_ISVTX 01000
199 #endif
200
201 #if !S_IRUSR && S_IREAD
202 # define S_IRUSR S_IREAD
203 #endif
204 #if !S_IRUSR
205 # define S_IRUSR 00400
206 #endif
207 #if !S_IRGRP
208 # define S_IRGRP (S_IRUSR >> 3)
209 #endif
210 #if !S_IROTH
211 # define S_IROTH (S_IRUSR >> 6)
212 #endif
213
214 #if !S_IWUSR && S_IWRITE
215 # define S_IWUSR S_IWRITE
216 #endif
217 #if !S_IWUSR
218 # define S_IWUSR 00200
219 #endif
220 #if !S_IWGRP
221 # define S_IWGRP (S_IWUSR >> 3)
222 #endif
223 #if !S_IWOTH
224 # define S_IWOTH (S_IWUSR >> 6)
225 #endif
226
227 #if !S_IXUSR && S_IEXEC
228 # define S_IXUSR S_IEXEC
229 #endif
230 #if !S_IXUSR
231 # define S_IXUSR 00100
232 #endif
233 #if !S_IXGRP
234 # define S_IXGRP (S_IXUSR >> 3)
235 #endif
236 #if !S_IXOTH
237 # define S_IXOTH (S_IXUSR >> 6)
238 #endif
239
240 #if !S_IRWXU
241 # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
242 #endif
243 #if !S_IRWXG
244 # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
245 #endif
246 #if !S_IRWXO
247 # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
248 #endif
249
250 /* S_IXUGO is a common extension to POSIX.  */
251 #if !S_IXUGO
252 # define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
253 #endif
254
255 #ifndef S_IRWXUGO
256 # define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
257 #endif
258
259 /* mingw does not support symlinks, therefore it does not have lstat.  But
260    without links, stat does just fine.  */
261 #if ! @HAVE_LSTAT@
262 # define lstat stat
263 #endif
264
265 /* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
266    Additionally, it declares _mkdir (and depending on compile flags, an
267    alias mkdir), only in the nonstandard io.h.  */
268 #if ! @HAVE_DECL_MKDIR@ && @HAVE_IO_H@
269 # include <io.h>
270
271 static inline int
272 rpl_mkdir (char const *name, mode_t mode)
273 {
274   return _mkdir (name);
275 }
276
277 # define mkdir rpl_mkdir
278 #endif
279
280 #endif /* _GL_SYS_STAT_H */