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 definition of _GL_ARG_NONNULL is copied here. */
52 /* The definition of _GL_WARN_ON_USE is copied here. */
54 /* Before doing "#define mkdir rpl_mkdir" below, we need to include all
55 headers that may declare mkdir(). */
56 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
61 # define S_IFMT 0170000
64 #if STAT_MACROS_BROKEN
80 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
88 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
96 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
102 #ifndef S_ISDOOR /* Solaris 2.5 and up */
103 # define S_ISDOOR(m) 0
108 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
110 # define S_ISFIFO(m) 0
116 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
118 # define S_ISLNK(m) 0
122 #ifndef S_ISMPB /* V7 */
124 # define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
125 # define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
127 # define S_ISMPB(m) 0
128 # define S_ISMPC(m) 0
132 #ifndef S_ISNAM /* Xenix */
134 # define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
136 # define S_ISNAM(m) 0
140 #ifndef S_ISNWK /* HP/UX */
142 # define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
144 # define S_ISNWK(m) 0
148 #ifndef S_ISPORT /* Solaris 10 and up */
149 # define S_ISPORT(m) 0
154 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
156 # define S_ISREG(m) 0
162 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
164 # define S_ISSOCK(m) 0
170 # define S_TYPEISMQ(p) 0
174 # define S_TYPEISTMO(p) 0
180 # define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
182 # define S_TYPEISSEM(p) 0
188 # define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
190 # define S_TYPEISSHM(p) 0
194 /* high performance ("contiguous data") */
196 # define S_ISCTG(p) 0
199 /* Cray DMF (data migration facility): off line, with data */
201 # define S_ISOFD(p) 0
204 /* Cray DMF (data migration facility): off line, with no data */
206 # define S_ISOFL(p) 0
209 /* 4.4BSD whiteout */
211 # define S_ISWHT(m) 0
214 /* If any of the following are undefined,
215 define them to their de facto standard values. */
217 # define S_ISUID 04000
220 # define S_ISGID 02000
223 /* S_ISVTX is a common extension to POSIX. */
225 # define S_ISVTX 01000
228 #if !S_IRUSR && S_IREAD
229 # define S_IRUSR S_IREAD
232 # define S_IRUSR 00400
235 # define S_IRGRP (S_IRUSR >> 3)
238 # define S_IROTH (S_IRUSR >> 6)
241 #if !S_IWUSR && S_IWRITE
242 # define S_IWUSR S_IWRITE
245 # define S_IWUSR 00200
248 # define S_IWGRP (S_IWUSR >> 3)
251 # define S_IWOTH (S_IWUSR >> 6)
254 #if !S_IXUSR && S_IEXEC
255 # define S_IXUSR S_IEXEC
258 # define S_IXUSR 00100
261 # define S_IXGRP (S_IXUSR >> 3)
264 # define S_IXOTH (S_IXUSR >> 6)
268 # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
271 # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
274 # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
277 /* S_IXUGO is a common extension to POSIX. */
279 # define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
283 # define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
286 /* Macros for futimens and utimensat. */
288 # define UTIME_NOW (-1)
289 # define UTIME_OMIT (-2)
298 #if @GNULIB_FCHMODAT@
299 # if !@HAVE_FCHMODAT@
300 extern int fchmodat (int fd
, char const *file
, mode_t mode
, int flag
)
301 _GL_ARG_NONNULL ((2));
303 #elif defined GNULIB_POSIXCHECK
305 # if HAVE_RAW_DECL_FCHMODAT
306 _GL_WARN_ON_USE (fchmodat
, "fchmodat is not portable - "
307 "use gnulib module openat for portability");
313 # define fstat rpl_fstat
314 extern int fstat (int fd
, struct stat
*buf
) _GL_ARG_NONNULL ((2));
319 # if @REPLACE_FSTATAT@
321 # define fstatat rpl_fstatat
323 # if !@HAVE_FSTATAT@ || @REPLACE_FSTATAT@
324 extern int fstatat (int fd
, char const *name
, struct stat
*st
, int flags
)
325 _GL_ARG_NONNULL ((2, 3));
327 #elif defined GNULIB_POSIXCHECK
329 # if HAVE_RAW_DECL_FSTATAT
330 _GL_WARN_ON_USE (fstatat
, "fstatat is not portable - "
331 "use gnulib module openat for portability");
336 #if @GNULIB_FUTIMENS@
337 # if @REPLACE_FUTIMENS@
339 # define futimens rpl_futimens
341 # if !@HAVE_FUTIMENS@ || @REPLACE_FUTIMENS@
342 extern int futimens (int fd
, struct timespec
const times
[2]);
344 #elif defined GNULIB_POSIXCHECK
346 # if HAVE_RAW_DECL_FUTIMENS
347 _GL_WARN_ON_USE (futimens
, "futimens is not portable - "
348 "use gnulib module futimens for portability");
354 /* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
355 denotes a symbolic link. */
357 /* The lchmod replacement follows symbolic links. Callers should take
358 this into account; lchmod should be applied only to arguments that
359 are known to not be symbolic links. On hosts that lack lchmod,
360 this can lead to race conditions between the check and the
361 invocation of lchmod, but we know of no workarounds that are
362 reliable in general. You might try requesting support for lchmod
363 from your operating system supplier. */
364 # define lchmod chmod
366 # if 0 /* assume already declared */
367 extern int lchmod (const char *filename
, mode_t mode
) _GL_ARG_NONNULL ((1));
369 #elif defined GNULIB_POSIXCHECK
371 # if HAVE_RAW_DECL_LCHMOD
372 _GL_WARN_ON_USE (lchmod
, "lchmod is unportable - "
373 "use gnulib module lchmod for portability");
380 /* mingw does not support symlinks, therefore it does not have lstat. But
381 without links, stat does just fine. */
383 # elif @REPLACE_LSTAT@
385 # define lstat rpl_lstat
386 extern int rpl_lstat (const char *name
, struct stat
*buf
)
387 _GL_ARG_NONNULL ((1, 2));
389 #elif defined GNULIB_POSIXCHECK
391 # if HAVE_RAW_DECL_LSTAT
392 _GL_WARN_ON_USE (lstat
, "lstat is unportable - "
393 "use gnulib module lstat for portability");
400 # define mkdir rpl_mkdir
401 extern int mkdir (char const *name
, mode_t mode
) _GL_ARG_NONNULL ((1));
403 /* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
404 Additionally, it declares _mkdir (and depending on compile flags, an
405 alias mkdir), only in the nonstandard <io.h>, which is included above. */
406 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
409 rpl_mkdir (char const *name
, mode_t mode
)
411 return _mkdir (name
);
414 # define mkdir rpl_mkdir
421 extern int mkdirat (int fd
, char const *file
, mode_t mode
)
422 _GL_ARG_NONNULL ((2));
424 #elif defined GNULIB_POSIXCHECK
426 # if HAVE_RAW_DECL_MKDIRAT
427 _GL_WARN_ON_USE (mkdirat
, "mkdirat is not portable - "
428 "use gnulib module openat for portability");
434 # if @REPLACE_MKFIFO@
436 # define mkfifo rpl_mkfifo
438 # if !@HAVE_MKFIFO@ || @REPLACE_MKFIFO@
439 extern int mkfifo (char const *file
, mode_t mode
) _GL_ARG_NONNULL ((1));
441 #elif defined GNULIB_POSIXCHECK
443 # if HAVE_RAW_DECL_MKFIFO
444 _GL_WARN_ON_USE (mkfifo
, "mkfifo is not portable - "
445 "use gnulib module mkfifo for portability");
450 #if @GNULIB_MKFIFOAT@
451 # if !@HAVE_MKFIFOAT@
452 extern int mkfifoat (int fd
, char const *file
, mode_t mode
)
453 _GL_ARG_NONNULL ((2));
455 #elif defined GNULIB_POSIXCHECK
457 # if HAVE_RAW_DECL_MKFIFOAT
458 _GL_WARN_ON_USE (mkfifoat
, "mkfifoat is not portable - "
459 "use gnulib module mkfifoat for portability");
467 # define mknod rpl_mknod
469 # if !@HAVE_MKNOD@ || @REPLACE_MKNOD@
470 extern int mknod (char const *file
, mode_t mode
, dev_t dev
)
471 _GL_ARG_NONNULL ((1));
473 #elif defined GNULIB_POSIXCHECK
475 # if HAVE_RAW_DECL_MKNOD
476 _GL_WARN_ON_USE (mknod
, "mknod is not portable - "
477 "use gnulib module mknod for portability");
484 extern int mknodat (int fd
, char const *file
, mode_t mode
, dev_t dev
)
485 _GL_ARG_NONNULL ((2));
487 #elif defined GNULIB_POSIXCHECK
489 # if HAVE_RAW_DECL_MKNODAT
490 _GL_WARN_ON_USE (mknodat
, "mknodat is not portable - "
491 "use gnulib module mkfifoat for portability");
498 /* We can't use the object-like #define stat rpl_stat, because of
499 struct stat. This means that rpl_stat will not be used if the user
500 does (stat)(a,b). Oh well. */
503 /* With _LARGE_FILES defined, AIX (only) defines stat to stat64,
504 so we have to replace stat64() instead of stat(). */
507 # define stat64(name, st) rpl_stat (name, st)
508 # else /* !_LARGE_FILES */
509 # define stat(name, st) rpl_stat (name, st)
510 # endif /* !_LARGE_FILES */
511 extern int stat (const char *name
, struct stat
*buf
) _GL_ARG_NONNULL ((1, 2));
513 #elif defined GNULIB_POSIXCHECK
515 # if HAVE_RAW_DECL_STAT
516 _GL_WARN_ON_USE (stat
, "stat is unportable - "
517 "use gnulib module stat for portability");
522 #if @GNULIB_UTIMENSAT@
523 # if @REPLACE_UTIMENSAT@
525 # define utimensat rpl_utimensat
527 # if !@HAVE_UTIMENSAT@ || @REPLACE_UTIMENSAT@
528 extern int utimensat (int fd
, char const *name
,
529 struct timespec
const times
[2], int flag
)
530 _GL_ARG_NONNULL ((2));
532 #elif defined GNULIB_POSIXCHECK
534 # if HAVE_RAW_DECL_UTIMENSAT
535 _GL_WARN_ON_USE (utimensat
, "utimensat is not portable - "
536 "use gnulib module utimensat for portability");
546 #endif /* _GL_SYS_STAT_H */
547 #endif /* _GL_SYS_STAT_H */