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__
59 # include <io.h> /* mingw32, mingw64 */
60 # include <direct.h> /* mingw64 */
64 # define S_IFMT 0170000
67 #if STAT_MACROS_BROKEN
83 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
91 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
99 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
101 # define S_ISDIR(m) 0
105 #ifndef S_ISDOOR /* Solaris 2.5 and up */
106 # define S_ISDOOR(m) 0
111 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
113 # define S_ISFIFO(m) 0
119 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
121 # define S_ISLNK(m) 0
125 #ifndef S_ISMPB /* V7 */
127 # define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
128 # define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
130 # define S_ISMPB(m) 0
131 # define S_ISMPC(m) 0
135 #ifndef S_ISNAM /* Xenix */
137 # define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
139 # define S_ISNAM(m) 0
143 #ifndef S_ISNWK /* HP/UX */
145 # define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
147 # define S_ISNWK(m) 0
151 #ifndef S_ISPORT /* Solaris 10 and up */
152 # define S_ISPORT(m) 0
157 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
159 # define S_ISREG(m) 0
165 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
167 # define S_ISSOCK(m) 0
173 # define S_TYPEISMQ(p) 0
177 # define S_TYPEISTMO(p) 0
183 # define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
185 # define S_TYPEISSEM(p) 0
191 # define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
193 # define S_TYPEISSHM(p) 0
197 /* high performance ("contiguous data") */
199 # define S_ISCTG(p) 0
202 /* Cray DMF (data migration facility): off line, with data */
204 # define S_ISOFD(p) 0
207 /* Cray DMF (data migration facility): off line, with no data */
209 # define S_ISOFL(p) 0
212 /* 4.4BSD whiteout */
214 # define S_ISWHT(m) 0
217 /* If any of the following are undefined,
218 define them to their de facto standard values. */
220 # define S_ISUID 04000
223 # define S_ISGID 02000
226 /* S_ISVTX is a common extension to POSIX. */
228 # define S_ISVTX 01000
231 #if !S_IRUSR && S_IREAD
232 # define S_IRUSR S_IREAD
235 # define S_IRUSR 00400
238 # define S_IRGRP (S_IRUSR >> 3)
241 # define S_IROTH (S_IRUSR >> 6)
244 #if !S_IWUSR && S_IWRITE
245 # define S_IWUSR S_IWRITE
248 # define S_IWUSR 00200
251 # define S_IWGRP (S_IWUSR >> 3)
254 # define S_IWOTH (S_IWUSR >> 6)
257 #if !S_IXUSR && S_IEXEC
258 # define S_IXUSR S_IEXEC
261 # define S_IXUSR 00100
264 # define S_IXGRP (S_IXUSR >> 3)
267 # define S_IXOTH (S_IXUSR >> 6)
271 # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
274 # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
277 # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
280 /* S_IXUGO is a common extension to POSIX. */
282 # define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
286 # define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
289 /* Macros for futimens and utimensat. */
291 # define UTIME_NOW (-1)
292 # define UTIME_OMIT (-2)
296 #if @GNULIB_FCHMODAT@
297 # if !@HAVE_FCHMODAT@
298 _GL_FUNCDECL_SYS (fchmodat
, int,
299 (int fd
, char const *file
, mode_t mode
, int flag
)
300 _GL_ARG_NONNULL ((2)));
302 _GL_CXXALIAS_SYS (fchmodat
, int,
303 (int fd
, char const *file
, mode_t mode
, int flag
));
304 _GL_CXXALIASWARN (fchmodat
);
305 #elif defined GNULIB_POSIXCHECK
307 # if HAVE_RAW_DECL_FCHMODAT
308 _GL_WARN_ON_USE (fchmodat
, "fchmodat is not portable - "
309 "use gnulib module openat for portability");
315 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
316 # define fstat rpl_fstat
318 _GL_FUNCDECL_RPL (fstat
, int, (int fd
, struct stat
*buf
) _GL_ARG_NONNULL ((2)));
319 _GL_CXXALIAS_RPL (fstat
, int, (int fd
, struct stat
*buf
));
321 _GL_CXXALIAS_SYS (fstat
, int, (int fd
, struct stat
*buf
));
323 _GL_CXXALIASWARN (fstat
);
327 # if @REPLACE_FSTATAT@
328 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
330 # define fstatat rpl_fstatat
332 _GL_FUNCDECL_RPL (fstatat
, int,
333 (int fd
, char const *name
, struct stat
*st
, int flags
)
334 _GL_ARG_NONNULL ((2, 3)));
335 _GL_CXXALIAS_RPL (fstatat
, int,
336 (int fd
, char const *name
, struct stat
*st
, int flags
));
339 _GL_FUNCDECL_SYS (fstatat
, int,
340 (int fd
, char const *name
, struct stat
*st
, int flags
)
341 _GL_ARG_NONNULL ((2, 3)));
343 _GL_CXXALIAS_SYS (fstatat
, int,
344 (int fd
, char const *name
, struct stat
*st
, int flags
));
346 _GL_CXXALIASWARN (fstatat
);
347 #elif defined GNULIB_POSIXCHECK
349 # if HAVE_RAW_DECL_FSTATAT
350 _GL_WARN_ON_USE (fstatat
, "fstatat is not portable - "
351 "use gnulib module openat for portability");
356 #if @GNULIB_FUTIMENS@
357 # if @REPLACE_FUTIMENS@
358 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
360 # define futimens rpl_futimens
362 _GL_FUNCDECL_RPL (futimens
, int, (int fd
, struct timespec
const times
[2]));
363 _GL_CXXALIAS_RPL (futimens
, int, (int fd
, struct timespec
const times
[2]));
365 # if !@HAVE_FUTIMENS@
366 _GL_FUNCDECL_SYS (futimens
, int, (int fd
, struct timespec
const times
[2]));
368 _GL_CXXALIAS_SYS (futimens
, int, (int fd
, struct timespec
const times
[2]));
370 _GL_CXXALIASWARN (futimens
);
371 #elif defined GNULIB_POSIXCHECK
373 # if HAVE_RAW_DECL_FUTIMENS
374 _GL_WARN_ON_USE (futimens
, "futimens is not portable - "
375 "use gnulib module futimens for portability");
381 /* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
382 denotes a symbolic link. */
384 /* The lchmod replacement follows symbolic links. Callers should take
385 this into account; lchmod should be applied only to arguments that
386 are known to not be symbolic links. On hosts that lack lchmod,
387 this can lead to race conditions between the check and the
388 invocation of lchmod, but we know of no workarounds that are
389 reliable in general. You might try requesting support for lchmod
390 from your operating system supplier. */
391 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
392 # define lchmod chmod
394 /* Need to cast, because on mingw, the second parameter of chmod is
396 _GL_CXXALIAS_RPL_CAST_1 (lchmod
, chmod
, int,
397 (const char *filename
, mode_t mode
));
399 # if 0 /* assume already declared */
400 _GL_FUNCDECL_SYS (lchmod
, int, (const char *filename
, mode_t mode
)
401 _GL_ARG_NONNULL ((1)));
403 _GL_CXXALIAS_SYS (lchmod
, int, (const char *filename
, mode_t mode
));
406 _GL_CXXALIASWARN (lchmod
);
408 #elif defined GNULIB_POSIXCHECK
410 # if HAVE_RAW_DECL_LCHMOD
411 _GL_WARN_ON_USE (lchmod
, "lchmod is unportable - "
412 "use gnulib module lchmod for portability");
419 /* mingw does not support symlinks, therefore it does not have lstat. But
420 without links, stat does just fine. */
421 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
424 _GL_CXXALIAS_RPL_1 (lstat
, stat
, int, (const char *name
, struct stat
*buf
));
425 # elif @REPLACE_LSTAT@
426 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
428 # define lstat rpl_lstat
430 _GL_FUNCDECL_RPL (lstat
, int, (const char *name
, struct stat
*buf
)
431 _GL_ARG_NONNULL ((1, 2)));
432 _GL_CXXALIAS_RPL (lstat
, int, (const char *name
, struct stat
*buf
));
434 _GL_CXXALIAS_SYS (lstat
, int, (const char *name
, struct stat
*buf
));
437 _GL_CXXALIASWARN (lstat
);
439 #elif defined GNULIB_POSIXCHECK
441 # if HAVE_RAW_DECL_LSTAT
442 _GL_WARN_ON_USE (lstat
, "lstat is unportable - "
443 "use gnulib module lstat for portability");
449 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
451 # define mkdir rpl_mkdir
453 _GL_FUNCDECL_RPL (mkdir
, int, (char const *name
, mode_t mode
)
454 _GL_ARG_NONNULL ((1)));
455 _GL_CXXALIAS_RPL (mkdir
, int, (char const *name
, mode_t mode
));
457 /* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
458 Additionally, it declares _mkdir (and depending on compile flags, an
459 alias mkdir), only in the nonstandard includes <direct.h> and <io.h>,
460 which are included above. */
461 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
464 rpl_mkdir (char const *name
, mode_t mode
)
466 return _mkdir (name
);
469 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
470 # define mkdir rpl_mkdir
472 _GL_CXXALIAS_RPL (mkdir
, int, (char const *name
, mode_t mode
));
474 _GL_CXXALIAS_SYS (mkdir
, int, (char const *name
, mode_t mode
));
477 _GL_CXXALIASWARN (mkdir
);
482 _GL_FUNCDECL_SYS (mkdirat
, int, (int fd
, char const *file
, mode_t mode
)
483 _GL_ARG_NONNULL ((2)));
485 _GL_CXXALIAS_SYS (mkdirat
, int, (int fd
, char const *file
, mode_t mode
));
486 _GL_CXXALIASWARN (mkdirat
);
487 #elif defined GNULIB_POSIXCHECK
489 # if HAVE_RAW_DECL_MKDIRAT
490 _GL_WARN_ON_USE (mkdirat
, "mkdirat is not portable - "
491 "use gnulib module openat for portability");
497 # if @REPLACE_MKFIFO@
498 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
500 # define mkfifo rpl_mkfifo
502 _GL_FUNCDECL_RPL (mkfifo
, int, (char const *file
, mode_t mode
)
503 _GL_ARG_NONNULL ((1)));
504 _GL_CXXALIAS_RPL (mkfifo
, int, (char const *file
, mode_t mode
));
507 _GL_FUNCDECL_SYS (mkfifo
, int, (char const *file
, mode_t mode
)
508 _GL_ARG_NONNULL ((1)));
510 _GL_CXXALIAS_SYS (mkfifo
, int, (char const *file
, mode_t mode
));
512 _GL_CXXALIASWARN (mkfifo
);
513 #elif defined GNULIB_POSIXCHECK
515 # if HAVE_RAW_DECL_MKFIFO
516 _GL_WARN_ON_USE (mkfifo
, "mkfifo is not portable - "
517 "use gnulib module mkfifo for portability");
522 #if @GNULIB_MKFIFOAT@
523 # if !@HAVE_MKFIFOAT@
524 _GL_FUNCDECL_SYS (mkfifoat
, int, (int fd
, char const *file
, mode_t mode
)
525 _GL_ARG_NONNULL ((2)));
527 _GL_CXXALIAS_SYS (mkfifoat
, int, (int fd
, char const *file
, mode_t mode
));
528 _GL_CXXALIASWARN (mkfifoat
);
529 #elif defined GNULIB_POSIXCHECK
531 # if HAVE_RAW_DECL_MKFIFOAT
532 _GL_WARN_ON_USE (mkfifoat
, "mkfifoat is not portable - "
533 "use gnulib module mkfifoat for portability");
540 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
542 # define mknod rpl_mknod
544 _GL_FUNCDECL_RPL (mknod
, int, (char const *file
, mode_t mode
, dev_t dev
)
545 _GL_ARG_NONNULL ((1)));
546 _GL_CXXALIAS_RPL (mknod
, int, (char const *file
, mode_t mode
, dev_t dev
));
549 _GL_FUNCDECL_SYS (mknod
, int, (char const *file
, mode_t mode
, dev_t dev
)
550 _GL_ARG_NONNULL ((1)));
552 _GL_CXXALIAS_SYS (mknod
, int, (char const *file
, mode_t mode
, dev_t dev
));
554 _GL_CXXALIASWARN (mknod
);
555 #elif defined GNULIB_POSIXCHECK
557 # if HAVE_RAW_DECL_MKNOD
558 _GL_WARN_ON_USE (mknod
, "mknod is not portable - "
559 "use gnulib module mknod for portability");
566 _GL_FUNCDECL_SYS (mknodat
, int,
567 (int fd
, char const *file
, mode_t mode
, dev_t dev
)
568 _GL_ARG_NONNULL ((2)));
570 _GL_CXXALIAS_SYS (mknodat
, int,
571 (int fd
, char const *file
, mode_t mode
, dev_t dev
));
572 _GL_CXXALIASWARN (mknodat
);
573 #elif defined GNULIB_POSIXCHECK
575 # if HAVE_RAW_DECL_MKNODAT
576 _GL_WARN_ON_USE (mknodat
, "mknodat is not portable - "
577 "use gnulib module mkfifoat for portability");
584 /* We can't use the object-like #define stat rpl_stat, because of
585 struct stat. This means that rpl_stat will not be used if the user
586 does (stat)(a,b). Oh well. */
589 /* With _LARGE_FILES defined, AIX (only) defines stat to stat64,
590 so we have to replace stat64() instead of stat(). */
593 # define stat64(name, st) rpl_stat (name, st)
594 # else /* !_LARGE_FILES */
595 # define stat(name, st) rpl_stat (name, st)
596 # endif /* !_LARGE_FILES */
597 _GL_EXTERN_C
int stat (const char *name
, struct stat
*buf
) _GL_ARG_NONNULL ((1, 2));
599 #elif defined GNULIB_POSIXCHECK
601 # if HAVE_RAW_DECL_STAT
602 _GL_WARN_ON_USE (stat
, "stat is unportable - "
603 "use gnulib module stat for portability");
608 #if @GNULIB_UTIMENSAT@
609 # if @REPLACE_UTIMENSAT@
610 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
612 # define utimensat rpl_utimensat
614 _GL_FUNCDECL_RPL (utimensat
, int, (int fd
, char const *name
,
615 struct timespec
const times
[2], int flag
)
616 _GL_ARG_NONNULL ((2)));
617 _GL_CXXALIAS_RPL (utimensat
, int, (int fd
, char const *name
,
618 struct timespec
const times
[2], int flag
));
620 # if !@HAVE_UTIMENSAT@
621 _GL_FUNCDECL_SYS (utimensat
, int, (int fd
, char const *name
,
622 struct timespec
const times
[2], int flag
)
623 _GL_ARG_NONNULL ((2)));
625 _GL_CXXALIAS_SYS (utimensat
, int, (int fd
, char const *name
,
626 struct timespec
const times
[2], int flag
));
628 _GL_CXXALIASWARN (utimensat
);
629 #elif defined GNULIB_POSIXCHECK
631 # if HAVE_RAW_DECL_UTIMENSAT
632 _GL_WARN_ON_USE (utimensat
, "utimensat is not portable - "
633 "use gnulib module utimensat for portability");
638 #endif /* _GL_SYS_STAT_H */
639 #endif /* _GL_SYS_STAT_H */