1 /* Provide a more complete sys/stat header file.
2 Copyright (C) 2005-2011 Free Software Foundation, Inc.
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)
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.
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. */
18 /* Written by Eric Blake, Paul Eggert, and Jim Meyering. */
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. */
25 @PRAGMA_SYSTEM_HEADER@
29 #if defined __need_system_sys_stat_h
30 /* Special invocation convention. */
32 #@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
35 /* Normal invocation convention. */
37 #ifndef _@GUARD_PREFIX@_SYS_STAT_H
40 #include <sys/types.h>
42 /* Get struct timespec. */
45 /* The include_next requires a split double-inclusion guard. */
46 #@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
48 #ifndef _@GUARD_PREFIX@_SYS_STAT_H
49 #define _@GUARD_PREFIX@_SYS_STAT_H
51 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
53 /* The definition of _GL_ARG_NONNULL is copied here. */
55 /* The definition of _GL_WARN_ON_USE is copied here. */
57 /* Before doing "#define mkdir rpl_mkdir" below, we need to include all
58 headers that may declare mkdir(). Native Windows platforms declare mkdir
59 in <io.h> and/or <direct.h>, not in <unistd.h>. */
60 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
61 # include <io.h> /* mingw32, mingw64 */
62 # include <direct.h> /* mingw64, MSVC 9 */
67 # define S_IFIFO _S_IFIFO
72 # define S_IFMT 0170000
75 #if STAT_MACROS_BROKEN
91 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
99 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
101 # define S_ISCHR(m) 0
107 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
109 # define S_ISDIR(m) 0
113 #ifndef S_ISDOOR /* Solaris 2.5 and up */
114 # define S_ISDOOR(m) 0
119 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
121 # define S_ISFIFO(m) 0
127 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
129 # define S_ISLNK(m) 0
133 #ifndef S_ISMPB /* V7 */
135 # define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
136 # define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
138 # define S_ISMPB(m) 0
139 # define S_ISMPC(m) 0
143 #ifndef S_ISNAM /* Xenix */
145 # define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
147 # define S_ISNAM(m) 0
151 #ifndef S_ISNWK /* HP/UX */
153 # define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
155 # define S_ISNWK(m) 0
159 #ifndef S_ISPORT /* Solaris 10 and up */
160 # define S_ISPORT(m) 0
165 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
167 # define S_ISREG(m) 0
173 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
175 # define S_ISSOCK(m) 0
181 # define S_TYPEISMQ(p) 0
185 # define S_TYPEISTMO(p) 0
191 # define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
193 # define S_TYPEISSEM(p) 0
199 # define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
201 # define S_TYPEISSHM(p) 0
205 /* high performance ("contiguous data") */
207 # define S_ISCTG(p) 0
210 /* Cray DMF (data migration facility): off line, with data */
212 # define S_ISOFD(p) 0
215 /* Cray DMF (data migration facility): off line, with no data */
217 # define S_ISOFL(p) 0
220 /* 4.4BSD whiteout */
222 # define S_ISWHT(m) 0
225 /* If any of the following are undefined,
226 define them to their de facto standard values. */
228 # define S_ISUID 04000
231 # define S_ISGID 02000
234 /* S_ISVTX is a common extension to POSIX. */
236 # define S_ISVTX 01000
239 #if !S_IRUSR && S_IREAD
240 # define S_IRUSR S_IREAD
243 # define S_IRUSR 00400
246 # define S_IRGRP (S_IRUSR >> 3)
249 # define S_IROTH (S_IRUSR >> 6)
252 #if !S_IWUSR && S_IWRITE
253 # define S_IWUSR S_IWRITE
256 # define S_IWUSR 00200
259 # define S_IWGRP (S_IWUSR >> 3)
262 # define S_IWOTH (S_IWUSR >> 6)
265 #if !S_IXUSR && S_IEXEC
266 # define S_IXUSR S_IEXEC
269 # define S_IXUSR 00100
272 # define S_IXGRP (S_IXUSR >> 3)
275 # define S_IXOTH (S_IXUSR >> 6)
279 # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
282 # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
285 # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
288 /* S_IXUGO is a common extension to POSIX. */
290 # define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
294 # define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
297 /* Macros for futimens and utimensat. */
299 # define UTIME_NOW (-1)
300 # define UTIME_OMIT (-2)
304 #if @GNULIB_FCHMODAT@
305 # if !@HAVE_FCHMODAT@
306 _GL_FUNCDECL_SYS (fchmodat, int,
307 (int fd, char const *file, mode_t mode, int flag)
308 _GL_ARG_NONNULL ((2)));
310 _GL_CXXALIAS_SYS (fchmodat, int,
311 (int fd, char const *file, mode_t mode, int flag));
312 _GL_CXXALIASWARN (fchmodat);
313 #elif defined GNULIB_POSIXCHECK
315 # if HAVE_RAW_DECL_FCHMODAT
316 _GL_WARN_ON_USE (fchmodat, "fchmodat is not portable - "
317 "use gnulib module openat for portability");
323 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
324 # define fstat rpl_fstat
326 _GL_FUNCDECL_RPL (fstat, int, (int fd, struct stat *buf) _GL_ARG_NONNULL ((2)));
327 _GL_CXXALIAS_RPL (fstat, int, (int fd, struct stat *buf));
329 _GL_CXXALIAS_SYS (fstat, int, (int fd, struct stat *buf));
331 _GL_CXXALIASWARN (fstat);
335 # if @REPLACE_FSTATAT@
336 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
338 # define fstatat rpl_fstatat
340 _GL_FUNCDECL_RPL (fstatat, int,
341 (int fd, char const *name, struct stat *st, int flags)
342 _GL_ARG_NONNULL ((2, 3)));
343 _GL_CXXALIAS_RPL (fstatat, int,
344 (int fd, char const *name, struct stat *st, int flags));
347 _GL_FUNCDECL_SYS (fstatat, int,
348 (int fd, char const *name, struct stat *st, int flags)
349 _GL_ARG_NONNULL ((2, 3)));
351 _GL_CXXALIAS_SYS (fstatat, int,
352 (int fd, char const *name, struct stat *st, int flags));
354 _GL_CXXALIASWARN (fstatat);
355 #elif defined GNULIB_POSIXCHECK
357 # if HAVE_RAW_DECL_FSTATAT
358 _GL_WARN_ON_USE (fstatat, "fstatat is not portable - "
359 "use gnulib module openat for portability");
364 #if @GNULIB_FUTIMENS@
365 /* Use the rpl_ prefix also on Solaris <= 9, because on Solaris 9 our futimens
366 implementation relies on futimesat, which on Solaris 10 makes an invocation
367 to futimens that is meant to invoke the libc's futimens(), not gnulib's
369 # if @REPLACE_FUTIMENS@ || (!@HAVE_FUTIMENS@ && defined __sun)
370 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
372 # define futimens rpl_futimens
374 _GL_FUNCDECL_RPL (futimens, int, (int fd, struct timespec const times[2]));
375 _GL_CXXALIAS_RPL (futimens, int, (int fd, struct timespec const times[2]));
377 # if !@HAVE_FUTIMENS@
378 _GL_FUNCDECL_SYS (futimens, int, (int fd, struct timespec const times[2]));
380 _GL_CXXALIAS_SYS (futimens, int, (int fd, struct timespec const times[2]));
383 _GL_CXXALIASWARN (futimens);
385 #elif defined GNULIB_POSIXCHECK
387 # if HAVE_RAW_DECL_FUTIMENS
388 _GL_WARN_ON_USE (futimens, "futimens is not portable - "
389 "use gnulib module futimens for portability");
395 /* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
396 denotes a symbolic link. */
398 /* The lchmod replacement follows symbolic links. Callers should take
399 this into account; lchmod should be applied only to arguments that
400 are known to not be symbolic links. On hosts that lack lchmod,
401 this can lead to race conditions between the check and the
402 invocation of lchmod, but we know of no workarounds that are
403 reliable in general. You might try requesting support for lchmod
404 from your operating system supplier. */
405 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
406 # define lchmod chmod
408 /* Need to cast, because on mingw, the second parameter of chmod is
410 _GL_CXXALIAS_RPL_CAST_1 (lchmod, chmod, int,
411 (const char *filename, mode_t mode));
413 # if 0 /* assume already declared */
414 _GL_FUNCDECL_SYS (lchmod, int, (const char *filename, mode_t mode)
415 _GL_ARG_NONNULL ((1)));
417 _GL_CXXALIAS_SYS (lchmod, int, (const char *filename, mode_t mode));
420 _GL_CXXALIASWARN (lchmod);
422 #elif defined GNULIB_POSIXCHECK
424 # if HAVE_RAW_DECL_LCHMOD
425 _GL_WARN_ON_USE (lchmod, "lchmod is unportable - "
426 "use gnulib module lchmod for portability");
433 /* mingw does not support symlinks, therefore it does not have lstat. But
434 without links, stat does just fine. */
435 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
438 _GL_CXXALIAS_RPL_1 (lstat, stat, int, (const char *name, struct stat *buf));
439 # elif @REPLACE_LSTAT@
440 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
442 # define lstat rpl_lstat
444 _GL_FUNCDECL_RPL (lstat, int, (const char *name, struct stat *buf)
445 _GL_ARG_NONNULL ((1, 2)));
446 _GL_CXXALIAS_RPL (lstat, int, (const char *name, struct stat *buf));
448 _GL_CXXALIAS_SYS (lstat, int, (const char *name, struct stat *buf));
451 _GL_CXXALIASWARN (lstat);
453 #elif defined GNULIB_POSIXCHECK
455 # if HAVE_RAW_DECL_LSTAT
456 _GL_WARN_ON_USE (lstat, "lstat is unportable - "
457 "use gnulib module lstat for portability");
463 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
465 # define mkdir rpl_mkdir
467 _GL_FUNCDECL_RPL (mkdir, int, (char const *name, mode_t mode)
468 _GL_ARG_NONNULL ((1)));
469 _GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode));
471 /* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
472 Additionally, it declares _mkdir (and depending on compile flags, an
473 alias mkdir), only in the nonstandard includes <direct.h> and <io.h>,
474 which are included above. */
475 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
477 # if !GNULIB_defined_rpl_mkdir
479 rpl_mkdir (char const *name, mode_t mode)
481 return _mkdir (name);
483 # define GNULIB_defined_rpl_mkdir 1
486 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
487 # define mkdir rpl_mkdir
489 _GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode));
491 _GL_CXXALIAS_SYS (mkdir, int, (char const *name, mode_t mode));
494 _GL_CXXALIASWARN (mkdir);
499 _GL_FUNCDECL_SYS (mkdirat, int, (int fd, char const *file, mode_t mode)
500 _GL_ARG_NONNULL ((2)));
502 _GL_CXXALIAS_SYS (mkdirat, int, (int fd, char const *file, mode_t mode));
503 _GL_CXXALIASWARN (mkdirat);
504 #elif defined GNULIB_POSIXCHECK
506 # if HAVE_RAW_DECL_MKDIRAT
507 _GL_WARN_ON_USE (mkdirat, "mkdirat is not portable - "
508 "use gnulib module openat for portability");
514 # if @REPLACE_MKFIFO@
515 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
517 # define mkfifo rpl_mkfifo
519 _GL_FUNCDECL_RPL (mkfifo, int, (char const *file, mode_t mode)
520 _GL_ARG_NONNULL ((1)));
521 _GL_CXXALIAS_RPL (mkfifo, int, (char const *file, mode_t mode));
524 _GL_FUNCDECL_SYS (mkfifo, int, (char const *file, mode_t mode)
525 _GL_ARG_NONNULL ((1)));
527 _GL_CXXALIAS_SYS (mkfifo, int, (char const *file, mode_t mode));
529 _GL_CXXALIASWARN (mkfifo);
530 #elif defined GNULIB_POSIXCHECK
532 # if HAVE_RAW_DECL_MKFIFO
533 _GL_WARN_ON_USE (mkfifo, "mkfifo is not portable - "
534 "use gnulib module mkfifo for portability");
539 #if @GNULIB_MKFIFOAT@
540 # if !@HAVE_MKFIFOAT@
541 _GL_FUNCDECL_SYS (mkfifoat, int, (int fd, char const *file, mode_t mode)
542 _GL_ARG_NONNULL ((2)));
544 _GL_CXXALIAS_SYS (mkfifoat, int, (int fd, char const *file, mode_t mode));
545 _GL_CXXALIASWARN (mkfifoat);
546 #elif defined GNULIB_POSIXCHECK
548 # if HAVE_RAW_DECL_MKFIFOAT
549 _GL_WARN_ON_USE (mkfifoat, "mkfifoat is not portable - "
550 "use gnulib module mkfifoat for portability");
557 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
559 # define mknod rpl_mknod
561 _GL_FUNCDECL_RPL (mknod, int, (char const *file, mode_t mode, dev_t dev)
562 _GL_ARG_NONNULL ((1)));
563 _GL_CXXALIAS_RPL (mknod, int, (char const *file, mode_t mode, dev_t dev));
566 _GL_FUNCDECL_SYS (mknod, int, (char const *file, mode_t mode, dev_t dev)
567 _GL_ARG_NONNULL ((1)));
569 /* Need to cast, because on OSF/1 5.1, the third parameter is '...'. */
570 _GL_CXXALIAS_SYS_CAST (mknod, int, (char const *file, mode_t mode, dev_t dev));
572 _GL_CXXALIASWARN (mknod);
573 #elif defined GNULIB_POSIXCHECK
575 # if HAVE_RAW_DECL_MKNOD
576 _GL_WARN_ON_USE (mknod, "mknod is not portable - "
577 "use gnulib module mknod for portability");
584 _GL_FUNCDECL_SYS (mknodat, int,
585 (int fd, char const *file, mode_t mode, dev_t dev)
586 _GL_ARG_NONNULL ((2)));
588 _GL_CXXALIAS_SYS (mknodat, int,
589 (int fd, char const *file, mode_t mode, dev_t dev));
590 _GL_CXXALIASWARN (mknodat);
591 #elif defined GNULIB_POSIXCHECK
593 # if HAVE_RAW_DECL_MKNODAT
594 _GL_WARN_ON_USE (mknodat, "mknodat is not portable - "
595 "use gnulib module mkfifoat for portability");
602 /* We can't use the object-like #define stat rpl_stat, because of
603 struct stat. This means that rpl_stat will not be used if the user
604 does (stat)(a,b). Oh well. */
607 /* With _LARGE_FILES defined, AIX (only) defines stat to stat64,
608 so we have to replace stat64() instead of stat(). */
611 # define stat64(name, st) rpl_stat (name, st)
612 # else /* !_LARGE_FILES */
613 # define stat(name, st) rpl_stat (name, st)
614 # endif /* !_LARGE_FILES */
615 _GL_EXTERN_C int stat (const char *name, struct stat *buf)
616 _GL_ARG_NONNULL ((1, 2));
618 #elif defined GNULIB_POSIXCHECK
620 # if HAVE_RAW_DECL_STAT
621 _GL_WARN_ON_USE (stat, "stat is unportable - "
622 "use gnulib module stat for portability");
627 #if @GNULIB_UTIMENSAT@
628 /* Use the rpl_ prefix also on Solaris <= 9, because on Solaris 9 our utimensat
629 implementation relies on futimesat, which on Solaris 10 makes an invocation
630 to utimensat that is meant to invoke the libc's utimensat(), not gnulib's
632 # if @REPLACE_UTIMENSAT@ || (!@HAVE_UTIMENSAT@ && defined __sun)
633 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
635 # define utimensat rpl_utimensat
637 _GL_FUNCDECL_RPL (utimensat, int, (int fd, char const *name,
638 struct timespec const times[2], int flag)
639 _GL_ARG_NONNULL ((2)));
640 _GL_CXXALIAS_RPL (utimensat, int, (int fd, char const *name,
641 struct timespec const times[2], int flag));
643 # if !@HAVE_UTIMENSAT@
644 _GL_FUNCDECL_SYS (utimensat, int, (int fd, char const *name,
645 struct timespec const times[2], int flag)
646 _GL_ARG_NONNULL ((2)));
648 _GL_CXXALIAS_SYS (utimensat, int, (int fd, char const *name,
649 struct timespec const times[2], int flag));
651 # if @HAVE_UTIMENSAT@
652 _GL_CXXALIASWARN (utimensat);
654 #elif defined GNULIB_POSIXCHECK
656 # if HAVE_RAW_DECL_UTIMENSAT
657 _GL_WARN_ON_USE (utimensat, "utimensat is not portable - "
658 "use gnulib module utimensat for portability");
663 #endif /* _@GUARD_PREFIX@_SYS_STAT_H */
664 #endif /* _@GUARD_PREFIX@_SYS_STAT_H */