Merge branch 'upstream'
[gnulib.git] / lib / sys_stat.in.h
1 /* Provide a more complete sys/stat header file.
2    Copyright (C) 2005-2009 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 /* Get nlink_t.  */
39 #include <sys/types.h>
40
41 /* The include_next requires a split double-inclusion guard.  */
42 #@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
43
44 #ifndef _GL_SYS_STAT_H
45 #define _GL_SYS_STAT_H
46
47 /* The definition of GL_LINK_WARNING is copied here.  */
48
49 /* Before doing "#define mkdir rpl_mkdir" below, we need to include all
50    headers that may declare mkdir().  */
51 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
52 # include <io.h>
53 #endif
54
55 #ifndef S_IFMT
56 # define S_IFMT 0170000
57 #endif
58
59 #if STAT_MACROS_BROKEN
60 # undef S_ISBLK
61 # undef S_ISCHR
62 # undef S_ISDIR
63 # undef S_ISFIFO
64 # undef S_ISLNK
65 # undef S_ISNAM
66 # undef S_ISMPB
67 # undef S_ISMPC
68 # undef S_ISNWK
69 # undef S_ISREG
70 # undef S_ISSOCK
71 #endif
72
73 #ifndef S_ISBLK
74 # ifdef S_IFBLK
75 #  define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
76 # else
77 #  define S_ISBLK(m) 0
78 # endif
79 #endif
80
81 #ifndef S_ISCHR
82 # ifdef S_IFCHR
83 #  define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
84 # else
85 #  define S_ISCHR(m) 0
86 # endif
87 #endif
88
89 #ifndef S_ISDIR
90 # ifdef S_IFDIR
91 #  define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
92 # else
93 #  define S_ISDIR(m) 0
94 # endif
95 #endif
96
97 #ifndef S_ISDOOR /* Solaris 2.5 and up */
98 # define S_ISDOOR(m) 0
99 #endif
100
101 #ifndef S_ISFIFO
102 # ifdef S_IFIFO
103 #  define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
104 # else
105 #  define S_ISFIFO(m) 0
106 # endif
107 #endif
108
109 #ifndef S_ISLNK
110 # ifdef S_IFLNK
111 #  define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
112 # else
113 #  define S_ISLNK(m) 0
114 # endif
115 #endif
116
117 #ifndef S_ISMPB /* V7 */
118 # ifdef S_IFMPB
119 #  define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
120 #  define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
121 # else
122 #  define S_ISMPB(m) 0
123 #  define S_ISMPC(m) 0
124 # endif
125 #endif
126
127 #ifndef S_ISNAM /* Xenix */
128 # ifdef S_IFNAM
129 #  define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
130 # else
131 #  define S_ISNAM(m) 0
132 # endif
133 #endif
134
135 #ifndef S_ISNWK /* HP/UX */
136 # ifdef S_IFNWK
137 #  define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
138 # else
139 #  define S_ISNWK(m) 0
140 # endif
141 #endif
142
143 #ifndef S_ISPORT /* Solaris 10 and up */
144 # define S_ISPORT(m) 0
145 #endif
146
147 #ifndef S_ISREG
148 # ifdef S_IFREG
149 #  define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
150 # else
151 #  define S_ISREG(m) 0
152 # endif
153 #endif
154
155 #ifndef S_ISSOCK
156 # ifdef S_IFSOCK
157 #  define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
158 # else
159 #  define S_ISSOCK(m) 0
160 # endif
161 #endif
162
163
164 #ifndef S_TYPEISMQ
165 # define S_TYPEISMQ(p) 0
166 #endif
167
168 #ifndef S_TYPEISTMO
169 # define S_TYPEISTMO(p) 0
170 #endif
171
172
173 #ifndef S_TYPEISSEM
174 # ifdef S_INSEM
175 #  define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
176 # else
177 #  define S_TYPEISSEM(p) 0
178 # endif
179 #endif
180
181 #ifndef S_TYPEISSHM
182 # ifdef S_INSHD
183 #  define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
184 # else
185 #  define S_TYPEISSHM(p) 0
186 # endif
187 #endif
188
189 /* high performance ("contiguous data") */
190 #ifndef S_ISCTG
191 # define S_ISCTG(p) 0
192 #endif
193
194 /* Cray DMF (data migration facility): off line, with data  */
195 #ifndef S_ISOFD
196 # define S_ISOFD(p) 0
197 #endif
198
199 /* Cray DMF (data migration facility): off line, with no data  */
200 #ifndef S_ISOFL
201 # define S_ISOFL(p) 0
202 #endif
203
204 /* 4.4BSD whiteout */
205 #ifndef S_ISWHT
206 # define S_ISWHT(m) 0
207 #endif
208
209 /* If any of the following are undefined,
210    define them to their de facto standard values.  */
211 #if !S_ISUID
212 # define S_ISUID 04000
213 #endif
214 #if !S_ISGID
215 # define S_ISGID 02000
216 #endif
217
218 /* S_ISVTX is a common extension to POSIX.  */
219 #ifndef S_ISVTX
220 # define S_ISVTX 01000
221 #endif
222
223 #if !S_IRUSR && S_IREAD
224 # define S_IRUSR S_IREAD
225 #endif
226 #if !S_IRUSR
227 # define S_IRUSR 00400
228 #endif
229 #if !S_IRGRP
230 # define S_IRGRP (S_IRUSR >> 3)
231 #endif
232 #if !S_IROTH
233 # define S_IROTH (S_IRUSR >> 6)
234 #endif
235
236 #if !S_IWUSR && S_IWRITE
237 # define S_IWUSR S_IWRITE
238 #endif
239 #if !S_IWUSR
240 # define S_IWUSR 00200
241 #endif
242 #if !S_IWGRP
243 # define S_IWGRP (S_IWUSR >> 3)
244 #endif
245 #if !S_IWOTH
246 # define S_IWOTH (S_IWUSR >> 6)
247 #endif
248
249 #if !S_IXUSR && S_IEXEC
250 # define S_IXUSR S_IEXEC
251 #endif
252 #if !S_IXUSR
253 # define S_IXUSR 00100
254 #endif
255 #if !S_IXGRP
256 # define S_IXGRP (S_IXUSR >> 3)
257 #endif
258 #if !S_IXOTH
259 # define S_IXOTH (S_IXUSR >> 6)
260 #endif
261
262 #if !S_IRWXU
263 # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
264 #endif
265 #if !S_IRWXG
266 # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
267 #endif
268 #if !S_IRWXO
269 # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
270 #endif
271
272 /* S_IXUGO is a common extension to POSIX.  */
273 #if !S_IXUGO
274 # define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
275 #endif
276
277 #ifndef S_IRWXUGO
278 # define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
279 #endif
280
281
282 #ifdef __cplusplus
283 extern "C" {
284 #endif
285
286
287 #if @GNULIB_LSTAT@
288 # if ! @HAVE_LSTAT@
289 /* mingw does not support symlinks, therefore it does not have lstat.  But
290    without links, stat does just fine.  */
291 #  define lstat stat
292 # elif @REPLACE_LSTAT@
293 #  undef lstat
294 #  define lstat rpl_lstat
295 extern int rpl_lstat (const char *name, struct stat *buf);
296 # endif
297 #elif defined GNULIB_POSIXCHECK
298 # undef lstat
299 # define lstat(p,b)                                                     \
300   (GL_LINK_WARNING ("lstat is unportable - "                            \
301                     "use gnulib module lstat for portability"),         \
302    lstat (p, b))
303 #endif
304
305 #if @GNULIB_STAT@
306 # if @REPLACE_STAT@
307 /* We can't use the object-like #define stat rpl_stat, because of
308    struct stat.  This means that rpl_stat will not be used if the user
309    does (stat)(a,b).  Oh well.  */
310 #  undef stat
311 #  define stat(name, st) rpl_stat (name, st)
312 extern int stat (const char *name, struct stat *buf);
313 # endif
314 #elif defined GNULIB_POSIXCHECK
315 # undef stat
316 # define stat(p,b)                                                      \
317   (GL_LINK_WARNING ("stat is unportable - "                             \
318                     "use gnulib module stat for portability"),          \
319    stat (p, b))
320 #endif
321
322 #if @GNULIB_FCHMODAT@
323 # if !@HAVE_FCHMODAT@
324 extern int fchmodat (int fd, char const *file, mode_t mode, int flag);
325 # endif
326 #elif defined GNULIB_POSIXCHECK
327 # undef fchmodat
328 # define fchmodat(d,n,m,f)                         \
329     (GL_LINK_WARNING ("fchmodat is not portable - " \
330                       "use gnulib module openat for portability"), \
331      fchmodat (d, n, m, f))
332 #endif
333
334
335 #if @GNULIB_FSTATAT@
336 # if @REPLACE_FSTATAT@
337 #  undef fstatat
338 #  define fstatat rpl_fstatat
339 # endif
340 # if !@HAVE_FSTATAT@ || @REPLACE_FSTATAT@
341 extern int fstatat (int fd, char const *name, struct stat *st, int flags);
342 # endif
343 #elif defined GNULIB_POSIXCHECK
344 # undef fstatat
345 # define fstatat(d,n,s,f)                         \
346     (GL_LINK_WARNING ("fstatat is not portable - " \
347                       "use gnulib module openat for portability"), \
348      fstatat (d, n, s, f))
349 #endif
350
351
352 #if @GNULIB_MKDIRAT@
353 # if !@HAVE_MKDIRAT@
354 extern int mkdirat (int fd, char const *file, mode_t mode);
355 # endif
356 #elif defined GNULIB_POSIXCHECK
357 # undef mkdirat
358 # define mkdirat(d,n,m)                         \
359     (GL_LINK_WARNING ("mkdirat is not portable - " \
360                       "use gnulib module openat for portability"), \
361      mkdirat (d, n, m))
362 #endif
363
364 #if @GNULIB_MKFIFOAT@
365 # if !@HAVE_MKFIFOAT@
366 int mkfifoat (int fd, char const *file, mode_t mode);
367 # endif
368 #elif defined GNULIB_POSIXCHECK
369 # undef mkfifoat
370 # define mkfifoat(d,n,m)                                     \
371     (GL_LINK_WARNING ("mkfifoat is not portable - " \
372                       "use gnulib module mkfifoat for portability"), \
373      mkfifoat (d, n, m))
374 #endif
375
376 #if @GNULIB_MKNODAT@
377 # if !@HAVE_MKNODAT@
378 int mknodat (int fd, char const *file, mode_t mode, dev_t dev);
379 # endif
380 #elif defined GNULIB_POSIXCHECK
381 # undef mknodat
382 # define mknodat(f,n,m,d)                            \
383     (GL_LINK_WARNING ("mknodat is not portable - " \
384                       "use gnulib module mkfifoat for portability"), \
385      mknodat (f, n, m, d))
386 #endif
387
388 #if @REPLACE_FSTAT@
389 # define fstat rpl_fstat
390 extern int fstat (int fd, struct stat *buf);
391 #endif
392
393 #if @REPLACE_MKDIR@
394 # undef mkdir
395 # define mkdir rpl_mkdir
396 extern int mkdir (char const *name, mode_t mode);
397 #else
398 /* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
399    Additionally, it declares _mkdir (and depending on compile flags, an
400    alias mkdir), only in the nonstandard <io.h>, which is included above.  */
401 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
402
403 static inline int
404 rpl_mkdir (char const *name, mode_t mode)
405 {
406   return _mkdir (name);
407 }
408
409 #  define mkdir rpl_mkdir
410 # endif
411 #endif
412
413
414 /* Declare BSD extensions.  */
415
416 #if @GNULIB_LCHMOD@
417 /* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
418    denotes a symbolic link.  */
419 # if !@HAVE_LCHMOD@
420 /* The lchmod replacement follows symbolic links.  Callers should take
421    this into account; lchmod should be applied only to arguments that
422    are known to not be symbolic links.  On hosts that lack lchmod,
423    this can lead to race conditions between the check and the
424    invocation of lchmod, but we know of no workarounds that are
425    reliable in general.  You might try requesting support for lchmod
426    from your operating system supplier.  */
427 #  define lchmod chmod
428 # endif
429 # if 0 /* assume already declared */
430 extern int lchmod (const char *filename, mode_t mode);
431 # endif
432 #elif defined GNULIB_POSIXCHECK
433 # undef lchmod
434 # define lchmod(f,m) \
435     (GL_LINK_WARNING ("lchmod is unportable - " \
436                       "use gnulib module lchmod for portability"), \
437      lchmod (f, m))
438 #endif
439
440
441 #ifdef __cplusplus
442 }
443 #endif
444
445
446 #endif /* _GL_SYS_STAT_H */
447 #endif /* _GL_SYS_STAT_H */
448 #endif