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