lib/sys_stat.in.h (lstat): Fix declaration for mingw.
[gnulib.git] / lib / sys_stat.in.h
1 /* Provide a more complete sys/stat header file.
2    Copyright (C) 2005-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 #if __GNUC__ >= 3
25 @PRAGMA_SYSTEM_HEADER@
26 #endif
27
28 #if defined __need_system_sys_stat_h
29 /* Special invocation convention.  */
30
31 #@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
32
33 #else
34 /* Normal invocation convention.  */
35
36 #ifndef _GL_SYS_STAT_H
37
38 /* The include_next requires a split double-inclusion guard.  */
39 #@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
40
41 #ifndef _GL_SYS_STAT_H
42 #define _GL_SYS_STAT_H
43
44 /* The definition of GL_LINK_WARNING is copied here.  */
45
46 /* Before doing "#define mkdir rpl_mkdir" below, we need to include all
47    headers that may declare mkdir().  */
48 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
49 # include <io.h>
50 #endif
51
52 #ifndef S_IFMT
53 # define S_IFMT 0170000
54 #endif
55
56 #if STAT_MACROS_BROKEN
57 # undef S_ISBLK
58 # undef S_ISCHR
59 # undef S_ISDIR
60 # undef S_ISFIFO
61 # undef S_ISLNK
62 # undef S_ISNAM
63 # undef S_ISMPB
64 # undef S_ISMPC
65 # undef S_ISNWK
66 # undef S_ISREG
67 # undef S_ISSOCK
68 #endif
69
70 #ifndef S_ISBLK
71 # ifdef S_IFBLK
72 #  define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
73 # else
74 #  define S_ISBLK(m) 0
75 # endif
76 #endif
77
78 #ifndef S_ISCHR
79 # ifdef S_IFCHR
80 #  define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
81 # else
82 #  define S_ISCHR(m) 0
83 # endif
84 #endif
85
86 #ifndef S_ISDIR
87 # ifdef S_IFDIR
88 #  define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
89 # else
90 #  define S_ISDIR(m) 0
91 # endif
92 #endif
93
94 #ifndef S_ISDOOR /* Solaris 2.5 and up */
95 # define S_ISDOOR(m) 0
96 #endif
97
98 #ifndef S_ISFIFO
99 # ifdef S_IFIFO
100 #  define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
101 # else
102 #  define S_ISFIFO(m) 0
103 # endif
104 #endif
105
106 #ifndef S_ISLNK
107 # ifdef S_IFLNK
108 #  define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
109 # else
110 #  define S_ISLNK(m) 0
111 # endif
112 #endif
113
114 #ifndef S_ISMPB /* V7 */
115 # ifdef S_IFMPB
116 #  define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
117 #  define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
118 # else
119 #  define S_ISMPB(m) 0
120 #  define S_ISMPC(m) 0
121 # endif
122 #endif
123
124 #ifndef S_ISNAM /* Xenix */
125 # ifdef S_IFNAM
126 #  define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
127 # else
128 #  define S_ISNAM(m) 0
129 # endif
130 #endif
131
132 #ifndef S_ISNWK /* HP/UX */
133 # ifdef S_IFNWK
134 #  define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
135 # else
136 #  define S_ISNWK(m) 0
137 # endif
138 #endif
139
140 #ifndef S_ISPORT /* Solaris 10 and up */
141 # define S_ISPORT(m) 0
142 #endif
143
144 #ifndef S_ISREG
145 # ifdef S_IFREG
146 #  define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
147 # else
148 #  define S_ISREG(m) 0
149 # endif
150 #endif
151
152 #ifndef S_ISSOCK
153 # ifdef S_IFSOCK
154 #  define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
155 # else
156 #  define S_ISSOCK(m) 0
157 # endif
158 #endif
159
160
161 #ifndef S_TYPEISMQ
162 # define S_TYPEISMQ(p) 0
163 #endif
164
165 #ifndef S_TYPEISTMO
166 # define S_TYPEISTMO(p) 0
167 #endif
168
169
170 #ifndef S_TYPEISSEM
171 # ifdef S_INSEM
172 #  define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
173 # else
174 #  define S_TYPEISSEM(p) 0
175 # endif
176 #endif
177
178 #ifndef S_TYPEISSHM
179 # ifdef S_INSHD
180 #  define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
181 # else
182 #  define S_TYPEISSHM(p) 0
183 # endif
184 #endif
185
186 /* high performance ("contiguous data") */
187 #ifndef S_ISCTG
188 # define S_ISCTG(p) 0
189 #endif
190
191 /* Cray DMF (data migration facility): off line, with data  */
192 #ifndef S_ISOFD
193 # define S_ISOFD(p) 0
194 #endif
195
196 /* Cray DMF (data migration facility): off line, with no data  */
197 #ifndef S_ISOFL
198 # define S_ISOFL(p) 0
199 #endif
200
201 /* 4.4BSD whiteout */
202 #ifndef S_ISWHT
203 # define S_ISWHT(m) 0
204 #endif
205
206 /* If any of the following are undefined,
207    define them to their de facto standard values.  */
208 #if !S_ISUID
209 # define S_ISUID 04000
210 #endif
211 #if !S_ISGID
212 # define S_ISGID 02000
213 #endif
214
215 /* S_ISVTX is a common extension to POSIX.  */
216 #ifndef S_ISVTX
217 # define S_ISVTX 01000
218 #endif
219
220 #if !S_IRUSR && S_IREAD
221 # define S_IRUSR S_IREAD
222 #endif
223 #if !S_IRUSR
224 # define S_IRUSR 00400
225 #endif
226 #if !S_IRGRP
227 # define S_IRGRP (S_IRUSR >> 3)
228 #endif
229 #if !S_IROTH
230 # define S_IROTH (S_IRUSR >> 6)
231 #endif
232
233 #if !S_IWUSR && S_IWRITE
234 # define S_IWUSR S_IWRITE
235 #endif
236 #if !S_IWUSR
237 # define S_IWUSR 00200
238 #endif
239 #if !S_IWGRP
240 # define S_IWGRP (S_IWUSR >> 3)
241 #endif
242 #if !S_IWOTH
243 # define S_IWOTH (S_IWUSR >> 6)
244 #endif
245
246 #if !S_IXUSR && S_IEXEC
247 # define S_IXUSR S_IEXEC
248 #endif
249 #if !S_IXUSR
250 # define S_IXUSR 00100
251 #endif
252 #if !S_IXGRP
253 # define S_IXGRP (S_IXUSR >> 3)
254 #endif
255 #if !S_IXOTH
256 # define S_IXOTH (S_IXUSR >> 6)
257 #endif
258
259 #if !S_IRWXU
260 # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
261 #endif
262 #if !S_IRWXG
263 # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
264 #endif
265 #if !S_IRWXO
266 # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
267 #endif
268
269 /* S_IXUGO is a common extension to POSIX.  */
270 #if !S_IXUGO
271 # define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
272 #endif
273
274 #ifndef S_IRWXUGO
275 # define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
276 #endif
277
278 #if @GNULIB_LSTAT@
279 # if ! @HAVE_LSTAT@
280 /* mingw does not support symlinks, therefore it does not have lstat.  But
281    without links, stat does just fine.  */
282 #  define lstat stat
283 # elif @REPLACE_LSTAT@
284 #  undef lstat
285 #  define lstat rpl_lstat
286 extern int rpl_lstat (const char *name, struct stat *buf);
287 # endif
288 #elif define GNULIB_POSIXCHECK
289 # undef lstat
290 # define lstat(p,b)                                                     \
291   (GL_LINK_WARNING ("lstat is unportable - "                            \
292                     "use gnulib module lstat for portability"),         \
293    lstat (p, b))
294 #endif
295
296
297 #if @REPLACE_MKDIR@
298 # undef mkdir
299 # define mkdir rpl_mkdir
300 extern int mkdir (char const *name, mode_t mode);
301 #else
302 /* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
303    Additionally, it declares _mkdir (and depending on compile flags, an
304    alias mkdir), only in the nonstandard <io.h>, which is included above.  */
305 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
306
307 static inline int
308 rpl_mkdir (char const *name, mode_t mode)
309 {
310   return _mkdir (name);
311 }
312
313 #  define mkdir rpl_mkdir
314 # endif
315 #endif
316
317
318 /* Declare BSD extensions.  */
319
320 #if @GNULIB_LCHMOD@
321 /* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
322    denotes a symbolic link.  */
323 # if !@HAVE_LCHMOD@
324 /* The lchmod replacement follows symbolic links.  Callers should take
325    this into account; lchmod should be applied only to arguments that
326    are known to not be symbolic links.  On hosts that lack lchmod,
327    this can lead to race conditions between the check and the
328    invocation of lchmod, but we know of no workarounds that are
329    reliable in general.  You might try requesting support for lchmod
330    from your operating system supplier.  */
331 #  define lchmod chmod
332 # endif
333 # if 0 /* assume already declared */
334 extern int lchmod (const char *filename, mode_t mode);
335 # endif
336 #elif defined GNULIB_POSIXCHECK
337 # undef lchmod
338 # define lchmod(f,m) \
339     (GL_LINK_WARNING ("lchmod is unportable - " \
340                       "use gnulib module lchmod for portability"), \
341      lchmod (f, m))
342 #endif
343
344 #endif /* _GL_SYS_STAT_H */
345 #endif /* _GL_SYS_STAT_H */
346 #endif