1 /* Provide a more complete sys/stat header file.
2 Copyright (C) 2005-2008 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
38 /* The include_next requires a split double-inclusion guard. */
39 #@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
41 #ifndef _GL_SYS_STAT_H
42 #define _GL_SYS_STAT_H
44 /* The definition of GL_LINK_WARNING is copied here. */
46 /* Before doing "#define mkdir rpl_mkdir" below, we need to include all
47 headers that may declare mkdir(). */
48 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
53 # define S_IFMT 0170000
56 #if STAT_MACROS_BROKEN
72 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
80 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
88 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
94 #ifndef S_ISDOOR /* Solaris 2.5 and up */
95 # define S_ISDOOR(m) 0
100 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
102 # define S_ISFIFO(m) 0
108 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
110 # define S_ISLNK(m) 0
114 #ifndef S_ISMPB /* V7 */
116 # define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
117 # define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
119 # define S_ISMPB(m) 0
120 # define S_ISMPC(m) 0
124 #ifndef S_ISNAM /* Xenix */
126 # define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
128 # define S_ISNAM(m) 0
132 #ifndef S_ISNWK /* HP/UX */
134 # define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
136 # define S_ISNWK(m) 0
140 #ifndef S_ISPORT /* Solaris 10 and up */
141 # define S_ISPORT(m) 0
146 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
148 # define S_ISREG(m) 0
154 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
156 # define S_ISSOCK(m) 0
162 # define S_TYPEISMQ(p) 0
166 # define S_TYPEISTMO(p) 0
172 # define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
174 # define S_TYPEISSEM(p) 0
180 # define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
182 # define S_TYPEISSHM(p) 0
186 /* high performance ("contiguous data") */
188 # define S_ISCTG(p) 0
191 /* Cray DMF (data migration facility): off line, with data */
193 # define S_ISOFD(p) 0
196 /* Cray DMF (data migration facility): off line, with no data */
198 # define S_ISOFL(p) 0
201 /* 4.4BSD whiteout */
203 # define S_ISWHT(m) 0
206 /* If any of the following are undefined,
207 define them to their de facto standard values. */
209 # define S_ISUID 04000
212 # define S_ISGID 02000
215 /* S_ISVTX is a common extension to POSIX. */
217 # define S_ISVTX 01000
220 #if !S_IRUSR && S_IREAD
221 # define S_IRUSR S_IREAD
224 # define S_IRUSR 00400
227 # define S_IRGRP (S_IRUSR >> 3)
230 # define S_IROTH (S_IRUSR >> 6)
233 #if !S_IWUSR && S_IWRITE
234 # define S_IWUSR S_IWRITE
237 # define S_IWUSR 00200
240 # define S_IWGRP (S_IWUSR >> 3)
243 # define S_IWOTH (S_IWUSR >> 6)
246 #if !S_IXUSR && S_IEXEC
247 # define S_IXUSR S_IEXEC
250 # define S_IXUSR 00100
253 # define S_IXGRP (S_IXUSR >> 3)
256 # define S_IXOTH (S_IXUSR >> 6)
260 # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
263 # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
266 # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
269 /* S_IXUGO is a common extension to POSIX. */
271 # define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
275 # define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
280 /* mingw does not support symlinks, therefore it does not have lstat. But
281 without links, stat does just fine. */
283 # elif @REPLACE_LSTAT@
285 # define lstat rpl_lstat
286 extern int rpl_lstat (const char *name, struct stat *buf);
288 #elif defined GNULIB_POSIXCHECK
290 # define lstat(p,b) \
291 (GL_LINK_WARNING ("lstat is unportable - " \
292 "use gnulib module lstat for portability"), \
299 # define mkdir rpl_mkdir
300 extern int mkdir (char const *name, mode_t mode);
302 /* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
303 Additionally, it declares _mkdir (and depending on compile flags, an
304 alias mkdir), only in the nonstandard <io.h>, which is included above. */
305 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
308 rpl_mkdir (char const *name, mode_t mode)
310 return _mkdir (name);
313 # define mkdir rpl_mkdir
318 /* Declare BSD extensions. */
321 /* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
322 denotes a symbolic link. */
324 /* The lchmod replacement follows symbolic links. Callers should take
325 this into account; lchmod should be applied only to arguments that
326 are known to not be symbolic links. On hosts that lack lchmod,
327 this can lead to race conditions between the check and the
328 invocation of lchmod, but we know of no workarounds that are
329 reliable in general. You might try requesting support for lchmod
330 from your operating system supplier. */
331 # define lchmod chmod
333 # if 0 /* assume already declared */
334 extern int lchmod (const char *filename, mode_t mode);
336 #elif defined GNULIB_POSIXCHECK
338 # define lchmod(f,m) \
339 (GL_LINK_WARNING ("lchmod is unportable - " \
340 "use gnulib module lchmod for portability"), \
344 #endif /* _GL_SYS_STAT_H */
345 #endif /* _GL_SYS_STAT_H */