1 /* Provide a more complete sys/stat header file.
2 Copyright (C) 2005-2010 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@
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 _GL_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 _GL_SYS_STAT_H
48 #define _GL_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(). */
58 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
63 # define S_IFMT 0170000
66 #if STAT_MACROS_BROKEN
82 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
90 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
98 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
100 # define S_ISDIR(m) 0
104 #ifndef S_ISDOOR /* Solaris 2.5 and up */
105 # define S_ISDOOR(m) 0
110 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
112 # define S_ISFIFO(m) 0
118 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
120 # define S_ISLNK(m) 0
124 #ifndef S_ISMPB /* V7 */
126 # define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
127 # define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
129 # define S_ISMPB(m) 0
130 # define S_ISMPC(m) 0
134 #ifndef S_ISNAM /* Xenix */
136 # define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
138 # define S_ISNAM(m) 0
142 #ifndef S_ISNWK /* HP/UX */
144 # define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
146 # define S_ISNWK(m) 0
150 #ifndef S_ISPORT /* Solaris 10 and up */
151 # define S_ISPORT(m) 0
156 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
158 # define S_ISREG(m) 0
164 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
166 # define S_ISSOCK(m) 0
172 # define S_TYPEISMQ(p) 0
176 # define S_TYPEISTMO(p) 0
182 # define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
184 # define S_TYPEISSEM(p) 0
190 # define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
192 # define S_TYPEISSHM(p) 0
196 /* high performance ("contiguous data") */
198 # define S_ISCTG(p) 0
201 /* Cray DMF (data migration facility): off line, with data */
203 # define S_ISOFD(p) 0
206 /* Cray DMF (data migration facility): off line, with no data */
208 # define S_ISOFL(p) 0
211 /* 4.4BSD whiteout */
213 # define S_ISWHT(m) 0
216 /* If any of the following are undefined,
217 define them to their de facto standard values. */
219 # define S_ISUID 04000
222 # define S_ISGID 02000
225 /* S_ISVTX is a common extension to POSIX. */
227 # define S_ISVTX 01000
230 #if !S_IRUSR && S_IREAD
231 # define S_IRUSR S_IREAD
234 # define S_IRUSR 00400
237 # define S_IRGRP (S_IRUSR >> 3)
240 # define S_IROTH (S_IRUSR >> 6)
243 #if !S_IWUSR && S_IWRITE
244 # define S_IWUSR S_IWRITE
247 # define S_IWUSR 00200
250 # define S_IWGRP (S_IWUSR >> 3)
253 # define S_IWOTH (S_IWUSR >> 6)
256 #if !S_IXUSR && S_IEXEC
257 # define S_IXUSR S_IEXEC
260 # define S_IXUSR 00100
263 # define S_IXGRP (S_IXUSR >> 3)
266 # define S_IXOTH (S_IXUSR >> 6)
270 # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
273 # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
276 # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
279 /* S_IXUGO is a common extension to POSIX. */
281 # define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
285 # define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
288 /* Macros for futimens and utimensat. */
290 # define UTIME_NOW (-1)
291 # define UTIME_OMIT (-2)
295 #if @GNULIB_FCHMODAT@
296 # if !@HAVE_FCHMODAT@
297 _GL_FUNCDECL_SYS (fchmodat
, int,
298 (int fd
, char const *file
, mode_t mode
, int flag
)
299 _GL_ARG_NONNULL ((2)));
301 _GL_CXXALIAS_SYS (fchmodat
, int,
302 (int fd
, char const *file
, mode_t mode
, int flag
));
303 _GL_CXXALIASWARN (fchmodat
);
304 #elif defined GNULIB_POSIXCHECK
306 # if HAVE_RAW_DECL_FCHMODAT
307 _GL_WARN_ON_USE (fchmodat
, "fchmodat is not portable - "
308 "use gnulib module openat for portability");
314 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
315 # define fstat rpl_fstat
317 _GL_FUNCDECL_RPL (fstat
, int, (int fd
, struct stat
*buf
) _GL_ARG_NONNULL ((2)));
318 _GL_CXXALIAS_RPL (fstat
, int, (int fd
, struct stat
*buf
));
320 _GL_CXXALIAS_SYS (fstat
, int, (int fd
, struct stat
*buf
));
322 _GL_CXXALIASWARN (fstat
);
326 # if @REPLACE_FSTATAT@
327 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
329 # define fstatat rpl_fstatat
331 _GL_FUNCDECL_RPL (fstatat
, int,
332 (int fd
, char const *name
, struct stat
*st
, int flags
)
333 _GL_ARG_NONNULL ((2, 3)));
334 _GL_CXXALIAS_RPL (fstatat
, int,
335 (int fd
, char const *name
, struct stat
*st
, int flags
));
338 _GL_FUNCDECL_SYS (fstatat
, int,
339 (int fd
, char const *name
, struct stat
*st
, int flags
)
340 _GL_ARG_NONNULL ((2, 3)));
342 _GL_CXXALIAS_SYS (fstatat
, int,
343 (int fd
, char const *name
, struct stat
*st
, int flags
));
345 _GL_CXXALIASWARN (fstatat
);
346 #elif defined GNULIB_POSIXCHECK
348 # if HAVE_RAW_DECL_FSTATAT
349 _GL_WARN_ON_USE (fstatat
, "fstatat is not portable - "
350 "use gnulib module openat for portability");
355 #if @GNULIB_FUTIMENS@
356 # if @REPLACE_FUTIMENS@
357 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
359 # define futimens rpl_futimens
361 _GL_FUNCDECL_RPL (futimens
, int, (int fd
, struct timespec
const times
[2]));
362 _GL_CXXALIAS_RPL (futimens
, int, (int fd
, struct timespec
const times
[2]));
364 # if !@HAVE_FUTIMENS@
365 _GL_FUNCDECL_SYS (futimens
, int, (int fd
, struct timespec
const times
[2]));
367 _GL_CXXALIAS_SYS (futimens
, int, (int fd
, struct timespec
const times
[2]));
369 _GL_CXXALIASWARN (futimens
);
370 #elif defined GNULIB_POSIXCHECK
372 # if HAVE_RAW_DECL_FUTIMENS
373 _GL_WARN_ON_USE (futimens
, "futimens is not portable - "
374 "use gnulib module futimens for portability");
380 /* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
381 denotes a symbolic link. */
383 /* The lchmod replacement follows symbolic links. Callers should take
384 this into account; lchmod should be applied only to arguments that
385 are known to not be symbolic links. On hosts that lack lchmod,
386 this can lead to race conditions between the check and the
387 invocation of lchmod, but we know of no workarounds that are
388 reliable in general. You might try requesting support for lchmod
389 from your operating system supplier. */
390 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
391 # define lchmod chmod
393 _GL_CXXALIAS_RPL_1 (lchmod
, chmod
, int, (const char *filename
, mode_t mode
));
395 # if 0 /* assume already declared */
396 _GL_FUNCDECL_SYS (lchmod
, int, (const char *filename
, mode_t mode
)
397 _GL_ARG_NONNULL ((1)));
399 _GL_CXXALIAS_SYS (lchmod
, int, (const char *filename
, mode_t mode
));
402 _GL_CXXALIASWARN (lchmod
);
404 #elif defined GNULIB_POSIXCHECK
406 # if HAVE_RAW_DECL_LCHMOD
407 _GL_WARN_ON_USE (lchmod
, "lchmod is unportable - "
408 "use gnulib module lchmod for portability");
415 /* mingw does not support symlinks, therefore it does not have lstat. But
416 without links, stat does just fine. */
417 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
420 _GL_CXXALIAS_RPL_1 (lstat
, stat
, int, (const char *name
, struct stat
*buf
));
421 # elif @REPLACE_LSTAT@
422 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
424 # define lstat rpl_lstat
426 _GL_FUNCDECL_RPL (lstat
, int, (const char *name
, struct stat
*buf
)
427 _GL_ARG_NONNULL ((1, 2)));
428 _GL_CXXALIAS_RPL (lstat
, int, (const char *name
, struct stat
*buf
));
430 _GL_CXXALIAS_SYS (lstat
, int, (const char *name
, struct stat
*buf
));
433 _GL_CXXALIASWARN (lstat
);
435 #elif defined GNULIB_POSIXCHECK
437 # if HAVE_RAW_DECL_LSTAT
438 _GL_WARN_ON_USE (lstat
, "lstat is unportable - "
439 "use gnulib module lstat for portability");
445 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
447 # define mkdir rpl_mkdir
449 _GL_FUNCDECL_RPL (mkdir
, int, (char const *name
, mode_t mode
)
450 _GL_ARG_NONNULL ((1)));
451 _GL_CXXALIAS_RPL (mkdir
, int, (char const *name
, mode_t mode
));
453 /* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
454 Additionally, it declares _mkdir (and depending on compile flags, an
455 alias mkdir), only in the nonstandard <io.h>, which is included above. */
456 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
459 rpl_mkdir (char const *name
, mode_t mode
)
461 return _mkdir (name
);
464 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
465 # define mkdir rpl_mkdir
467 _GL_CXXALIAS_RPL (mkdir
, int, (char const *name
, mode_t mode
));
469 _GL_CXXALIAS_SYS (mkdir
, int, (char const *name
, mode_t mode
));
472 _GL_CXXALIASWARN (mkdir
);
477 _GL_FUNCDECL_SYS (mkdirat
, int, (int fd
, char const *file
, mode_t mode
)
478 _GL_ARG_NONNULL ((2)));
480 _GL_CXXALIAS_SYS (mkdirat
, int, (int fd
, char const *file
, mode_t mode
));
481 _GL_CXXALIASWARN (mkdirat
);
482 #elif defined GNULIB_POSIXCHECK
484 # if HAVE_RAW_DECL_MKDIRAT
485 _GL_WARN_ON_USE (mkdirat
, "mkdirat is not portable - "
486 "use gnulib module openat for portability");
492 # if @REPLACE_MKFIFO@
493 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
495 # define mkfifo rpl_mkfifo
497 _GL_FUNCDECL_RPL (mkfifo
, int, (char const *file
, mode_t mode
)
498 _GL_ARG_NONNULL ((1)));
499 _GL_CXXALIAS_RPL (mkfifo
, int, (char const *file
, mode_t mode
));
502 _GL_FUNCDECL_SYS (mkfifo
, int, (char const *file
, mode_t mode
)
503 _GL_ARG_NONNULL ((1)));
505 _GL_CXXALIAS_SYS (mkfifo
, int, (char const *file
, mode_t mode
));
507 _GL_CXXALIASWARN (mkfifo
);
508 #elif defined GNULIB_POSIXCHECK
510 # if HAVE_RAW_DECL_MKFIFO
511 _GL_WARN_ON_USE (mkfifo
, "mkfifo is not portable - "
512 "use gnulib module mkfifo for portability");
517 #if @GNULIB_MKFIFOAT@
518 # if !@HAVE_MKFIFOAT@
519 _GL_FUNCDECL_SYS (mkfifoat
, int, (int fd
, char const *file
, mode_t mode
)
520 _GL_ARG_NONNULL ((2)));
522 _GL_CXXALIAS_SYS (mkfifoat
, int, (int fd
, char const *file
, mode_t mode
));
523 _GL_CXXALIASWARN (mkfifoat
);
524 #elif defined GNULIB_POSIXCHECK
526 # if HAVE_RAW_DECL_MKFIFOAT
527 _GL_WARN_ON_USE (mkfifoat
, "mkfifoat is not portable - "
528 "use gnulib module mkfifoat for portability");
535 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
537 # define mknod rpl_mknod
539 _GL_FUNCDECL_RPL (mknod
, int, (char const *file
, mode_t mode
, dev_t dev
)
540 _GL_ARG_NONNULL ((1)));
541 _GL_CXXALIAS_RPL (mknod
, int, (char const *file
, mode_t mode
, dev_t dev
));
544 _GL_FUNCDECL_SYS (mknod
, int, (char const *file
, mode_t mode
, dev_t dev
)
545 _GL_ARG_NONNULL ((1)));
547 _GL_CXXALIAS_SYS (mknod
, int, (char const *file
, mode_t mode
, dev_t dev
));
549 _GL_CXXALIASWARN (mknod
);
550 #elif defined GNULIB_POSIXCHECK
552 # if HAVE_RAW_DECL_MKNOD
553 _GL_WARN_ON_USE (mknod
, "mknod is not portable - "
554 "use gnulib module mknod for portability");
561 _GL_FUNCDECL_SYS (mknodat
, int,
562 (int fd
, char const *file
, mode_t mode
, dev_t dev
)
563 _GL_ARG_NONNULL ((2)));
565 _GL_CXXALIAS_SYS (mknodat
, int,
566 (int fd
, char const *file
, mode_t mode
, dev_t dev
));
567 _GL_CXXALIASWARN (mknodat
);
568 #elif defined GNULIB_POSIXCHECK
570 # if HAVE_RAW_DECL_MKNODAT
571 _GL_WARN_ON_USE (mknodat
, "mknodat is not portable - "
572 "use gnulib module mkfifoat for portability");
579 /* We can't use the object-like #define stat rpl_stat, because of
580 struct stat. This means that rpl_stat will not be used if the user
581 does (stat)(a,b). Oh well. */
584 /* With _LARGE_FILES defined, AIX (only) defines stat to stat64,
585 so we have to replace stat64() instead of stat(). */
588 # define stat64(name, st) rpl_stat (name, st)
589 # else /* !_LARGE_FILES */
590 # define stat(name, st) rpl_stat (name, st)
591 # endif /* !_LARGE_FILES */
592 _GL_EXTERN_C
int stat (const char *name
, struct stat
*buf
) _GL_ARG_NONNULL ((1, 2));
594 #elif defined GNULIB_POSIXCHECK
596 # if HAVE_RAW_DECL_STAT
597 _GL_WARN_ON_USE (stat
, "stat is unportable - "
598 "use gnulib module stat for portability");
603 #if @GNULIB_UTIMENSAT@
604 # if @REPLACE_UTIMENSAT@
605 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
607 # define utimensat rpl_utimensat
609 _GL_FUNCDECL_RPL (utimensat
, int, (int fd
, char const *name
,
610 struct timespec
const times
[2], int flag
)
611 _GL_ARG_NONNULL ((2)));
612 _GL_CXXALIAS_RPL (utimensat
, int, (int fd
, char const *name
,
613 struct timespec
const times
[2], int flag
));
615 # if !@HAVE_UTIMENSAT@
616 _GL_FUNCDECL_SYS (utimensat
, int, (int fd
, char const *name
,
617 struct timespec
const times
[2], int flag
)
618 _GL_ARG_NONNULL ((2)));
620 _GL_CXXALIAS_SYS (utimensat
, int, (int fd
, char const *name
,
621 struct timespec
const times
[2], int flag
));
623 _GL_CXXALIASWARN (utimensat
);
624 #elif defined GNULIB_POSIXCHECK
626 # if HAVE_RAW_DECL_UTIMENSAT
627 _GL_WARN_ON_USE (utimensat
, "utimensat is not portable - "
628 "use gnulib module utimensat for portability");
633 #endif /* _GL_SYS_STAT_H */
634 #endif /* _GL_SYS_STAT_H */