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 /* The include_next requires a split double-inclusion guard. */
42 #@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
44 #ifndef _GL_SYS_STAT_H
45 #define _GL_SYS_STAT_H
47 /* The definition of GL_LINK_WARNING is copied here. */
49 /* Before doing "#define mkdir rpl_mkdir" below, we need to include all
50 headers that may declare mkdir(). */
51 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
56 # define S_IFMT 0170000
59 #if STAT_MACROS_BROKEN
75 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
83 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
91 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
97 #ifndef S_ISDOOR /* Solaris 2.5 and up */
98 # define S_ISDOOR(m) 0
103 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
105 # define S_ISFIFO(m) 0
111 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
113 # define S_ISLNK(m) 0
117 #ifndef S_ISMPB /* V7 */
119 # define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
120 # define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
122 # define S_ISMPB(m) 0
123 # define S_ISMPC(m) 0
127 #ifndef S_ISNAM /* Xenix */
129 # define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
131 # define S_ISNAM(m) 0
135 #ifndef S_ISNWK /* HP/UX */
137 # define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
139 # define S_ISNWK(m) 0
143 #ifndef S_ISPORT /* Solaris 10 and up */
144 # define S_ISPORT(m) 0
149 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
151 # define S_ISREG(m) 0
157 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
159 # define S_ISSOCK(m) 0
165 # define S_TYPEISMQ(p) 0
169 # define S_TYPEISTMO(p) 0
175 # define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
177 # define S_TYPEISSEM(p) 0
183 # define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
185 # define S_TYPEISSHM(p) 0
189 /* high performance ("contiguous data") */
191 # define S_ISCTG(p) 0
194 /* Cray DMF (data migration facility): off line, with data */
196 # define S_ISOFD(p) 0
199 /* Cray DMF (data migration facility): off line, with no data */
201 # define S_ISOFL(p) 0
204 /* 4.4BSD whiteout */
206 # define S_ISWHT(m) 0
209 /* If any of the following are undefined,
210 define them to their de facto standard values. */
212 # define S_ISUID 04000
215 # define S_ISGID 02000
218 /* S_ISVTX is a common extension to POSIX. */
220 # define S_ISVTX 01000
223 #if !S_IRUSR && S_IREAD
224 # define S_IRUSR S_IREAD
227 # define S_IRUSR 00400
230 # define S_IRGRP (S_IRUSR >> 3)
233 # define S_IROTH (S_IRUSR >> 6)
236 #if !S_IWUSR && S_IWRITE
237 # define S_IWUSR S_IWRITE
240 # define S_IWUSR 00200
243 # define S_IWGRP (S_IWUSR >> 3)
246 # define S_IWOTH (S_IWUSR >> 6)
249 #if !S_IXUSR && S_IEXEC
250 # define S_IXUSR S_IEXEC
253 # define S_IXUSR 00100
256 # define S_IXGRP (S_IXUSR >> 3)
259 # define S_IXOTH (S_IXUSR >> 6)
263 # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
266 # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
269 # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
272 /* S_IXUGO is a common extension to POSIX. */
274 # define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
278 # define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
289 /* mingw does not support symlinks, therefore it does not have lstat. But
290 without links, stat does just fine. */
292 # elif @REPLACE_LSTAT@
294 # define lstat rpl_lstat
295 extern int rpl_lstat (const char *name, struct stat *buf);
297 #elif defined GNULIB_POSIXCHECK
299 # define lstat(p,b) \
300 (GL_LINK_WARNING ("lstat is unportable - " \
301 "use gnulib module lstat for portability"), \
308 # define mkdir rpl_mkdir
309 extern int mkdir (char const *name, mode_t mode);
311 /* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
312 Additionally, it declares _mkdir (and depending on compile flags, an
313 alias mkdir), only in the nonstandard <io.h>, which is included above. */
314 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
317 rpl_mkdir (char const *name, mode_t mode)
319 return _mkdir (name);
322 # define mkdir rpl_mkdir
327 /* Declare BSD extensions. */
330 /* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
331 denotes a symbolic link. */
333 /* The lchmod replacement follows symbolic links. Callers should take
334 this into account; lchmod should be applied only to arguments that
335 are known to not be symbolic links. On hosts that lack lchmod,
336 this can lead to race conditions between the check and the
337 invocation of lchmod, but we know of no workarounds that are
338 reliable in general. You might try requesting support for lchmod
339 from your operating system supplier. */
340 # define lchmod chmod
342 # if 0 /* assume already declared */
343 extern int lchmod (const char *filename, mode_t mode);
345 #elif defined GNULIB_POSIXCHECK
347 # define lchmod(f,m) \
348 (GL_LINK_WARNING ("lchmod is unportable - " \
349 "use gnulib module lchmod for portability"), \
359 #endif /* _GL_SYS_STAT_H */
360 #endif /* _GL_SYS_STAT_H */