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