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 #include <sys/types.h>
41 /* Get struct timespec. */
44 /* The include_next requires a split double-inclusion guard. */
45 #@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
47 #ifndef _@GUARD_PREFIX@_SYS_STAT_H
48 #define _@GUARD_PREFIX@_SYS_STAT_H
50 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
52 /* The definition of _GL_ARG_NONNULL is copied here. */
54 /* The definition of _GL_WARN_ON_USE is copied here. */
56 /* Before doing "#define mkdir rpl_mkdir" below, we need to include all
57 headers that may declare mkdir(). Native Windows platforms declare mkdir
58 in <io.h> and/or <direct.h>, not in <unistd.h>. */
59 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
60 # include <io.h> /* mingw32, mingw64 */
61 # include <direct.h> /* mingw64, MSVC 9 */
64 /* Native Windows platforms declare umask() in <io.h>. */
65 #if 0 && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
71 # define S_IFIFO _S_IFIFO
76 # define S_IFMT 0170000
79 #if STAT_MACROS_BROKEN
95 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
103 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
105 # define S_ISCHR(m) 0
111 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
113 # define S_ISDIR(m) 0
117 #ifndef S_ISDOOR /* Solaris 2.5 and up */
118 # define S_ISDOOR(m) 0
123 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
125 # define S_ISFIFO(m) 0
131 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
133 # define S_ISLNK(m) 0
137 #ifndef S_ISMPB /* V7 */
139 # define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
140 # define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
142 # define S_ISMPB(m) 0
143 # define S_ISMPC(m) 0
147 #ifndef S_ISNAM /* Xenix */
149 # define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
151 # define S_ISNAM(m) 0
155 #ifndef S_ISNWK /* HP/UX */
157 # define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
159 # define S_ISNWK(m) 0
163 #ifndef S_ISPORT /* Solaris 10 and up */
164 # define S_ISPORT(m) 0
169 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
171 # define S_ISREG(m) 0
177 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
179 # define S_ISSOCK(m) 0
185 # define S_TYPEISMQ(p) 0
189 # define S_TYPEISTMO(p) 0
195 # define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
197 # define S_TYPEISSEM(p) 0
203 # define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
205 # define S_TYPEISSHM(p) 0
209 /* high performance ("contiguous data") */
211 # define S_ISCTG(p) 0
214 /* Cray DMF (data migration facility): off line, with data */
216 # define S_ISOFD(p) 0
219 /* Cray DMF (data migration facility): off line, with no data */
221 # define S_ISOFL(p) 0
224 /* 4.4BSD whiteout */
226 # define S_ISWHT(m) 0
229 /* If any of the following are undefined,
230 define them to their de facto standard values. */
232 # define S_ISUID 04000
235 # define S_ISGID 02000
238 /* S_ISVTX is a common extension to POSIX. */
240 # define S_ISVTX 01000
243 #if !S_IRUSR && S_IREAD
244 # define S_IRUSR S_IREAD
247 # define S_IRUSR 00400
250 # define S_IRGRP (S_IRUSR >> 3)
253 # define S_IROTH (S_IRUSR >> 6)
256 #if !S_IWUSR && S_IWRITE
257 # define S_IWUSR S_IWRITE
260 # define S_IWUSR 00200
263 # define S_IWGRP (S_IWUSR >> 3)
266 # define S_IWOTH (S_IWUSR >> 6)
269 #if !S_IXUSR && S_IEXEC
270 # define S_IXUSR S_IEXEC
273 # define S_IXUSR 00100
276 # define S_IXGRP (S_IXUSR >> 3)
279 # define S_IXOTH (S_IXUSR >> 6)
283 # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
286 # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
289 # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
292 /* S_IXUGO is a common extension to POSIX. */
294 # define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
298 # define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
301 /* Macros for futimens and utimensat. */
303 # define UTIME_NOW (-1)
304 # define UTIME_OMIT (-2)
308 #if @GNULIB_FCHMODAT@
309 # if !@HAVE_FCHMODAT@
310 _GL_FUNCDECL_SYS (fchmodat
, int,
311 (int fd
, char const *file
, mode_t mode
, int flag
)
312 _GL_ARG_NONNULL ((2)));
314 _GL_CXXALIAS_SYS (fchmodat
, int,
315 (int fd
, char const *file
, mode_t mode
, int flag
));
316 _GL_CXXALIASWARN (fchmodat
);
317 #elif defined GNULIB_POSIXCHECK
319 # if HAVE_RAW_DECL_FCHMODAT
320 _GL_WARN_ON_USE (fchmodat
, "fchmodat is not portable - "
321 "use gnulib module openat for portability");
328 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
330 # define fstat rpl_fstat
332 _GL_FUNCDECL_RPL (fstat
, int, (int fd
, struct stat
*buf
) _GL_ARG_NONNULL ((2)));
333 _GL_CXXALIAS_RPL (fstat
, int, (int fd
, struct stat
*buf
));
335 _GL_CXXALIAS_SYS (fstat
, int, (int fd
, struct stat
*buf
));
337 _GL_CXXALIASWARN (fstat
);
338 #elif defined GNULIB_POSIXCHECK
340 # if HAVE_RAW_DECL_FSTAT
341 _GL_WARN_ON_USE (fstat
, "fstat has portability problems - "
342 "use gnulib module fstat for portability");
348 # if @REPLACE_FSTATAT@
349 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
351 # define fstatat rpl_fstatat
353 _GL_FUNCDECL_RPL (fstatat
, int,
354 (int fd
, char const *name
, struct stat
*st
, int flags
)
355 _GL_ARG_NONNULL ((2, 3)));
356 _GL_CXXALIAS_RPL (fstatat
, int,
357 (int fd
, char const *name
, struct stat
*st
, int flags
));
360 _GL_FUNCDECL_SYS (fstatat
, int,
361 (int fd
, char const *name
, struct stat
*st
, int flags
)
362 _GL_ARG_NONNULL ((2, 3)));
364 _GL_CXXALIAS_SYS (fstatat
, int,
365 (int fd
, char const *name
, struct stat
*st
, int flags
));
367 _GL_CXXALIASWARN (fstatat
);
368 #elif defined GNULIB_POSIXCHECK
370 # if HAVE_RAW_DECL_FSTATAT
371 _GL_WARN_ON_USE (fstatat
, "fstatat is not portable - "
372 "use gnulib module openat for portability");
377 #if @GNULIB_FUTIMENS@
378 /* Use the rpl_ prefix also on Solaris <= 9, because on Solaris 9 our futimens
379 implementation relies on futimesat, which on Solaris 10 makes an invocation
380 to futimens that is meant to invoke the libc's futimens(), not gnulib's
382 # if @REPLACE_FUTIMENS@ || (!@HAVE_FUTIMENS@ && defined __sun)
383 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
385 # define futimens rpl_futimens
387 _GL_FUNCDECL_RPL (futimens
, int, (int fd
, struct timespec
const times
[2]));
388 _GL_CXXALIAS_RPL (futimens
, int, (int fd
, struct timespec
const times
[2]));
390 # if !@HAVE_FUTIMENS@
391 _GL_FUNCDECL_SYS (futimens
, int, (int fd
, struct timespec
const times
[2]));
393 _GL_CXXALIAS_SYS (futimens
, int, (int fd
, struct timespec
const times
[2]));
396 _GL_CXXALIASWARN (futimens
);
398 #elif defined GNULIB_POSIXCHECK
400 # if HAVE_RAW_DECL_FUTIMENS
401 _GL_WARN_ON_USE (futimens
, "futimens is not portable - "
402 "use gnulib module futimens for portability");
408 /* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
409 denotes a symbolic link. */
411 /* The lchmod replacement follows symbolic links. Callers should take
412 this into account; lchmod should be applied only to arguments that
413 are known to not be symbolic links. On hosts that lack lchmod,
414 this can lead to race conditions between the check and the
415 invocation of lchmod, but we know of no workarounds that are
416 reliable in general. You might try requesting support for lchmod
417 from your operating system supplier. */
418 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
419 # define lchmod chmod
421 /* Need to cast, because on mingw, the second parameter of chmod is
423 _GL_CXXALIAS_RPL_CAST_1 (lchmod
, chmod
, int,
424 (const char *filename
, mode_t mode
));
426 # if 0 /* assume already declared */
427 _GL_FUNCDECL_SYS (lchmod
, int, (const char *filename
, mode_t mode
)
428 _GL_ARG_NONNULL ((1)));
430 _GL_CXXALIAS_SYS (lchmod
, int, (const char *filename
, mode_t mode
));
433 _GL_CXXALIASWARN (lchmod
);
435 #elif defined GNULIB_POSIXCHECK
437 # if HAVE_RAW_DECL_LCHMOD
438 _GL_WARN_ON_USE (lchmod
, "lchmod is unportable - "
439 "use gnulib module lchmod for portability");
446 /* mingw does not support symlinks, therefore it does not have lstat. But
447 without links, stat does just fine. */
448 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
451 _GL_CXXALIAS_RPL_1 (lstat
, stat
, int, (const char *name
, struct stat
*buf
));
452 # elif @REPLACE_LSTAT@
453 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
455 # define lstat rpl_lstat
457 _GL_FUNCDECL_RPL (lstat
, int, (const char *name
, struct stat
*buf
)
458 _GL_ARG_NONNULL ((1, 2)));
459 _GL_CXXALIAS_RPL (lstat
, int, (const char *name
, struct stat
*buf
));
461 _GL_CXXALIAS_SYS (lstat
, int, (const char *name
, struct stat
*buf
));
464 _GL_CXXALIASWARN (lstat
);
466 #elif defined GNULIB_POSIXCHECK
468 # if HAVE_RAW_DECL_LSTAT
469 _GL_WARN_ON_USE (lstat
, "lstat is unportable - "
470 "use gnulib module lstat for portability");
476 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
478 # define mkdir rpl_mkdir
480 _GL_FUNCDECL_RPL (mkdir
, int, (char const *name
, mode_t mode
)
481 _GL_ARG_NONNULL ((1)));
482 _GL_CXXALIAS_RPL (mkdir
, int, (char const *name
, mode_t mode
));
484 /* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
485 Additionally, it declares _mkdir (and depending on compile flags, an
486 alias mkdir), only in the nonstandard includes <direct.h> and <io.h>,
487 which are included above. */
488 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
490 # if !GNULIB_defined_rpl_mkdir
492 rpl_mkdir (char const *name
, mode_t mode
)
494 return _mkdir (name
);
496 # define GNULIB_defined_rpl_mkdir 1
499 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
500 # define mkdir rpl_mkdir
502 _GL_CXXALIAS_RPL (mkdir
, int, (char const *name
, mode_t mode
));
504 _GL_CXXALIAS_SYS (mkdir
, int, (char const *name
, mode_t mode
));
507 _GL_CXXALIASWARN (mkdir
);
512 _GL_FUNCDECL_SYS (mkdirat
, int, (int fd
, char const *file
, mode_t mode
)
513 _GL_ARG_NONNULL ((2)));
515 _GL_CXXALIAS_SYS (mkdirat
, int, (int fd
, char const *file
, mode_t mode
));
516 _GL_CXXALIASWARN (mkdirat
);
517 #elif defined GNULIB_POSIXCHECK
519 # if HAVE_RAW_DECL_MKDIRAT
520 _GL_WARN_ON_USE (mkdirat
, "mkdirat is not portable - "
521 "use gnulib module openat for portability");
527 # if @REPLACE_MKFIFO@
528 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
530 # define mkfifo rpl_mkfifo
532 _GL_FUNCDECL_RPL (mkfifo
, int, (char const *file
, mode_t mode
)
533 _GL_ARG_NONNULL ((1)));
534 _GL_CXXALIAS_RPL (mkfifo
, int, (char const *file
, mode_t mode
));
537 _GL_FUNCDECL_SYS (mkfifo
, int, (char const *file
, mode_t mode
)
538 _GL_ARG_NONNULL ((1)));
540 _GL_CXXALIAS_SYS (mkfifo
, int, (char const *file
, mode_t mode
));
542 _GL_CXXALIASWARN (mkfifo
);
543 #elif defined GNULIB_POSIXCHECK
545 # if HAVE_RAW_DECL_MKFIFO
546 _GL_WARN_ON_USE (mkfifo
, "mkfifo is not portable - "
547 "use gnulib module mkfifo for portability");
552 #if @GNULIB_MKFIFOAT@
553 # if !@HAVE_MKFIFOAT@
554 _GL_FUNCDECL_SYS (mkfifoat
, int, (int fd
, char const *file
, mode_t mode
)
555 _GL_ARG_NONNULL ((2)));
557 _GL_CXXALIAS_SYS (mkfifoat
, int, (int fd
, char const *file
, mode_t mode
));
558 _GL_CXXALIASWARN (mkfifoat
);
559 #elif defined GNULIB_POSIXCHECK
561 # if HAVE_RAW_DECL_MKFIFOAT
562 _GL_WARN_ON_USE (mkfifoat
, "mkfifoat is not portable - "
563 "use gnulib module mkfifoat for portability");
570 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
572 # define mknod rpl_mknod
574 _GL_FUNCDECL_RPL (mknod
, int, (char const *file
, mode_t mode
, dev_t dev
)
575 _GL_ARG_NONNULL ((1)));
576 _GL_CXXALIAS_RPL (mknod
, int, (char const *file
, mode_t mode
, dev_t dev
));
579 _GL_FUNCDECL_SYS (mknod
, int, (char const *file
, mode_t mode
, dev_t dev
)
580 _GL_ARG_NONNULL ((1)));
582 /* Need to cast, because on OSF/1 5.1, the third parameter is '...'. */
583 _GL_CXXALIAS_SYS_CAST (mknod
, int, (char const *file
, mode_t mode
, dev_t dev
));
585 _GL_CXXALIASWARN (mknod
);
586 #elif defined GNULIB_POSIXCHECK
588 # if HAVE_RAW_DECL_MKNOD
589 _GL_WARN_ON_USE (mknod
, "mknod is not portable - "
590 "use gnulib module mknod for portability");
597 _GL_FUNCDECL_SYS (mknodat
, int,
598 (int fd
, char const *file
, mode_t mode
, dev_t dev
)
599 _GL_ARG_NONNULL ((2)));
601 _GL_CXXALIAS_SYS (mknodat
, int,
602 (int fd
, char const *file
, mode_t mode
, dev_t dev
));
603 _GL_CXXALIASWARN (mknodat
);
604 #elif defined GNULIB_POSIXCHECK
606 # if HAVE_RAW_DECL_MKNODAT
607 _GL_WARN_ON_USE (mknodat
, "mknodat is not portable - "
608 "use gnulib module mkfifoat for portability");
615 /* We can't use the object-like #define stat rpl_stat, because of
616 struct stat. This means that rpl_stat will not be used if the user
617 does (stat)(a,b). Oh well. */
618 # if defined _AIX && defined stat && defined _LARGE_FILES
619 /* With _LARGE_FILES defined, AIX (only) defines stat to stat64,
620 so we have to replace stat64() instead of stat(). */
622 # define stat64(name, st) rpl_stat (name, st)
623 # elif defined __MINGW32__ && defined stat
624 # ifdef _USE_32BIT_TIME_T
625 /* The system headers define stat to _stat32i64. */
627 # define _stat32i64(name, st) rpl_stat (name, st)
629 /* The system headers define stat to _stat64. */
631 # define _stat64(name, st) rpl_stat (name, st)
633 # elif defined _MSC_VER && defined stat
634 # ifdef _USE_32BIT_TIME_T
635 /* The system headers define stat to _stat32. */
637 # define _stat32(name, st) rpl_stat (name, st)
639 /* The system headers define stat to _stat64i32. */
641 # define _stat64i32(name, st) rpl_stat (name, st)
643 # else /* !(_AIX ||__MINGW32__ || _MSC_VER) */
645 # define stat(name, st) rpl_stat (name, st)
646 # endif /* !_LARGE_FILES */
647 _GL_EXTERN_C
int stat (const char *name
, struct stat
*buf
)
648 _GL_ARG_NONNULL ((1, 2));
650 #elif defined GNULIB_POSIXCHECK
652 # if HAVE_RAW_DECL_STAT
653 _GL_WARN_ON_USE (stat
, "stat is unportable - "
654 "use gnulib module stat for portability");
659 #if @GNULIB_UTIMENSAT@
660 /* Use the rpl_ prefix also on Solaris <= 9, because on Solaris 9 our utimensat
661 implementation relies on futimesat, which on Solaris 10 makes an invocation
662 to utimensat that is meant to invoke the libc's utimensat(), not gnulib's
664 # if @REPLACE_UTIMENSAT@ || (!@HAVE_UTIMENSAT@ && defined __sun)
665 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
667 # define utimensat rpl_utimensat
669 _GL_FUNCDECL_RPL (utimensat
, int, (int fd
, char const *name
,
670 struct timespec
const times
[2], int flag
)
671 _GL_ARG_NONNULL ((2)));
672 _GL_CXXALIAS_RPL (utimensat
, int, (int fd
, char const *name
,
673 struct timespec
const times
[2], int flag
));
675 # if !@HAVE_UTIMENSAT@
676 _GL_FUNCDECL_SYS (utimensat
, int, (int fd
, char const *name
,
677 struct timespec
const times
[2], int flag
)
678 _GL_ARG_NONNULL ((2)));
680 _GL_CXXALIAS_SYS (utimensat
, int, (int fd
, char const *name
,
681 struct timespec
const times
[2], int flag
));
683 # if @HAVE_UTIMENSAT@
684 _GL_CXXALIASWARN (utimensat
);
686 #elif defined GNULIB_POSIXCHECK
688 # if HAVE_RAW_DECL_UTIMENSAT
689 _GL_WARN_ON_USE (utimensat
, "utimensat is not portable - "
690 "use gnulib module utimensat for portability");
695 #endif /* _@GUARD_PREFIX@_SYS_STAT_H */
696 #endif /* _@GUARD_PREFIX@_SYS_STAT_H */