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 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, 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 _GL_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 _GL_SYS_STAT_H
49 #define _GL_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(). */
59 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
60 # include <io.h> /* mingw32, mingw64 */
61 # include <direct.h> /* mingw64 */
65 # define S_IFMT 0170000
68 #if STAT_MACROS_BROKEN
84 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
92 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
100 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
102 # define S_ISDIR(m) 0
106 #ifndef S_ISDOOR /* Solaris 2.5 and up */
107 # define S_ISDOOR(m) 0
112 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
114 # define S_ISFIFO(m) 0
120 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
122 # define S_ISLNK(m) 0
126 #ifndef S_ISMPB /* V7 */
128 # define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
129 # define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
131 # define S_ISMPB(m) 0
132 # define S_ISMPC(m) 0
136 #ifndef S_ISNAM /* Xenix */
138 # define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
140 # define S_ISNAM(m) 0
144 #ifndef S_ISNWK /* HP/UX */
146 # define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
148 # define S_ISNWK(m) 0
152 #ifndef S_ISPORT /* Solaris 10 and up */
153 # define S_ISPORT(m) 0
158 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
160 # define S_ISREG(m) 0
166 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
168 # define S_ISSOCK(m) 0
174 # define S_TYPEISMQ(p) 0
178 # define S_TYPEISTMO(p) 0
184 # define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
186 # define S_TYPEISSEM(p) 0
192 # define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
194 # define S_TYPEISSHM(p) 0
198 /* high performance ("contiguous data") */
200 # define S_ISCTG(p) 0
203 /* Cray DMF (data migration facility): off line, with data */
205 # define S_ISOFD(p) 0
208 /* Cray DMF (data migration facility): off line, with no data */
210 # define S_ISOFL(p) 0
213 /* 4.4BSD whiteout */
215 # define S_ISWHT(m) 0
218 /* If any of the following are undefined,
219 define them to their de facto standard values. */
221 # define S_ISUID 04000
224 # define S_ISGID 02000
227 /* S_ISVTX is a common extension to POSIX. */
229 # define S_ISVTX 01000
232 #if !S_IRUSR && S_IREAD
233 # define S_IRUSR S_IREAD
236 # define S_IRUSR 00400
239 # define S_IRGRP (S_IRUSR >> 3)
242 # define S_IROTH (S_IRUSR >> 6)
245 #if !S_IWUSR && S_IWRITE
246 # define S_IWUSR S_IWRITE
249 # define S_IWUSR 00200
252 # define S_IWGRP (S_IWUSR >> 3)
255 # define S_IWOTH (S_IWUSR >> 6)
258 #if !S_IXUSR && S_IEXEC
259 # define S_IXUSR S_IEXEC
262 # define S_IXUSR 00100
265 # define S_IXGRP (S_IXUSR >> 3)
268 # define S_IXOTH (S_IXUSR >> 6)
272 # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
275 # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
278 # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
281 /* S_IXUGO is a common extension to POSIX. */
283 # define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
287 # define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
290 /* Macros for futimens and utimensat. */
292 # define UTIME_NOW (-1)
293 # define UTIME_OMIT (-2)
297 #if @GNULIB_FCHMODAT@
298 # if !@HAVE_FCHMODAT@
299 _GL_FUNCDECL_SYS (fchmodat
, int,
300 (int fd
, char const *file
, mode_t mode
, int flag
)
301 _GL_ARG_NONNULL ((2)));
303 _GL_CXXALIAS_SYS (fchmodat
, int,
304 (int fd
, char const *file
, mode_t mode
, int flag
));
305 _GL_CXXALIASWARN (fchmodat
);
306 #elif defined GNULIB_POSIXCHECK
308 # if HAVE_RAW_DECL_FCHMODAT
309 _GL_WARN_ON_USE (fchmodat
, "fchmodat is not portable - "
310 "use gnulib module openat for portability");
316 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
317 # define fstat rpl_fstat
319 _GL_FUNCDECL_RPL (fstat
, int, (int fd
, struct stat
*buf
) _GL_ARG_NONNULL ((2)));
320 _GL_CXXALIAS_RPL (fstat
, int, (int fd
, struct stat
*buf
));
322 _GL_CXXALIAS_SYS (fstat
, int, (int fd
, struct stat
*buf
));
324 _GL_CXXALIASWARN (fstat
);
328 # if @REPLACE_FSTATAT@
329 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
331 # define fstatat rpl_fstatat
333 _GL_FUNCDECL_RPL (fstatat
, int,
334 (int fd
, char const *name
, struct stat
*st
, int flags
)
335 _GL_ARG_NONNULL ((2, 3)));
336 _GL_CXXALIAS_RPL (fstatat
, int,
337 (int fd
, char const *name
, struct stat
*st
, int flags
));
340 _GL_FUNCDECL_SYS (fstatat
, int,
341 (int fd
, char const *name
, struct stat
*st
, int flags
)
342 _GL_ARG_NONNULL ((2, 3)));
344 _GL_CXXALIAS_SYS (fstatat
, int,
345 (int fd
, char const *name
, struct stat
*st
, int flags
));
347 _GL_CXXALIASWARN (fstatat
);
348 #elif defined GNULIB_POSIXCHECK
350 # if HAVE_RAW_DECL_FSTATAT
351 _GL_WARN_ON_USE (fstatat
, "fstatat is not portable - "
352 "use gnulib module openat for portability");
357 #if @GNULIB_FUTIMENS@
358 # if @REPLACE_FUTIMENS@
359 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
361 # define futimens rpl_futimens
363 _GL_FUNCDECL_RPL (futimens
, int, (int fd
, struct timespec
const times
[2]));
364 _GL_CXXALIAS_RPL (futimens
, int, (int fd
, struct timespec
const times
[2]));
366 # if !@HAVE_FUTIMENS@
367 _GL_FUNCDECL_SYS (futimens
, int, (int fd
, struct timespec
const times
[2]));
369 _GL_CXXALIAS_SYS (futimens
, int, (int fd
, struct timespec
const times
[2]));
371 _GL_CXXALIASWARN (futimens
);
372 #elif defined GNULIB_POSIXCHECK
374 # if HAVE_RAW_DECL_FUTIMENS
375 _GL_WARN_ON_USE (futimens
, "futimens is not portable - "
376 "use gnulib module futimens for portability");
382 /* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
383 denotes a symbolic link. */
385 /* The lchmod replacement follows symbolic links. Callers should take
386 this into account; lchmod should be applied only to arguments that
387 are known to not be symbolic links. On hosts that lack lchmod,
388 this can lead to race conditions between the check and the
389 invocation of lchmod, but we know of no workarounds that are
390 reliable in general. You might try requesting support for lchmod
391 from your operating system supplier. */
392 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
393 # define lchmod chmod
395 /* Need to cast, because on mingw, the second parameter of chmod is
397 _GL_CXXALIAS_RPL_CAST_1 (lchmod
, chmod
, int,
398 (const char *filename
, mode_t mode
));
400 # if 0 /* assume already declared */
401 _GL_FUNCDECL_SYS (lchmod
, int, (const char *filename
, mode_t mode
)
402 _GL_ARG_NONNULL ((1)));
404 _GL_CXXALIAS_SYS (lchmod
, int, (const char *filename
, mode_t mode
));
407 _GL_CXXALIASWARN (lchmod
);
409 #elif defined GNULIB_POSIXCHECK
411 # if HAVE_RAW_DECL_LCHMOD
412 _GL_WARN_ON_USE (lchmod
, "lchmod is unportable - "
413 "use gnulib module lchmod for portability");
420 /* mingw does not support symlinks, therefore it does not have lstat. But
421 without links, stat does just fine. */
422 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
425 _GL_CXXALIAS_RPL_1 (lstat
, stat
, int, (const char *name
, struct stat
*buf
));
426 # elif @REPLACE_LSTAT@
427 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
429 # define lstat rpl_lstat
431 _GL_FUNCDECL_RPL (lstat
, int, (const char *name
, struct stat
*buf
)
432 _GL_ARG_NONNULL ((1, 2)));
433 _GL_CXXALIAS_RPL (lstat
, int, (const char *name
, struct stat
*buf
));
435 _GL_CXXALIAS_SYS (lstat
, int, (const char *name
, struct stat
*buf
));
438 _GL_CXXALIASWARN (lstat
);
440 #elif defined GNULIB_POSIXCHECK
442 # if HAVE_RAW_DECL_LSTAT
443 _GL_WARN_ON_USE (lstat
, "lstat is unportable - "
444 "use gnulib module lstat for portability");
450 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
452 # define mkdir rpl_mkdir
454 _GL_FUNCDECL_RPL (mkdir
, int, (char const *name
, mode_t mode
)
455 _GL_ARG_NONNULL ((1)));
456 _GL_CXXALIAS_RPL (mkdir
, int, (char const *name
, mode_t mode
));
458 /* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
459 Additionally, it declares _mkdir (and depending on compile flags, an
460 alias mkdir), only in the nonstandard includes <direct.h> and <io.h>,
461 which are included above. */
462 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
464 # if !GNULIB_defined_rpl_mkdir
466 rpl_mkdir (char const *name
, mode_t mode
)
468 return _mkdir (name
);
470 # define GNULIB_defined_rpl_mkdir 1
473 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
474 # define mkdir rpl_mkdir
476 _GL_CXXALIAS_RPL (mkdir
, int, (char const *name
, mode_t mode
));
478 _GL_CXXALIAS_SYS (mkdir
, int, (char const *name
, mode_t mode
));
481 _GL_CXXALIASWARN (mkdir
);
486 _GL_FUNCDECL_SYS (mkdirat
, int, (int fd
, char const *file
, mode_t mode
)
487 _GL_ARG_NONNULL ((2)));
489 _GL_CXXALIAS_SYS (mkdirat
, int, (int fd
, char const *file
, mode_t mode
));
490 _GL_CXXALIASWARN (mkdirat
);
491 #elif defined GNULIB_POSIXCHECK
493 # if HAVE_RAW_DECL_MKDIRAT
494 _GL_WARN_ON_USE (mkdirat
, "mkdirat is not portable - "
495 "use gnulib module openat for portability");
501 # if @REPLACE_MKFIFO@
502 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
504 # define mkfifo rpl_mkfifo
506 _GL_FUNCDECL_RPL (mkfifo
, int, (char const *file
, mode_t mode
)
507 _GL_ARG_NONNULL ((1)));
508 _GL_CXXALIAS_RPL (mkfifo
, int, (char const *file
, mode_t mode
));
511 _GL_FUNCDECL_SYS (mkfifo
, int, (char const *file
, mode_t mode
)
512 _GL_ARG_NONNULL ((1)));
514 _GL_CXXALIAS_SYS (mkfifo
, int, (char const *file
, mode_t mode
));
516 _GL_CXXALIASWARN (mkfifo
);
517 #elif defined GNULIB_POSIXCHECK
519 # if HAVE_RAW_DECL_MKFIFO
520 _GL_WARN_ON_USE (mkfifo
, "mkfifo is not portable - "
521 "use gnulib module mkfifo for portability");
526 #if @GNULIB_MKFIFOAT@
527 # if !@HAVE_MKFIFOAT@
528 _GL_FUNCDECL_SYS (mkfifoat
, int, (int fd
, char const *file
, mode_t mode
)
529 _GL_ARG_NONNULL ((2)));
531 _GL_CXXALIAS_SYS (mkfifoat
, int, (int fd
, char const *file
, mode_t mode
));
532 _GL_CXXALIASWARN (mkfifoat
);
533 #elif defined GNULIB_POSIXCHECK
535 # if HAVE_RAW_DECL_MKFIFOAT
536 _GL_WARN_ON_USE (mkfifoat
, "mkfifoat is not portable - "
537 "use gnulib module mkfifoat for portability");
544 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
546 # define mknod rpl_mknod
548 _GL_FUNCDECL_RPL (mknod
, int, (char const *file
, mode_t mode
, dev_t dev
)
549 _GL_ARG_NONNULL ((1)));
550 _GL_CXXALIAS_RPL (mknod
, int, (char const *file
, mode_t mode
, dev_t dev
));
553 _GL_FUNCDECL_SYS (mknod
, int, (char const *file
, mode_t mode
, dev_t dev
)
554 _GL_ARG_NONNULL ((1)));
556 /* Need to cast, because on OSF/1 5.1, the third parameter is '...'. */
557 _GL_CXXALIAS_SYS_CAST (mknod
, int, (char const *file
, mode_t mode
, dev_t dev
));
559 _GL_CXXALIASWARN (mknod
);
560 #elif defined GNULIB_POSIXCHECK
562 # if HAVE_RAW_DECL_MKNOD
563 _GL_WARN_ON_USE (mknod
, "mknod is not portable - "
564 "use gnulib module mknod for portability");
571 _GL_FUNCDECL_SYS (mknodat
, int,
572 (int fd
, char const *file
, mode_t mode
, dev_t dev
)
573 _GL_ARG_NONNULL ((2)));
575 _GL_CXXALIAS_SYS (mknodat
, int,
576 (int fd
, char const *file
, mode_t mode
, dev_t dev
));
577 _GL_CXXALIASWARN (mknodat
);
578 #elif defined GNULIB_POSIXCHECK
580 # if HAVE_RAW_DECL_MKNODAT
581 _GL_WARN_ON_USE (mknodat
, "mknodat is not portable - "
582 "use gnulib module mkfifoat for portability");
589 /* We can't use the object-like #define stat rpl_stat, because of
590 struct stat. This means that rpl_stat will not be used if the user
591 does (stat)(a,b). Oh well. */
594 /* With _LARGE_FILES defined, AIX (only) defines stat to stat64,
595 so we have to replace stat64() instead of stat(). */
598 # define stat64(name, st) rpl_stat (name, st)
599 # else /* !_LARGE_FILES */
600 # define stat(name, st) rpl_stat (name, st)
601 # endif /* !_LARGE_FILES */
602 _GL_EXTERN_C
int stat (const char *name
, struct stat
*buf
)
603 _GL_ARG_NONNULL ((1, 2));
605 #elif defined GNULIB_POSIXCHECK
607 # if HAVE_RAW_DECL_STAT
608 _GL_WARN_ON_USE (stat
, "stat is unportable - "
609 "use gnulib module stat for portability");
614 #if @GNULIB_UTIMENSAT@
615 # if @REPLACE_UTIMENSAT@
616 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
618 # define utimensat rpl_utimensat
620 _GL_FUNCDECL_RPL (utimensat
, int, (int fd
, char const *name
,
621 struct timespec
const times
[2], int flag
)
622 _GL_ARG_NONNULL ((2)));
623 _GL_CXXALIAS_RPL (utimensat
, int, (int fd
, char const *name
,
624 struct timespec
const times
[2], int flag
));
626 # if !@HAVE_UTIMENSAT@
627 _GL_FUNCDECL_SYS (utimensat
, int, (int fd
, char const *name
,
628 struct timespec
const times
[2], int flag
)
629 _GL_ARG_NONNULL ((2)));
631 _GL_CXXALIAS_SYS (utimensat
, int, (int fd
, char const *name
,
632 struct timespec
const times
[2], int flag
));
634 _GL_CXXALIASWARN (utimensat
);
635 #elif defined GNULIB_POSIXCHECK
637 # if HAVE_RAW_DECL_UTIMENSAT
638 _GL_WARN_ON_USE (utimensat
, "utimensat is not portable - "
639 "use gnulib module utimensat for portability");
644 #endif /* _GL_SYS_STAT_H */
645 #endif /* _GL_SYS_STAT_H */