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)
298 /* mingw does not support symlinks, therefore it does not have lstat. But
299 without links, stat does just fine. */
301 # elif @REPLACE_LSTAT@
303 # define lstat rpl_lstat
304 extern int rpl_lstat (const char *name, struct stat *buf);
306 #elif defined GNULIB_POSIXCHECK
308 # define lstat(p,b) \
309 (GL_LINK_WARNING ("lstat is unportable - " \
310 "use gnulib module lstat for portability"), \
316 /* We can't use the object-like #define stat rpl_stat, because of
317 struct stat. This means that rpl_stat will not be used if the user
318 does (stat)(a,b). Oh well. */
320 # define stat(name, st) rpl_stat (name, st)
321 extern int stat (const char *name, struct stat *buf);
323 #elif defined GNULIB_POSIXCHECK
326 (GL_LINK_WARNING ("stat is unportable - " \
327 "use gnulib module stat for portability"), \
331 #if @GNULIB_FCHMODAT@
332 # if !@HAVE_FCHMODAT@
333 extern int fchmodat (int fd, char const *file, mode_t mode, int flag);
335 #elif defined GNULIB_POSIXCHECK
337 # define fchmodat(d,n,m,f) \
338 (GL_LINK_WARNING ("fchmodat is not portable - " \
339 "use gnulib module openat for portability"), \
340 fchmodat (d, n, m, f))
345 # if @REPLACE_FSTATAT@
347 # define fstatat rpl_fstatat
349 # if !@HAVE_FSTATAT@ || @REPLACE_FSTATAT@
350 extern int fstatat (int fd, char const *name, struct stat *st, int flags);
352 #elif defined GNULIB_POSIXCHECK
354 # define fstatat(d,n,s,f) \
355 (GL_LINK_WARNING ("fstatat is not portable - " \
356 "use gnulib module openat for portability"), \
357 fstatat (d, n, s, f))
361 #if @GNULIB_FUTIMENS@
362 # if @REPLACE_FUTIMENS@
364 # define futimens rpl_futimens
366 # if !@HAVE_FUTIMENS@ || @REPLACE_FUTIMENS@
367 extern int futimens (int fd, struct timespec const times[2]);
369 #elif defined GNULIB_POSIXCHECK
371 # define futimens(f,t) \
372 (GL_LINK_WARNING ("futimens is not portable - " \
373 "use gnulib module futimens for portability"), \
380 extern int mkdirat (int fd, char const *file, mode_t mode);
382 #elif defined GNULIB_POSIXCHECK
384 # define mkdirat(d,n,m) \
385 (GL_LINK_WARNING ("mkdirat is not portable - " \
386 "use gnulib module openat for portability"), \
390 #if @GNULIB_MKFIFOAT@
391 # if !@HAVE_MKFIFOAT@
392 int mkfifoat (int fd, char const *file, mode_t mode);
394 #elif defined GNULIB_POSIXCHECK
396 # define mkfifoat(d,n,m) \
397 (GL_LINK_WARNING ("mkfifoat is not portable - " \
398 "use gnulib module mkfifoat for portability"), \
404 int mknodat (int fd, char const *file, mode_t mode, dev_t dev);
406 #elif defined GNULIB_POSIXCHECK
408 # define mknodat(f,n,m,d) \
409 (GL_LINK_WARNING ("mknodat is not portable - " \
410 "use gnulib module mkfifoat for portability"), \
411 mknodat (f, n, m, d))
415 # define fstat rpl_fstat
416 extern int fstat (int fd, struct stat *buf);
421 # define mkdir rpl_mkdir
422 extern int mkdir (char const *name, mode_t mode);
424 /* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
425 Additionally, it declares _mkdir (and depending on compile flags, an
426 alias mkdir), only in the nonstandard <io.h>, which is included above. */
427 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
430 rpl_mkdir (char const *name, mode_t mode)
432 return _mkdir (name);
435 # define mkdir rpl_mkdir
440 /* Declare BSD extensions. */
443 /* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
444 denotes a symbolic link. */
446 /* The lchmod replacement follows symbolic links. Callers should take
447 this into account; lchmod should be applied only to arguments that
448 are known to not be symbolic links. On hosts that lack lchmod,
449 this can lead to race conditions between the check and the
450 invocation of lchmod, but we know of no workarounds that are
451 reliable in general. You might try requesting support for lchmod
452 from your operating system supplier. */
453 # define lchmod chmod
455 # if 0 /* assume already declared */
456 extern int lchmod (const char *filename, mode_t mode);
458 #elif defined GNULIB_POSIXCHECK
460 # define lchmod(f,m) \
461 (GL_LINK_WARNING ("lchmod is unportable - " \
462 "use gnulib module lchmod for portability"), \
472 #endif /* _GL_SYS_STAT_H */
473 #endif /* _GL_SYS_STAT_H */