1 /* Provide a more complete sys/stat header file.
2 Copyright (C) 2005-2012 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 3, 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, see <http://www.gnu.org/licenses/>. */
17 /* Written by Eric Blake, Paul Eggert, and Jim Meyering. */
19 /* This file is supposed to be used on platforms where <sys/stat.h> is
20 incomplete. It is intended to provide definitions and prototypes
21 needed by an application. Start with what the system provides. */
24 @PRAGMA_SYSTEM_HEADER@
28 #if defined __need_system_sys_stat_h
29 /* Special invocation convention. */
31 #@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
34 /* Normal invocation convention. */
36 #ifndef _@GUARD_PREFIX@_SYS_STAT_H
39 May also define off_t to a 64-bit type on native Windows. */
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 */
65 /* Native Windows platforms declare umask() in <io.h>. */
66 #if 0 && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
70 /* Large File Support on native Windows. */
71 #if @WINDOWS_64_BIT_ST_SIZE@
72 # define stat _stati64
77 # define S_IFIFO _S_IFIFO
82 # define S_IFMT 0170000
85 #if STAT_MACROS_BROKEN
101 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
103 # define S_ISBLK(m) 0
109 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
111 # define S_ISCHR(m) 0
117 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
119 # define S_ISDIR(m) 0
123 #ifndef S_ISDOOR /* Solaris 2.5 and up */
124 # define S_ISDOOR(m) 0
129 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
131 # define S_ISFIFO(m) 0
137 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
139 # define S_ISLNK(m) 0
143 #ifndef S_ISMPB /* V7 */
145 # define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
146 # define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
148 # define S_ISMPB(m) 0
149 # define S_ISMPC(m) 0
153 #ifndef S_ISNAM /* Xenix */
155 # define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
157 # define S_ISNAM(m) 0
161 #ifndef S_ISNWK /* HP/UX */
163 # define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
165 # define S_ISNWK(m) 0
169 #ifndef S_ISPORT /* Solaris 10 and up */
170 # define S_ISPORT(m) 0
175 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
177 # define S_ISREG(m) 0
183 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
185 # define S_ISSOCK(m) 0
191 # define S_TYPEISMQ(p) 0
195 # define S_TYPEISTMO(p) 0
201 # define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
203 # define S_TYPEISSEM(p) 0
209 # define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
211 # define S_TYPEISSHM(p) 0
215 /* high performance ("contiguous data") */
217 # define S_ISCTG(p) 0
220 /* Cray DMF (data migration facility): off line, with data */
222 # define S_ISOFD(p) 0
225 /* Cray DMF (data migration facility): off line, with no data */
227 # define S_ISOFL(p) 0
230 /* 4.4BSD whiteout */
232 # define S_ISWHT(m) 0
235 /* If any of the following are undefined,
236 define them to their de facto standard values. */
238 # define S_ISUID 04000
241 # define S_ISGID 02000
244 /* S_ISVTX is a common extension to POSIX. */
246 # define S_ISVTX 01000
249 #if !S_IRUSR && S_IREAD
250 # define S_IRUSR S_IREAD
253 # define S_IRUSR 00400
256 # define S_IRGRP (S_IRUSR >> 3)
259 # define S_IROTH (S_IRUSR >> 6)
262 #if !S_IWUSR && S_IWRITE
263 # define S_IWUSR S_IWRITE
266 # define S_IWUSR 00200
269 # define S_IWGRP (S_IWUSR >> 3)
272 # define S_IWOTH (S_IWUSR >> 6)
275 #if !S_IXUSR && S_IEXEC
276 # define S_IXUSR S_IEXEC
279 # define S_IXUSR 00100
282 # define S_IXGRP (S_IXUSR >> 3)
285 # define S_IXOTH (S_IXUSR >> 6)
289 # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
292 # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
295 # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
298 /* S_IXUGO is a common extension to POSIX. */
300 # define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
304 # define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
307 /* Macros for futimens and utimensat. */
309 # define UTIME_NOW (-1)
310 # define UTIME_OMIT (-2)
314 #if @GNULIB_FCHMODAT@
315 # if !@HAVE_FCHMODAT@
316 _GL_FUNCDECL_SYS (fchmodat
, int,
317 (int fd
, char const *file
, mode_t mode
, int flag
)
318 _GL_ARG_NONNULL ((2)));
320 _GL_CXXALIAS_SYS (fchmodat
, int,
321 (int fd
, char const *file
, mode_t mode
, int flag
));
322 _GL_CXXALIASWARN (fchmodat
);
323 #elif defined GNULIB_POSIXCHECK
325 # if HAVE_RAW_DECL_FCHMODAT
326 _GL_WARN_ON_USE (fchmodat
, "fchmodat is not portable - "
327 "use gnulib module openat for portability");
334 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
336 # define fstat rpl_fstat
338 _GL_FUNCDECL_RPL (fstat
, int, (int fd
, struct stat
*buf
) _GL_ARG_NONNULL ((2)));
339 _GL_CXXALIAS_RPL (fstat
, int, (int fd
, struct stat
*buf
));
341 _GL_CXXALIAS_SYS (fstat
, int, (int fd
, struct stat
*buf
));
343 _GL_CXXALIASWARN (fstat
);
344 #elif @WINDOWS_64_BIT_ST_SIZE@
345 /* Above, we define stat to _stati64. */
346 # define fstat _fstati64
347 #elif defined GNULIB_POSIXCHECK
349 # if HAVE_RAW_DECL_FSTAT
350 _GL_WARN_ON_USE (fstat
, "fstat has portability problems - "
351 "use gnulib module fstat for portability");
357 # if @REPLACE_FSTATAT@
358 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
360 # define fstatat rpl_fstatat
362 _GL_FUNCDECL_RPL (fstatat
, int,
363 (int fd
, char const *name
, struct stat
*st
, int flags
)
364 _GL_ARG_NONNULL ((2, 3)));
365 _GL_CXXALIAS_RPL (fstatat
, int,
366 (int fd
, char const *name
, struct stat
*st
, int flags
));
369 _GL_FUNCDECL_SYS (fstatat
, int,
370 (int fd
, char const *name
, struct stat
*st
, int flags
)
371 _GL_ARG_NONNULL ((2, 3)));
373 _GL_CXXALIAS_SYS (fstatat
, int,
374 (int fd
, char const *name
, struct stat
*st
, int flags
));
376 _GL_CXXALIASWARN (fstatat
);
377 #elif defined GNULIB_POSIXCHECK
379 # if HAVE_RAW_DECL_FSTATAT
380 _GL_WARN_ON_USE (fstatat
, "fstatat is not portable - "
381 "use gnulib module openat for portability");
386 #if @GNULIB_FUTIMENS@
387 /* Use the rpl_ prefix also on Solaris <= 9, because on Solaris 9 our futimens
388 implementation relies on futimesat, which on Solaris 10 makes an invocation
389 to futimens that is meant to invoke the libc's futimens(), not gnulib's
391 # if @REPLACE_FUTIMENS@ || (!@HAVE_FUTIMENS@ && defined __sun)
392 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
394 # define futimens rpl_futimens
396 _GL_FUNCDECL_RPL (futimens
, int, (int fd
, struct timespec
const times
[2]));
397 _GL_CXXALIAS_RPL (futimens
, int, (int fd
, struct timespec
const times
[2]));
399 # if !@HAVE_FUTIMENS@
400 _GL_FUNCDECL_SYS (futimens
, int, (int fd
, struct timespec
const times
[2]));
402 _GL_CXXALIAS_SYS (futimens
, int, (int fd
, struct timespec
const times
[2]));
405 _GL_CXXALIASWARN (futimens
);
407 #elif defined GNULIB_POSIXCHECK
409 # if HAVE_RAW_DECL_FUTIMENS
410 _GL_WARN_ON_USE (futimens
, "futimens is not portable - "
411 "use gnulib module futimens for portability");
417 /* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
418 denotes a symbolic link. */
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 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
428 # define lchmod chmod
430 /* Need to cast, because on mingw, the second parameter of chmod is
432 _GL_CXXALIAS_RPL_CAST_1 (lchmod
, chmod
, int,
433 (const char *filename
, mode_t mode
));
435 # if 0 /* assume already declared */
436 _GL_FUNCDECL_SYS (lchmod
, int, (const char *filename
, mode_t mode
)
437 _GL_ARG_NONNULL ((1)));
439 _GL_CXXALIAS_SYS (lchmod
, int, (const char *filename
, mode_t mode
));
442 _GL_CXXALIASWARN (lchmod
);
444 #elif defined GNULIB_POSIXCHECK
446 # if HAVE_RAW_DECL_LCHMOD
447 _GL_WARN_ON_USE (lchmod
, "lchmod is unportable - "
448 "use gnulib module lchmod for portability");
455 /* mingw does not support symlinks, therefore it does not have lstat. But
456 without links, stat does just fine. */
457 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
460 _GL_CXXALIAS_RPL_1 (lstat
, stat
, int, (const char *name
, struct stat
*buf
));
461 # elif @REPLACE_LSTAT@
462 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
464 # define lstat rpl_lstat
466 _GL_FUNCDECL_RPL (lstat
, int, (const char *name
, struct stat
*buf
)
467 _GL_ARG_NONNULL ((1, 2)));
468 _GL_CXXALIAS_RPL (lstat
, int, (const char *name
, struct stat
*buf
));
470 _GL_CXXALIAS_SYS (lstat
, int, (const char *name
, struct stat
*buf
));
473 _GL_CXXALIASWARN (lstat
);
475 #elif defined GNULIB_POSIXCHECK
477 # if HAVE_RAW_DECL_LSTAT
478 _GL_WARN_ON_USE (lstat
, "lstat is unportable - "
479 "use gnulib module lstat for portability");
485 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
487 # define mkdir rpl_mkdir
489 _GL_FUNCDECL_RPL (mkdir
, int, (char const *name
, mode_t mode
)
490 _GL_ARG_NONNULL ((1)));
491 _GL_CXXALIAS_RPL (mkdir
, int, (char const *name
, mode_t mode
));
493 /* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
494 Additionally, it declares _mkdir (and depending on compile flags, an
495 alias mkdir), only in the nonstandard includes <direct.h> and <io.h>,
496 which are included above. */
497 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
499 # if !GNULIB_defined_rpl_mkdir
501 rpl_mkdir (char const *name
, mode_t mode
)
503 return _mkdir (name
);
505 # define GNULIB_defined_rpl_mkdir 1
508 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
509 # define mkdir rpl_mkdir
511 _GL_CXXALIAS_RPL (mkdir
, int, (char const *name
, mode_t mode
));
513 _GL_CXXALIAS_SYS (mkdir
, int, (char const *name
, mode_t mode
));
516 _GL_CXXALIASWARN (mkdir
);
521 _GL_FUNCDECL_SYS (mkdirat
, int, (int fd
, char const *file
, mode_t mode
)
522 _GL_ARG_NONNULL ((2)));
524 _GL_CXXALIAS_SYS (mkdirat
, int, (int fd
, char const *file
, mode_t mode
));
525 _GL_CXXALIASWARN (mkdirat
);
526 #elif defined GNULIB_POSIXCHECK
528 # if HAVE_RAW_DECL_MKDIRAT
529 _GL_WARN_ON_USE (mkdirat
, "mkdirat is not portable - "
530 "use gnulib module openat for portability");
536 # if @REPLACE_MKFIFO@
537 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
539 # define mkfifo rpl_mkfifo
541 _GL_FUNCDECL_RPL (mkfifo
, int, (char const *file
, mode_t mode
)
542 _GL_ARG_NONNULL ((1)));
543 _GL_CXXALIAS_RPL (mkfifo
, int, (char const *file
, mode_t mode
));
546 _GL_FUNCDECL_SYS (mkfifo
, int, (char const *file
, mode_t mode
)
547 _GL_ARG_NONNULL ((1)));
549 _GL_CXXALIAS_SYS (mkfifo
, int, (char const *file
, mode_t mode
));
551 _GL_CXXALIASWARN (mkfifo
);
552 #elif defined GNULIB_POSIXCHECK
554 # if HAVE_RAW_DECL_MKFIFO
555 _GL_WARN_ON_USE (mkfifo
, "mkfifo is not portable - "
556 "use gnulib module mkfifo for portability");
561 #if @GNULIB_MKFIFOAT@
562 # if !@HAVE_MKFIFOAT@
563 _GL_FUNCDECL_SYS (mkfifoat
, int, (int fd
, char const *file
, mode_t mode
)
564 _GL_ARG_NONNULL ((2)));
566 _GL_CXXALIAS_SYS (mkfifoat
, int, (int fd
, char const *file
, mode_t mode
));
567 _GL_CXXALIASWARN (mkfifoat
);
568 #elif defined GNULIB_POSIXCHECK
570 # if HAVE_RAW_DECL_MKFIFOAT
571 _GL_WARN_ON_USE (mkfifoat
, "mkfifoat is not portable - "
572 "use gnulib module mkfifoat for portability");
579 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
581 # define mknod rpl_mknod
583 _GL_FUNCDECL_RPL (mknod
, int, (char const *file
, mode_t mode
, dev_t dev
)
584 _GL_ARG_NONNULL ((1)));
585 _GL_CXXALIAS_RPL (mknod
, int, (char const *file
, mode_t mode
, dev_t dev
));
588 _GL_FUNCDECL_SYS (mknod
, int, (char const *file
, mode_t mode
, dev_t dev
)
589 _GL_ARG_NONNULL ((1)));
591 /* Need to cast, because on OSF/1 5.1, the third parameter is '...'. */
592 _GL_CXXALIAS_SYS_CAST (mknod
, int, (char const *file
, mode_t mode
, dev_t dev
));
594 _GL_CXXALIASWARN (mknod
);
595 #elif defined GNULIB_POSIXCHECK
597 # if HAVE_RAW_DECL_MKNOD
598 _GL_WARN_ON_USE (mknod
, "mknod is not portable - "
599 "use gnulib module mknod for portability");
606 _GL_FUNCDECL_SYS (mknodat
, int,
607 (int fd
, char const *file
, mode_t mode
, dev_t dev
)
608 _GL_ARG_NONNULL ((2)));
610 _GL_CXXALIAS_SYS (mknodat
, int,
611 (int fd
, char const *file
, mode_t mode
, dev_t dev
));
612 _GL_CXXALIASWARN (mknodat
);
613 #elif defined GNULIB_POSIXCHECK
615 # if HAVE_RAW_DECL_MKNODAT
616 _GL_WARN_ON_USE (mknodat
, "mknodat is not portable - "
617 "use gnulib module mkfifoat for portability");
624 /* We can't use the object-like #define stat rpl_stat, because of
625 struct stat. This means that rpl_stat will not be used if the user
626 does (stat)(a,b). Oh well. */
627 # if defined _AIX && defined stat && defined _LARGE_FILES
628 /* With _LARGE_FILES defined, AIX (only) defines stat to stat64,
629 so we have to replace stat64() instead of stat(). */
631 # define stat64(name, st) rpl_stat (name, st)
632 # elif @WINDOWS_64_BIT_ST_SIZE@
633 /* Above, we define stat to _stati64. */
634 # if defined __MINGW32__ && defined _stati64
635 # ifndef _USE_32BIT_TIME_T
636 /* The system headers define _stati64 to _stat64. */
638 # define _stat64(name, st) rpl_stat (name, st)
640 # elif defined _MSC_VER && defined _stati64
641 # ifdef _USE_32BIT_TIME_T
642 /* The system headers define _stati64 to _stat32i64. */
644 # define _stat32i64(name, st) rpl_stat (name, st)
646 /* The system headers define _stati64 to _stat64. */
648 # define _stat64(name, st) rpl_stat (name, st)
652 # define _stati64(name, st) rpl_stat (name, st)
654 # elif defined __MINGW32__ && defined stat
655 # ifdef _USE_32BIT_TIME_T
656 /* The system headers define stat to _stat32i64. */
658 # define _stat32i64(name, st) rpl_stat (name, st)
660 /* The system headers define stat to _stat64. */
662 # define _stat64(name, st) rpl_stat (name, st)
664 # elif defined _MSC_VER && defined stat
665 # ifdef _USE_32BIT_TIME_T
666 /* The system headers define stat to _stat32. */
668 # define _stat32(name, st) rpl_stat (name, st)
670 /* The system headers define stat to _stat64i32. */
672 # define _stat64i32(name, st) rpl_stat (name, st)
674 # else /* !(_AIX ||__MINGW32__ || _MSC_VER) */
676 # define stat(name, st) rpl_stat (name, st)
677 # endif /* !_LARGE_FILES */
678 _GL_EXTERN_C
int stat (const char *name
, struct stat
*buf
)
679 _GL_ARG_NONNULL ((1, 2));
681 #elif defined GNULIB_POSIXCHECK
683 # if HAVE_RAW_DECL_STAT
684 _GL_WARN_ON_USE (stat
, "stat is unportable - "
685 "use gnulib module stat for portability");
690 #if @GNULIB_UTIMENSAT@
691 /* Use the rpl_ prefix also on Solaris <= 9, because on Solaris 9 our utimensat
692 implementation relies on futimesat, which on Solaris 10 makes an invocation
693 to utimensat that is meant to invoke the libc's utimensat(), not gnulib's
695 # if @REPLACE_UTIMENSAT@ || (!@HAVE_UTIMENSAT@ && defined __sun)
696 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
698 # define utimensat rpl_utimensat
700 _GL_FUNCDECL_RPL (utimensat
, int, (int fd
, char const *name
,
701 struct timespec
const times
[2], int flag
)
702 _GL_ARG_NONNULL ((2)));
703 _GL_CXXALIAS_RPL (utimensat
, int, (int fd
, char const *name
,
704 struct timespec
const times
[2], int flag
));
706 # if !@HAVE_UTIMENSAT@
707 _GL_FUNCDECL_SYS (utimensat
, int, (int fd
, char const *name
,
708 struct timespec
const times
[2], int flag
)
709 _GL_ARG_NONNULL ((2)));
711 _GL_CXXALIAS_SYS (utimensat
, int, (int fd
, char const *name
,
712 struct timespec
const times
[2], int flag
));
714 # if @HAVE_UTIMENSAT@
715 _GL_CXXALIASWARN (utimensat
);
717 #elif defined GNULIB_POSIXCHECK
719 # if HAVE_RAW_DECL_UTIMENSAT
720 _GL_WARN_ON_USE (utimensat
, "utimensat is not portable - "
721 "use gnulib module utimensat for portability");
726 #endif /* _@GUARD_PREFIX@_SYS_STAT_H */
727 #endif /* _@GUARD_PREFIX@_SYS_STAT_H */