mknod: new module
[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 /* Get struct timespec.  */
42 #include <time.h>
43
44 /* The include_next requires a split double-inclusion guard.  */
45 #@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
46
47 #ifndef _GL_SYS_STAT_H
48 #define _GL_SYS_STAT_H
49
50 /* The definition of GL_LINK_WARNING is copied here.  */
51
52 /* Before doing "#define mkdir rpl_mkdir" below, we need to include all
53    headers that may declare mkdir().  */
54 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
55 # include <io.h>
56 #endif
57
58 #ifndef S_IFMT
59 # define S_IFMT 0170000
60 #endif
61
62 #if STAT_MACROS_BROKEN
63 # undef S_ISBLK
64 # undef S_ISCHR
65 # undef S_ISDIR
66 # undef S_ISFIFO
67 # undef S_ISLNK
68 # undef S_ISNAM
69 # undef S_ISMPB
70 # undef S_ISMPC
71 # undef S_ISNWK
72 # undef S_ISREG
73 # undef S_ISSOCK
74 #endif
75
76 #ifndef S_ISBLK
77 # ifdef S_IFBLK
78 #  define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
79 # else
80 #  define S_ISBLK(m) 0
81 # endif
82 #endif
83
84 #ifndef S_ISCHR
85 # ifdef S_IFCHR
86 #  define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
87 # else
88 #  define S_ISCHR(m) 0
89 # endif
90 #endif
91
92 #ifndef S_ISDIR
93 # ifdef S_IFDIR
94 #  define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
95 # else
96 #  define S_ISDIR(m) 0
97 # endif
98 #endif
99
100 #ifndef S_ISDOOR /* Solaris 2.5 and up */
101 # define S_ISDOOR(m) 0
102 #endif
103
104 #ifndef S_ISFIFO
105 # ifdef S_IFIFO
106 #  define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
107 # else
108 #  define S_ISFIFO(m) 0
109 # endif
110 #endif
111
112 #ifndef S_ISLNK
113 # ifdef S_IFLNK
114 #  define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
115 # else
116 #  define S_ISLNK(m) 0
117 # endif
118 #endif
119
120 #ifndef S_ISMPB /* V7 */
121 # ifdef S_IFMPB
122 #  define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
123 #  define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
124 # else
125 #  define S_ISMPB(m) 0
126 #  define S_ISMPC(m) 0
127 # endif
128 #endif
129
130 #ifndef S_ISNAM /* Xenix */
131 # ifdef S_IFNAM
132 #  define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
133 # else
134 #  define S_ISNAM(m) 0
135 # endif
136 #endif
137
138 #ifndef S_ISNWK /* HP/UX */
139 # ifdef S_IFNWK
140 #  define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
141 # else
142 #  define S_ISNWK(m) 0
143 # endif
144 #endif
145
146 #ifndef S_ISPORT /* Solaris 10 and up */
147 # define S_ISPORT(m) 0
148 #endif
149
150 #ifndef S_ISREG
151 # ifdef S_IFREG
152 #  define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
153 # else
154 #  define S_ISREG(m) 0
155 # endif
156 #endif
157
158 #ifndef S_ISSOCK
159 # ifdef S_IFSOCK
160 #  define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
161 # else
162 #  define S_ISSOCK(m) 0
163 # endif
164 #endif
165
166
167 #ifndef S_TYPEISMQ
168 # define S_TYPEISMQ(p) 0
169 #endif
170
171 #ifndef S_TYPEISTMO
172 # define S_TYPEISTMO(p) 0
173 #endif
174
175
176 #ifndef S_TYPEISSEM
177 # ifdef S_INSEM
178 #  define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
179 # else
180 #  define S_TYPEISSEM(p) 0
181 # endif
182 #endif
183
184 #ifndef S_TYPEISSHM
185 # ifdef S_INSHD
186 #  define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
187 # else
188 #  define S_TYPEISSHM(p) 0
189 # endif
190 #endif
191
192 /* high performance ("contiguous data") */
193 #ifndef S_ISCTG
194 # define S_ISCTG(p) 0
195 #endif
196
197 /* Cray DMF (data migration facility): off line, with data  */
198 #ifndef S_ISOFD
199 # define S_ISOFD(p) 0
200 #endif
201
202 /* Cray DMF (data migration facility): off line, with no data  */
203 #ifndef S_ISOFL
204 # define S_ISOFL(p) 0
205 #endif
206
207 /* 4.4BSD whiteout */
208 #ifndef S_ISWHT
209 # define S_ISWHT(m) 0
210 #endif
211
212 /* If any of the following are undefined,
213    define them to their de facto standard values.  */
214 #if !S_ISUID
215 # define S_ISUID 04000
216 #endif
217 #if !S_ISGID
218 # define S_ISGID 02000
219 #endif
220
221 /* S_ISVTX is a common extension to POSIX.  */
222 #ifndef S_ISVTX
223 # define S_ISVTX 01000
224 #endif
225
226 #if !S_IRUSR && S_IREAD
227 # define S_IRUSR S_IREAD
228 #endif
229 #if !S_IRUSR
230 # define S_IRUSR 00400
231 #endif
232 #if !S_IRGRP
233 # define S_IRGRP (S_IRUSR >> 3)
234 #endif
235 #if !S_IROTH
236 # define S_IROTH (S_IRUSR >> 6)
237 #endif
238
239 #if !S_IWUSR && S_IWRITE
240 # define S_IWUSR S_IWRITE
241 #endif
242 #if !S_IWUSR
243 # define S_IWUSR 00200
244 #endif
245 #if !S_IWGRP
246 # define S_IWGRP (S_IWUSR >> 3)
247 #endif
248 #if !S_IWOTH
249 # define S_IWOTH (S_IWUSR >> 6)
250 #endif
251
252 #if !S_IXUSR && S_IEXEC
253 # define S_IXUSR S_IEXEC
254 #endif
255 #if !S_IXUSR
256 # define S_IXUSR 00100
257 #endif
258 #if !S_IXGRP
259 # define S_IXGRP (S_IXUSR >> 3)
260 #endif
261 #if !S_IXOTH
262 # define S_IXOTH (S_IXUSR >> 6)
263 #endif
264
265 #if !S_IRWXU
266 # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
267 #endif
268 #if !S_IRWXG
269 # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
270 #endif
271 #if !S_IRWXO
272 # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
273 #endif
274
275 /* S_IXUGO is a common extension to POSIX.  */
276 #if !S_IXUGO
277 # define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
278 #endif
279
280 #ifndef S_IRWXUGO
281 # define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
282 #endif
283
284 /* Macros for futimens and utimensat.  */
285 #ifndef UTIME_NOW
286 # define UTIME_NOW (-1)
287 # define UTIME_OMIT (-2)
288 #endif
289
290
291 #ifdef __cplusplus
292 extern "C" {
293 #endif
294
295
296 #if @GNULIB_FCHMODAT@
297 # if !@HAVE_FCHMODAT@
298 extern int fchmodat (int fd, char const *file, mode_t mode, int flag);
299 # endif
300 #elif defined GNULIB_POSIXCHECK
301 # undef fchmodat
302 # define fchmodat(d,n,m,f)                         \
303     (GL_LINK_WARNING ("fchmodat is not portable - " \
304                       "use gnulib module openat for portability"), \
305      fchmodat (d, n, m, f))
306 #endif
307
308
309 #if @REPLACE_FSTAT@
310 # define fstat rpl_fstat
311 extern int fstat (int fd, struct stat *buf);
312 #endif
313
314
315 #if @GNULIB_FSTATAT@
316 # if @REPLACE_FSTATAT@
317 #  undef fstatat
318 #  define fstatat rpl_fstatat
319 # endif
320 # if !@HAVE_FSTATAT@ || @REPLACE_FSTATAT@
321 extern int fstatat (int fd, char const *name, struct stat *st, int flags);
322 # endif
323 #elif defined GNULIB_POSIXCHECK
324 # undef fstatat
325 # define fstatat(d,n,s,f)                         \
326     (GL_LINK_WARNING ("fstatat is not portable - " \
327                       "use gnulib module openat for portability"), \
328      fstatat (d, n, s, f))
329 #endif
330
331
332 #if @GNULIB_FUTIMENS@
333 # if @REPLACE_FUTIMENS@
334 #  undef futimens
335 #  define futimens rpl_futimens
336 # endif
337 # if !@HAVE_FUTIMENS@ || @REPLACE_FUTIMENS@
338 extern int futimens (int fd, struct timespec const times[2]);
339 # endif
340 #elif defined GNULIB_POSIXCHECK
341 # undef futimens
342 # define futimens(f,t)                         \
343     (GL_LINK_WARNING ("futimens is not portable - " \
344                       "use gnulib module futimens for portability"), \
345      futimens (f, t))
346 #endif
347
348
349 #if @GNULIB_LCHMOD@
350 /* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
351    denotes a symbolic link.  */
352 # if !@HAVE_LCHMOD@
353 /* The lchmod replacement follows symbolic links.  Callers should take
354    this into account; lchmod should be applied only to arguments that
355    are known to not be symbolic links.  On hosts that lack lchmod,
356    this can lead to race conditions between the check and the
357    invocation of lchmod, but we know of no workarounds that are
358    reliable in general.  You might try requesting support for lchmod
359    from your operating system supplier.  */
360 #  define lchmod chmod
361 # endif
362 # if 0 /* assume already declared */
363 extern int lchmod (const char *filename, mode_t mode);
364 # endif
365 #elif defined GNULIB_POSIXCHECK
366 # undef lchmod
367 # define lchmod(f,m) \
368     (GL_LINK_WARNING ("lchmod is unportable - " \
369                       "use gnulib module lchmod for portability"), \
370      lchmod (f, m))
371 #endif
372
373
374 #if @GNULIB_LSTAT@
375 # if ! @HAVE_LSTAT@
376 /* mingw does not support symlinks, therefore it does not have lstat.  But
377    without links, stat does just fine.  */
378 #  define lstat stat
379 # elif @REPLACE_LSTAT@
380 #  undef lstat
381 #  define lstat rpl_lstat
382 extern int rpl_lstat (const char *name, struct stat *buf);
383 # endif
384 #elif defined GNULIB_POSIXCHECK
385 # undef lstat
386 # define lstat(p,b)                                                     \
387   (GL_LINK_WARNING ("lstat is unportable - "                            \
388                     "use gnulib module lstat for portability"),         \
389    lstat (p, b))
390 #endif
391
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 #if @GNULIB_MKDIRAT@
415 # if !@HAVE_MKDIRAT@
416 extern int mkdirat (int fd, char const *file, mode_t mode);
417 # endif
418 #elif defined GNULIB_POSIXCHECK
419 # undef mkdirat
420 # define mkdirat(d,n,m)                         \
421     (GL_LINK_WARNING ("mkdirat is not portable - " \
422                       "use gnulib module openat for portability"), \
423      mkdirat (d, n, m))
424 #endif
425
426
427 #if @GNULIB_MKFIFO@
428 # if @REPLACE_MKFIFO@
429 #  undef mkfifo
430 #  define mkfifo rpl_mkfifo
431 # endif
432 # if !@HAVE_MKFIFO@ || @REPLACE_MKFIFO@
433 int mkfifo (char const *file, mode_t mode);
434 # endif
435 #elif defined GNULIB_POSIXCHECK
436 # undef mkfifo
437 # define mkfifo(n,m)                                                    \
438     (GL_LINK_WARNING ("mkfifo is not portable - "                       \
439                       "use gnulib module mkfifo for portability"),      \
440      mkfifo (n, m))
441 #endif
442
443
444 #if @GNULIB_MKFIFOAT@
445 # if !@HAVE_MKFIFOAT@
446 int mkfifoat (int fd, char const *file, mode_t mode);
447 # endif
448 #elif defined GNULIB_POSIXCHECK
449 # undef mkfifoat
450 # define mkfifoat(d,n,m)                                     \
451     (GL_LINK_WARNING ("mkfifoat is not portable - " \
452                       "use gnulib module mkfifoat for portability"), \
453      mkfifoat (d, n, m))
454 #endif
455
456
457 #if @GNULIB_MKNOD@
458 # if @REPLACE_MKNOD@
459 #  undef mknod
460 #  define mknod rpl_mknod
461 # endif
462 # if !@HAVE_MKNOD@ || @REPLACE_MKNOD@
463 int mknod (char const *file, mode_t mode, dev_t dev);
464 # endif
465 #elif defined GNULIB_POSIXCHECK
466 # undef mknod
467 # define mknod(n,m,d)                                                   \
468     (GL_LINK_WARNING ("mknod is not portable - "                        \
469                       "use gnulib module mknod for portability"),       \
470      mknod (n, m, d))
471 #endif
472
473
474 #if @GNULIB_MKNODAT@
475 # if !@HAVE_MKNODAT@
476 int mknodat (int fd, char const *file, mode_t mode, dev_t dev);
477 # endif
478 #elif defined GNULIB_POSIXCHECK
479 # undef mknodat
480 # define mknodat(f,n,m,d)                            \
481     (GL_LINK_WARNING ("mknodat is not portable - " \
482                       "use gnulib module mkfifoat for portability"), \
483      mknodat (f, n, m, d))
484 #endif
485
486
487 #if @GNULIB_STAT@
488 # if @REPLACE_STAT@
489 /* We can't use the object-like #define stat rpl_stat, because of
490    struct stat.  This means that rpl_stat will not be used if the user
491    does (stat)(a,b).  Oh well.  */
492 #  undef stat
493 #  ifdef _LARGE_FILES
494     /* With _LARGE_FILES defined, AIX (only) defines stat to stat64,
495        so we have to replace stat64() instead of stat(). */
496 #   define stat stat64
497 #   undef stat64
498 #   define stat64(name, st) rpl_stat (name, st)
499 #  else /* !_LARGE_FILES */
500 #   define stat(name, st) rpl_stat (name, st)
501 #  endif /* !_LARGE_FILES */
502 extern int stat (const char *name, struct stat *buf);
503 # endif
504 #elif defined GNULIB_POSIXCHECK
505 # undef stat
506 # define stat(p,b)                                                      \
507   (GL_LINK_WARNING ("stat is unportable - "                             \
508                     "use gnulib module stat for portability"),          \
509    stat (p, b))
510 #endif
511
512
513 #if @GNULIB_UTIMENSAT@
514 # if @REPLACE_UTIMENSAT@
515 #  undef utimensat
516 #  define utimensat rpl_utimensat
517 # endif
518 # if !@HAVE_UTIMENSAT@ || @REPLACE_UTIMENSAT@
519    extern int utimensat (int fd, char const *name,
520                          struct timespec const times[2], int flag);
521 # endif
522 #elif defined GNULIB_POSIXCHECK
523 # undef utimensat
524 # define utimensat(d,n,t,f)                          \
525     (GL_LINK_WARNING ("utimensat is not portable - " \
526                       "use gnulib module utimensat for portability"), \
527      utimensat (d, n, t, f))
528 #endif
529
530
531 #ifdef __cplusplus
532 }
533 #endif
534
535
536 #endif /* _GL_SYS_STAT_H */
537 #endif /* _GL_SYS_STAT_H */
538 #endif