1 /* Provide a more complete sys/stat header file.
2 Copyright (C) 2005-2017 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_ISMPX /* AIX */
154 # define S_ISMPX(m) 0
157 #ifndef S_ISNAM /* Xenix */
159 # define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
161 # define S_ISNAM(m) 0
165 #ifndef S_ISNWK /* HP/UX */
167 # define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
169 # define S_ISNWK(m) 0
173 #ifndef S_ISPORT /* Solaris 10 and up */
174 # define S_ISPORT(m) 0
179 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
181 # define S_ISREG(m) 0
187 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
189 # define S_ISSOCK(m) 0
195 # define S_TYPEISMQ(p) 0
199 # define S_TYPEISTMO(p) 0
205 # define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
207 # define S_TYPEISSEM(p) 0
213 # define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
215 # define S_TYPEISSHM(p) 0
219 /* high performance ("contiguous data") */
221 # define S_ISCTG(p) 0
224 /* Cray DMF (data migration facility): off line, with data */
226 # define S_ISOFD(p) 0
229 /* Cray DMF (data migration facility): off line, with no data */
231 # define S_ISOFL(p) 0
234 /* 4.4BSD whiteout */
236 # define S_ISWHT(m) 0
239 /* If any of the following are undefined,
240 define them to their de facto standard values. */
242 # define S_ISUID 04000
245 # define S_ISGID 02000
248 /* S_ISVTX is a common extension to POSIX. */
250 # define S_ISVTX 01000
253 #if !S_IRUSR && S_IREAD
254 # define S_IRUSR S_IREAD
257 # define S_IRUSR 00400
260 # define S_IRGRP (S_IRUSR >> 3)
263 # define S_IROTH (S_IRUSR >> 6)
266 #if !S_IWUSR && S_IWRITE
267 # define S_IWUSR S_IWRITE
270 # define S_IWUSR 00200
273 # define S_IWGRP (S_IWUSR >> 3)
276 # define S_IWOTH (S_IWUSR >> 6)
279 #if !S_IXUSR && S_IEXEC
280 # define S_IXUSR S_IEXEC
283 # define S_IXUSR 00100
286 # define S_IXGRP (S_IXUSR >> 3)
289 # define S_IXOTH (S_IXUSR >> 6)
293 # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
296 # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
299 # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
302 /* S_IXUGO is a common extension to POSIX. */
304 # define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
308 # define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
311 /* Macros for futimens and utimensat. */
313 # define UTIME_NOW (-1)
314 # define UTIME_OMIT (-2)
318 #if @GNULIB_FCHMODAT@
319 # if !@HAVE_FCHMODAT@
320 _GL_FUNCDECL_SYS (fchmodat
, int,
321 (int fd
, char const *file
, mode_t mode
, int flag
)
322 _GL_ARG_NONNULL ((2)));
324 _GL_CXXALIAS_SYS (fchmodat
, int,
325 (int fd
, char const *file
, mode_t mode
, int flag
));
326 _GL_CXXALIASWARN (fchmodat
);
327 #elif defined GNULIB_POSIXCHECK
329 # if HAVE_RAW_DECL_FCHMODAT
330 _GL_WARN_ON_USE (fchmodat
, "fchmodat is not portable - "
331 "use gnulib module openat for portability");
338 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
340 # define fstat rpl_fstat
342 _GL_FUNCDECL_RPL (fstat
, int, (int fd
, struct stat
*buf
) _GL_ARG_NONNULL ((2)));
343 _GL_CXXALIAS_RPL (fstat
, int, (int fd
, struct stat
*buf
));
345 _GL_CXXALIAS_SYS (fstat
, int, (int fd
, struct stat
*buf
));
347 _GL_CXXALIASWARN (fstat
);
348 #elif @WINDOWS_64_BIT_ST_SIZE@
349 /* Above, we define stat to _stati64. */
350 # define fstat _fstati64
351 #elif defined GNULIB_POSIXCHECK
353 # if HAVE_RAW_DECL_FSTAT
354 _GL_WARN_ON_USE (fstat
, "fstat has portability problems - "
355 "use gnulib module fstat for portability");
361 # if @REPLACE_FSTATAT@
362 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
364 # define fstatat rpl_fstatat
366 _GL_FUNCDECL_RPL (fstatat
, int,
367 (int fd
, char const *name
, struct stat
*st
, int flags
)
368 _GL_ARG_NONNULL ((2, 3)));
369 _GL_CXXALIAS_RPL (fstatat
, int,
370 (int fd
, char const *name
, struct stat
*st
, int flags
));
373 _GL_FUNCDECL_SYS (fstatat
, int,
374 (int fd
, char const *name
, struct stat
*st
, int flags
)
375 _GL_ARG_NONNULL ((2, 3)));
377 _GL_CXXALIAS_SYS (fstatat
, int,
378 (int fd
, char const *name
, struct stat
*st
, int flags
));
380 _GL_CXXALIASWARN (fstatat
);
381 #elif defined GNULIB_POSIXCHECK
383 # if HAVE_RAW_DECL_FSTATAT
384 _GL_WARN_ON_USE (fstatat
, "fstatat is not portable - "
385 "use gnulib module openat for portability");
390 #if @GNULIB_FUTIMENS@
391 /* Use the rpl_ prefix also on Solaris <= 9, because on Solaris 9 our futimens
392 implementation relies on futimesat, which on Solaris 10 makes an invocation
393 to futimens that is meant to invoke the libc's futimens(), not gnulib's
395 # if @REPLACE_FUTIMENS@ || (!@HAVE_FUTIMENS@ && defined __sun)
396 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
398 # define futimens rpl_futimens
400 _GL_FUNCDECL_RPL (futimens
, int, (int fd
, struct timespec
const times
[2]));
401 _GL_CXXALIAS_RPL (futimens
, int, (int fd
, struct timespec
const times
[2]));
403 # if !@HAVE_FUTIMENS@
404 _GL_FUNCDECL_SYS (futimens
, int, (int fd
, struct timespec
const times
[2]));
406 _GL_CXXALIAS_SYS (futimens
, int, (int fd
, struct timespec
const times
[2]));
409 _GL_CXXALIASWARN (futimens
);
411 #elif defined GNULIB_POSIXCHECK
413 # if HAVE_RAW_DECL_FUTIMENS
414 _GL_WARN_ON_USE (futimens
, "futimens is not portable - "
415 "use gnulib module futimens for portability");
421 /* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
422 denotes a symbolic link. */
424 /* The lchmod replacement follows symbolic links. Callers should take
425 this into account; lchmod should be applied only to arguments that
426 are known to not be symbolic links. On hosts that lack lchmod,
427 this can lead to race conditions between the check and the
428 invocation of lchmod, but we know of no workarounds that are
429 reliable in general. You might try requesting support for lchmod
430 from your operating system supplier. */
431 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
432 # define lchmod chmod
434 /* Need to cast, because on mingw, the second parameter of chmod is
436 _GL_CXXALIAS_RPL_CAST_1 (lchmod
, chmod
, int,
437 (const char *filename
, mode_t mode
));
439 # if 0 /* assume already declared */
440 _GL_FUNCDECL_SYS (lchmod
, int, (const char *filename
, mode_t mode
)
441 _GL_ARG_NONNULL ((1)));
443 _GL_CXXALIAS_SYS (lchmod
, int, (const char *filename
, mode_t mode
));
446 _GL_CXXALIASWARN (lchmod
);
448 #elif defined GNULIB_POSIXCHECK
450 # if HAVE_RAW_DECL_LCHMOD
451 _GL_WARN_ON_USE (lchmod
, "lchmod is unportable - "
452 "use gnulib module lchmod for portability");
459 /* mingw does not support symlinks, therefore it does not have lstat. But
460 without links, stat does just fine. */
461 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
464 _GL_CXXALIAS_RPL_1 (lstat
, stat
, int, (const char *name
, struct stat
*buf
));
465 # elif @REPLACE_LSTAT@
466 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
468 # define lstat rpl_lstat
470 _GL_FUNCDECL_RPL (lstat
, int, (const char *name
, struct stat
*buf
)
471 _GL_ARG_NONNULL ((1, 2)));
472 _GL_CXXALIAS_RPL (lstat
, int, (const char *name
, struct stat
*buf
));
474 _GL_CXXALIAS_SYS (lstat
, int, (const char *name
, struct stat
*buf
));
477 _GL_CXXALIASWARN (lstat
);
479 #elif defined GNULIB_POSIXCHECK
481 # if HAVE_RAW_DECL_LSTAT
482 _GL_WARN_ON_USE (lstat
, "lstat is unportable - "
483 "use gnulib module lstat for portability");
489 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
491 # define mkdir rpl_mkdir
493 _GL_FUNCDECL_RPL (mkdir
, int, (char const *name
, mode_t mode
)
494 _GL_ARG_NONNULL ((1)));
495 _GL_CXXALIAS_RPL (mkdir
, int, (char const *name
, mode_t mode
));
497 /* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
498 Additionally, it declares _mkdir (and depending on compile flags, an
499 alias mkdir), only in the nonstandard includes <direct.h> and <io.h>,
500 which are included above. */
501 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
503 # if !GNULIB_defined_rpl_mkdir
505 rpl_mkdir (char const *name
, mode_t mode
)
507 return _mkdir (name
);
509 # define GNULIB_defined_rpl_mkdir 1
512 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
513 # define mkdir rpl_mkdir
515 _GL_CXXALIAS_RPL (mkdir
, int, (char const *name
, mode_t mode
));
517 _GL_CXXALIAS_SYS (mkdir
, int, (char const *name
, mode_t mode
));
520 _GL_CXXALIASWARN (mkdir
);
525 _GL_FUNCDECL_SYS (mkdirat
, int, (int fd
, char const *file
, mode_t mode
)
526 _GL_ARG_NONNULL ((2)));
528 _GL_CXXALIAS_SYS (mkdirat
, int, (int fd
, char const *file
, mode_t mode
));
529 _GL_CXXALIASWARN (mkdirat
);
530 #elif defined GNULIB_POSIXCHECK
532 # if HAVE_RAW_DECL_MKDIRAT
533 _GL_WARN_ON_USE (mkdirat
, "mkdirat is not portable - "
534 "use gnulib module openat for portability");
540 # if @REPLACE_MKFIFO@
541 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
543 # define mkfifo rpl_mkfifo
545 _GL_FUNCDECL_RPL (mkfifo
, int, (char const *file
, mode_t mode
)
546 _GL_ARG_NONNULL ((1)));
547 _GL_CXXALIAS_RPL (mkfifo
, int, (char const *file
, mode_t mode
));
550 _GL_FUNCDECL_SYS (mkfifo
, int, (char const *file
, mode_t mode
)
551 _GL_ARG_NONNULL ((1)));
553 _GL_CXXALIAS_SYS (mkfifo
, int, (char const *file
, mode_t mode
));
555 _GL_CXXALIASWARN (mkfifo
);
556 #elif defined GNULIB_POSIXCHECK
558 # if HAVE_RAW_DECL_MKFIFO
559 _GL_WARN_ON_USE (mkfifo
, "mkfifo is not portable - "
560 "use gnulib module mkfifo for portability");
565 #if @GNULIB_MKFIFOAT@
566 # if !@HAVE_MKFIFOAT@
567 _GL_FUNCDECL_SYS (mkfifoat
, int, (int fd
, char const *file
, mode_t mode
)
568 _GL_ARG_NONNULL ((2)));
570 _GL_CXXALIAS_SYS (mkfifoat
, int, (int fd
, char const *file
, mode_t mode
));
571 _GL_CXXALIASWARN (mkfifoat
);
572 #elif defined GNULIB_POSIXCHECK
574 # if HAVE_RAW_DECL_MKFIFOAT
575 _GL_WARN_ON_USE (mkfifoat
, "mkfifoat is not portable - "
576 "use gnulib module mkfifoat for portability");
583 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
585 # define mknod rpl_mknod
587 _GL_FUNCDECL_RPL (mknod
, int, (char const *file
, mode_t mode
, dev_t dev
)
588 _GL_ARG_NONNULL ((1)));
589 _GL_CXXALIAS_RPL (mknod
, int, (char const *file
, mode_t mode
, dev_t dev
));
592 _GL_FUNCDECL_SYS (mknod
, int, (char const *file
, mode_t mode
, dev_t dev
)
593 _GL_ARG_NONNULL ((1)));
595 /* Need to cast, because on OSF/1 5.1, the third parameter is '...'. */
596 _GL_CXXALIAS_SYS_CAST (mknod
, int, (char const *file
, mode_t mode
, dev_t dev
));
598 _GL_CXXALIASWARN (mknod
);
599 #elif defined GNULIB_POSIXCHECK
601 # if HAVE_RAW_DECL_MKNOD
602 _GL_WARN_ON_USE (mknod
, "mknod is not portable - "
603 "use gnulib module mknod for portability");
610 _GL_FUNCDECL_SYS (mknodat
, int,
611 (int fd
, char const *file
, mode_t mode
, dev_t dev
)
612 _GL_ARG_NONNULL ((2)));
614 _GL_CXXALIAS_SYS (mknodat
, int,
615 (int fd
, char const *file
, mode_t mode
, dev_t dev
));
616 _GL_CXXALIASWARN (mknodat
);
617 #elif defined GNULIB_POSIXCHECK
619 # if HAVE_RAW_DECL_MKNODAT
620 _GL_WARN_ON_USE (mknodat
, "mknodat is not portable - "
621 "use gnulib module mkfifoat for portability");
628 /* We can't use the object-like #define stat rpl_stat, because of
629 struct stat. This means that rpl_stat will not be used if the user
630 does (stat)(a,b). Oh well. */
631 # if defined _AIX && defined stat && defined _LARGE_FILES
632 /* With _LARGE_FILES defined, AIX (only) defines stat to stat64,
633 so we have to replace stat64() instead of stat(). */
635 # define stat64(name, st) rpl_stat (name, st)
636 # elif @WINDOWS_64_BIT_ST_SIZE@
637 /* Above, we define stat to _stati64. */
638 # if defined __MINGW32__ && defined _stati64
639 # ifndef _USE_32BIT_TIME_T
640 /* The system headers define _stati64 to _stat64. */
642 # define _stat64(name, st) rpl_stat (name, st)
644 # elif defined _MSC_VER && defined _stati64
645 # ifdef _USE_32BIT_TIME_T
646 /* The system headers define _stati64 to _stat32i64. */
648 # define _stat32i64(name, st) rpl_stat (name, st)
650 /* The system headers define _stati64 to _stat64. */
652 # define _stat64(name, st) rpl_stat (name, st)
656 # define _stati64(name, st) rpl_stat (name, st)
658 # elif defined __MINGW32__ && defined stat
659 # ifdef _USE_32BIT_TIME_T
660 /* The system headers define stat to _stat32i64. */
662 # define _stat32i64(name, st) rpl_stat (name, st)
664 /* The system headers define stat to _stat64. */
666 # define _stat64(name, st) rpl_stat (name, st)
668 # elif defined _MSC_VER && defined stat
669 # ifdef _USE_32BIT_TIME_T
670 /* The system headers define stat to _stat32. */
672 # define _stat32(name, st) rpl_stat (name, st)
674 /* The system headers define stat to _stat64i32. */
676 # define _stat64i32(name, st) rpl_stat (name, st)
678 # else /* !(_AIX ||__MINGW32__ || _MSC_VER) */
680 # define stat(name, st) rpl_stat (name, st)
681 # endif /* !_LARGE_FILES */
682 _GL_EXTERN_C
int stat (const char *name
, struct stat
*buf
)
683 _GL_ARG_NONNULL ((1, 2));
685 #elif defined GNULIB_POSIXCHECK
687 # if HAVE_RAW_DECL_STAT
688 _GL_WARN_ON_USE (stat
, "stat is unportable - "
689 "use gnulib module stat for portability");
694 #if @GNULIB_UTIMENSAT@
695 /* Use the rpl_ prefix also on Solaris <= 9, because on Solaris 9 our utimensat
696 implementation relies on futimesat, which on Solaris 10 makes an invocation
697 to utimensat that is meant to invoke the libc's utimensat(), not gnulib's
699 # if @REPLACE_UTIMENSAT@ || (!@HAVE_UTIMENSAT@ && defined __sun)
700 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
702 # define utimensat rpl_utimensat
704 _GL_FUNCDECL_RPL (utimensat
, int, (int fd
, char const *name
,
705 struct timespec
const times
[2], int flag
)
706 _GL_ARG_NONNULL ((2)));
707 _GL_CXXALIAS_RPL (utimensat
, int, (int fd
, char const *name
,
708 struct timespec
const times
[2], int flag
));
710 # if !@HAVE_UTIMENSAT@
711 _GL_FUNCDECL_SYS (utimensat
, int, (int fd
, char const *name
,
712 struct timespec
const times
[2], int flag
)
713 _GL_ARG_NONNULL ((2)));
715 _GL_CXXALIAS_SYS (utimensat
, int, (int fd
, char const *name
,
716 struct timespec
const times
[2], int flag
));
718 # if @HAVE_UTIMENSAT@
719 _GL_CXXALIASWARN (utimensat
);
721 #elif defined GNULIB_POSIXCHECK
723 # if HAVE_RAW_DECL_UTIMENSAT
724 _GL_WARN_ON_USE (utimensat
, "utimensat is not portable - "
725 "use gnulib module utimensat for portability");
730 #endif /* _@GUARD_PREFIX@_SYS_STAT_H */
731 #endif /* _@GUARD_PREFIX@_SYS_STAT_H */