1 /* Provide a more complete sys/stat header file.
2 Copyright (C) 2005-2009 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 2, 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_LINK_WARNING is copied here. */
52 /* Before doing "#define mkdir rpl_mkdir" below, we need to include all
53 headers that may declare mkdir(). */
54 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
59 # define S_IFMT 0170000
62 #if STAT_MACROS_BROKEN
78 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
86 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
94 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
100 #ifndef S_ISDOOR /* Solaris 2.5 and up */
101 # define S_ISDOOR(m) 0
106 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
108 # define S_ISFIFO(m) 0
114 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
116 # define S_ISLNK(m) 0
120 #ifndef S_ISMPB /* V7 */
122 # define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
123 # define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
125 # define S_ISMPB(m) 0
126 # define S_ISMPC(m) 0
130 #ifndef S_ISNAM /* Xenix */
132 # define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
134 # define S_ISNAM(m) 0
138 #ifndef S_ISNWK /* HP/UX */
140 # define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
142 # define S_ISNWK(m) 0
146 #ifndef S_ISPORT /* Solaris 10 and up */
147 # define S_ISPORT(m) 0
152 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
154 # define S_ISREG(m) 0
160 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
162 # define S_ISSOCK(m) 0
168 # define S_TYPEISMQ(p) 0
172 # define S_TYPEISTMO(p) 0
178 # define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
180 # define S_TYPEISSEM(p) 0
186 # define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
188 # define S_TYPEISSHM(p) 0
192 /* high performance ("contiguous data") */
194 # define S_ISCTG(p) 0
197 /* Cray DMF (data migration facility): off line, with data */
199 # define S_ISOFD(p) 0
202 /* Cray DMF (data migration facility): off line, with no data */
204 # define S_ISOFL(p) 0
207 /* 4.4BSD whiteout */
209 # define S_ISWHT(m) 0
212 /* If any of the following are undefined,
213 define them to their de facto standard values. */
215 # define S_ISUID 04000
218 # define S_ISGID 02000
221 /* S_ISVTX is a common extension to POSIX. */
223 # define S_ISVTX 01000
226 #if !S_IRUSR && S_IREAD
227 # define S_IRUSR S_IREAD
230 # define S_IRUSR 00400
233 # define S_IRGRP (S_IRUSR >> 3)
236 # define S_IROTH (S_IRUSR >> 6)
239 #if !S_IWUSR && S_IWRITE
240 # define S_IWUSR S_IWRITE
243 # define S_IWUSR 00200
246 # define S_IWGRP (S_IWUSR >> 3)
249 # define S_IWOTH (S_IWUSR >> 6)
252 #if !S_IXUSR && S_IEXEC
253 # define S_IXUSR S_IEXEC
256 # define S_IXUSR 00100
259 # define S_IXGRP (S_IXUSR >> 3)
262 # define S_IXOTH (S_IXUSR >> 6)
266 # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
269 # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
272 # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
275 /* S_IXUGO is a common extension to POSIX. */
277 # define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
281 # define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
284 /* Macros for futimens and utimensat. */
286 # define UTIME_NOW (-1)
287 # define UTIME_OMIT (-2)
296 #if @GNULIB_FCHMODAT@
297 # if !@HAVE_FCHMODAT@
298 extern int fchmodat (int fd, char const *file, mode_t mode, int flag);
300 #elif defined GNULIB_POSIXCHECK
302 # define fchmodat(d,n,m,f) \
303 (GL_LINK_WARNING ("fchmodat is not portable - " \
304 "use gnulib module openat for portability"), \
305 fchmodat (d, n, m, f))
310 # define fstat rpl_fstat
311 extern int fstat (int fd, struct stat *buf);
316 # if @REPLACE_FSTATAT@
318 # define fstatat rpl_fstatat
320 # if !@HAVE_FSTATAT@ || @REPLACE_FSTATAT@
321 extern int fstatat (int fd, char const *name, struct stat *st, int flags);
323 #elif defined GNULIB_POSIXCHECK
325 # define fstatat(d,n,s,f) \
326 (GL_LINK_WARNING ("fstatat is not portable - " \
327 "use gnulib module openat for portability"), \
328 fstatat (d, n, s, f))
332 #if @GNULIB_FUTIMENS@
333 # if @REPLACE_FUTIMENS@
335 # define futimens rpl_futimens
337 # if !@HAVE_FUTIMENS@ || @REPLACE_FUTIMENS@
338 extern int futimens (int fd, struct timespec const times[2]);
340 #elif defined GNULIB_POSIXCHECK
342 # define futimens(f,t) \
343 (GL_LINK_WARNING ("futimens is not portable - " \
344 "use gnulib module futimens for portability"), \
350 /* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
351 denotes a symbolic link. */
353 /* The lchmod replacement follows symbolic links. Callers should take
354 this into account; lchmod should be applied only to arguments that
355 are known to not be symbolic links. On hosts that lack lchmod,
356 this can lead to race conditions between the check and the
357 invocation of lchmod, but we know of no workarounds that are
358 reliable in general. You might try requesting support for lchmod
359 from your operating system supplier. */
360 # define lchmod chmod
362 # if 0 /* assume already declared */
363 extern int lchmod (const char *filename, mode_t mode);
365 #elif defined GNULIB_POSIXCHECK
367 # define lchmod(f,m) \
368 (GL_LINK_WARNING ("lchmod is unportable - " \
369 "use gnulib module lchmod for portability"), \
376 /* mingw does not support symlinks, therefore it does not have lstat. But
377 without links, stat does just fine. */
379 # elif @REPLACE_LSTAT@
381 # define lstat rpl_lstat
382 extern int rpl_lstat (const char *name, struct stat *buf);
384 #elif defined GNULIB_POSIXCHECK
386 # define lstat(p,b) \
387 (GL_LINK_WARNING ("lstat is unportable - " \
388 "use gnulib module lstat for portability"), \
395 # define mkdir rpl_mkdir
396 extern int mkdir (char const *name, mode_t mode);
398 /* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
399 Additionally, it declares _mkdir (and depending on compile flags, an
400 alias mkdir), only in the nonstandard <io.h>, which is included above. */
401 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
404 rpl_mkdir (char const *name, mode_t mode)
406 return _mkdir (name);
409 # define mkdir rpl_mkdir
416 extern int mkdirat (int fd, char const *file, mode_t mode);
418 #elif defined GNULIB_POSIXCHECK
420 # define mkdirat(d,n,m) \
421 (GL_LINK_WARNING ("mkdirat is not portable - " \
422 "use gnulib module openat for portability"), \
427 #if @GNULIB_MKFIFOAT@
428 # if !@HAVE_MKFIFOAT@
429 int mkfifoat (int fd, char const *file, mode_t mode);
431 #elif defined GNULIB_POSIXCHECK
433 # define mkfifoat(d,n,m) \
434 (GL_LINK_WARNING ("mkfifoat is not portable - " \
435 "use gnulib module mkfifoat for portability"), \
442 int mknodat (int fd, char const *file, mode_t mode, dev_t dev);
444 #elif defined GNULIB_POSIXCHECK
446 # define mknodat(f,n,m,d) \
447 (GL_LINK_WARNING ("mknodat is not portable - " \
448 "use gnulib module mkfifoat for portability"), \
449 mknodat (f, n, m, d))
455 /* We can't use the object-like #define stat rpl_stat, because of
456 struct stat. This means that rpl_stat will not be used if the user
457 does (stat)(a,b). Oh well. */
460 /* With _LARGE_FILES defined, AIX (only) defines stat to stat64,
461 so we have to replace stat64() instead of stat(). */
464 # define stat64(name, st) rpl_stat (name, st)
465 # else /* !_LARGE_FILES */
466 # define stat(name, st) rpl_stat (name, st)
467 # endif /* !_LARGE_FILES */
468 extern int stat (const char *name, struct stat *buf);
470 #elif defined GNULIB_POSIXCHECK
473 (GL_LINK_WARNING ("stat is unportable - " \
474 "use gnulib module stat for portability"), \
479 #if @GNULIB_UTIMENSAT@
480 # if @REPLACE_UTIMENSAT@
482 # define utimensat rpl_utimensat
484 # if !@HAVE_UTIMENSAT@ || @REPLACE_UTIMENSAT@
485 extern int utimensat (int fd, char const *name,
486 struct timespec const times[2], int flag);
488 #elif defined GNULIB_POSIXCHECK
490 # define utimensat(d,n,t,f) \
491 (GL_LINK_WARNING ("utimensat is not portable - " \
492 "use gnulib module utimensat for portability"), \
493 utimensat (d, n, t, f))
502 #endif /* _GL_SYS_STAT_H */
503 #endif /* _GL_SYS_STAT_H */