6226544762d5fcd7ee2f41c33218ab148dab4a5b
[gnulib.git] / lib / sys_stat.in.h
1 /* Provide a more complete sys/stat header file.
2    Copyright (C) 2006-2008 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 /* This file is supposed to be used on platforms where <sys/stat.h> is
21    incomplete.  It is intended to provide definitions and prototypes
22    needed by an application.  Start with what the system provides.  */
23
24 #ifndef _GL_SYS_STAT_H
25
26 #if __GNUC__ >= 3
27 @PRAGMA_SYSTEM_HEADER@
28 #endif
29
30 /* The include_next requires a split double-inclusion guard.  */
31 #@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
32
33 #ifndef _GL_SYS_STAT_H
34 #define _GL_SYS_STAT_H
35
36 /* Before doing "#define mkdir rpl_mkdir" below, we need to include all
37    headers that may declare mkdir().  */
38 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
39 # include <io.h>
40 #endif
41
42 #ifndef S_IFMT
43 # define S_IFMT 0170000
44 #endif
45
46 #if STAT_MACROS_BROKEN
47 # undef S_ISBLK
48 # undef S_ISCHR
49 # undef S_ISDIR
50 # undef S_ISFIFO
51 # undef S_ISLNK
52 # undef S_ISNAM
53 # undef S_ISMPB
54 # undef S_ISMPC
55 # undef S_ISNWK
56 # undef S_ISREG
57 # undef S_ISSOCK
58 #endif
59
60 #ifndef S_ISBLK
61 # ifdef S_IFBLK
62 #  define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
63 # else
64 #  define S_ISBLK(m) 0
65 # endif
66 #endif
67
68 #ifndef S_ISCHR
69 # ifdef S_IFCHR
70 #  define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
71 # else
72 #  define S_ISCHR(m) 0
73 # endif
74 #endif
75
76 #ifndef S_ISDIR
77 # ifdef S_IFDIR
78 #  define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
79 # else
80 #  define S_ISDIR(m) 0
81 # endif
82 #endif
83
84 #ifndef S_ISDOOR /* Solaris 2.5 and up */
85 # define S_ISDOOR(m) 0
86 #endif
87
88 #ifndef S_ISFIFO
89 # ifdef S_IFIFO
90 #  define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
91 # else
92 #  define S_ISFIFO(m) 0
93 # endif
94 #endif
95
96 #ifndef S_ISLNK
97 # ifdef S_IFLNK
98 #  define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
99 # else
100 #  define S_ISLNK(m) 0
101 # endif
102 #endif
103
104 #ifndef S_ISMPB /* V7 */
105 # ifdef S_IFMPB
106 #  define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
107 #  define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
108 # else
109 #  define S_ISMPB(m) 0
110 #  define S_ISMPC(m) 0
111 # endif
112 #endif
113
114 #ifndef S_ISNAM /* Xenix */
115 # ifdef S_IFNAM
116 #  define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
117 # else
118 #  define S_ISNAM(m) 0
119 # endif
120 #endif
121
122 #ifndef S_ISNWK /* HP/UX */
123 # ifdef S_IFNWK
124 #  define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
125 # else
126 #  define S_ISNWK(m) 0
127 # endif
128 #endif
129
130 #ifndef S_ISPORT /* Solaris 10 and up */
131 # define S_ISPORT(m) 0
132 #endif
133
134 #ifndef S_ISREG
135 # ifdef S_IFREG
136 #  define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
137 # else
138 #  define S_ISREG(m) 0
139 # endif
140 #endif
141
142 #ifndef S_ISSOCK
143 # ifdef S_IFSOCK
144 #  define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
145 # else
146 #  define S_ISSOCK(m) 0
147 # endif
148 #endif
149
150
151 #ifndef S_TYPEISMQ
152 # define S_TYPEISMQ(p) 0
153 #endif
154
155 #ifndef S_TYPEISTMO
156 # define S_TYPEISTMO(p) 0
157 #endif
158
159
160 #ifndef S_TYPEISSEM
161 # ifdef S_INSEM
162 #  define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
163 # else
164 #  define S_TYPEISSEM(p) 0
165 # endif
166 #endif
167
168 #ifndef S_TYPEISSHM
169 # ifdef S_INSHD
170 #  define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
171 # else
172 #  define S_TYPEISSHM(p) 0
173 # endif
174 #endif
175
176 /* high performance ("contiguous data") */
177 #ifndef S_ISCTG
178 # define S_ISCTG(p) 0
179 #endif
180
181 /* Cray DMF (data migration facility): off line, with data  */
182 #ifndef S_ISOFD
183 # define S_ISOFD(p) 0
184 #endif
185
186 /* Cray DMF (data migration facility): off line, with no data  */
187 #ifndef S_ISOFL
188 # define S_ISOFL(p) 0
189 #endif
190
191 /* 4.4BSD whiteout */
192 #ifndef S_ISWHT
193 # define S_ISWHT(m) 0
194 #endif
195
196 /* If any of the following are undefined,
197    define them to their de facto standard values.  */
198 #if !S_ISUID
199 # define S_ISUID 04000
200 #endif
201 #if !S_ISGID
202 # define S_ISGID 02000
203 #endif
204
205 /* S_ISVTX is a common extension to POSIX.  */
206 #ifndef S_ISVTX
207 # define S_ISVTX 01000
208 #endif
209
210 #if !S_IRUSR && S_IREAD
211 # define S_IRUSR S_IREAD
212 #endif
213 #if !S_IRUSR
214 # define S_IRUSR 00400
215 #endif
216 #if !S_IRGRP
217 # define S_IRGRP (S_IRUSR >> 3)
218 #endif
219 #if !S_IROTH
220 # define S_IROTH (S_IRUSR >> 6)
221 #endif
222
223 #if !S_IWUSR && S_IWRITE
224 # define S_IWUSR S_IWRITE
225 #endif
226 #if !S_IWUSR
227 # define S_IWUSR 00200
228 #endif
229 #if !S_IWGRP
230 # define S_IWGRP (S_IWUSR >> 3)
231 #endif
232 #if !S_IWOTH
233 # define S_IWOTH (S_IWUSR >> 6)
234 #endif
235
236 #if !S_IXUSR && S_IEXEC
237 # define S_IXUSR S_IEXEC
238 #endif
239 #if !S_IXUSR
240 # define S_IXUSR 00100
241 #endif
242 #if !S_IXGRP
243 # define S_IXGRP (S_IXUSR >> 3)
244 #endif
245 #if !S_IXOTH
246 # define S_IXOTH (S_IXUSR >> 6)
247 #endif
248
249 #if !S_IRWXU
250 # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
251 #endif
252 #if !S_IRWXG
253 # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
254 #endif
255 #if !S_IRWXO
256 # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
257 #endif
258
259 /* S_IXUGO is a common extension to POSIX.  */
260 #if !S_IXUGO
261 # define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
262 #endif
263
264 #ifndef S_IRWXUGO
265 # define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
266 #endif
267
268 /* mingw does not support symlinks, therefore it does not have lstat.  But
269    without links, stat does just fine.  */
270 #if ! @HAVE_LSTAT@
271 # define lstat stat
272 #endif
273
274 #if @REPLACE_MKDIR@
275 # undef mkdir
276 # define mkdir rpl_mkdir
277 extern int mkdir (char const *name, mode_t mode);
278 #else
279 /* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
280    Additionally, it declares _mkdir (and depending on compile flags, an
281    alias mkdir), only in the nonstandard <io.h>, which is included above.  */
282 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
283
284 static inline int
285 rpl_mkdir (char const *name, mode_t mode)
286 {
287   return _mkdir (name);
288 }
289
290 #  define mkdir rpl_mkdir
291 # endif
292 #endif
293
294 #endif /* _GL_SYS_STAT_H */
295 #endif /* _GL_SYS_STAT_H */