1/* Provide a more complete sys/stat header file.
2   Copyright (C) 2006, 2007 Free Software Foundation, Inc.
3
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)
7   any later version.
8
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.
13
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.  */
17
18/* Written by Eric Blake, Paul Eggert, and Jim Meyering.  */
19
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.  */
23
24#ifndef _GL_SYS_STAT_H
25
26/* The include_next requires a split double-inclusion guard.  */
27#if @HAVE_INCLUDE_NEXT@
28# include_next <sys/stat.h>
29#else
30# include @ABSOLUTE_SYS_STAT_H@
31#endif
32
33#ifndef _GL_SYS_STAT_H
34#define _GL_SYS_STAT_H
35
36#ifndef S_IFMT
37# define S_IFMT 0170000
38#endif
39
40#if STAT_MACROS_BROKEN
41# undef S_ISBLK
42# undef S_ISCHR
43# undef S_ISDIR
44# undef S_ISFIFO
45# undef S_ISLNK
46# undef S_ISNAM
47# undef S_ISMPB
48# undef S_ISMPC
49# undef S_ISNWK
50# undef S_ISREG
51# undef S_ISSOCK
52#endif
53
54#ifndef S_ISBLK
55# ifdef S_IFBLK
56#  define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
57# else
58#  define S_ISBLK(m) 0
59# endif
60#endif
61
62#ifndef S_ISCHR
63# ifdef S_IFCHR
64#  define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
65# else
66#  define S_ISCHR(m) 0
67# endif
68#endif
69
70#ifndef S_ISDIR
71# ifdef S_IFDIR
72#  define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
73# else
74#  define S_ISDIR(m) 0
75# endif
76#endif
77
78#ifndef S_ISDOOR /* Solaris 2.5 and up */
79# define S_ISDOOR(m) 0
80#endif
81
82#ifndef S_ISFIFO
83# ifdef S_IFIFO
84#  define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
85# else
86#  define S_ISFIFO(m) 0
87# endif
88#endif
89
90#ifndef S_ISLNK
91# ifdef S_IFLNK
92#  define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
93# else
94#  define S_ISLNK(m) 0
95# endif
96#endif
97
98#ifndef S_ISMPB /* V7 */
99# ifdef S_IFMPB
100#  define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
101#  define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
102# else
103#  define S_ISMPB(m) 0
104#  define S_ISMPC(m) 0
105# endif
106#endif
107
108#ifndef S_ISNAM /* Xenix */
109# ifdef S_IFNAM
110#  define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
111# else
112#  define S_ISNAM(m) 0
113# endif
114#endif
115
116#ifndef S_ISNWK /* HP/UX */
117# ifdef S_IFNWK
118#  define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
119# else
120#  define S_ISNWK(m) 0
121# endif
122#endif
123
124#ifndef S_ISPORT /* Solaris 10 and up */
125# define S_ISPORT(m) 0
126#endif
127
128#ifndef S_ISREG
129# ifdef S_IFREG
130#  define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
131# else
132#  define S_ISREG(m) 0
133# endif
134#endif
135
136#ifndef S_ISSOCK
137# ifdef S_IFSOCK
138#  define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
139# else
140#  define S_ISSOCK(m) 0
141# endif
142#endif
143
144
145#ifndef S_TYPEISMQ
146# define S_TYPEISMQ(p) 0
147#endif
148
149#ifndef S_TYPEISTMO
150# define S_TYPEISTMO(p) 0
151#endif
152
153
154#ifndef S_TYPEISSEM
155# ifdef S_INSEM
156#  define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
157# else
158#  define S_TYPEISSEM(p) 0
159# endif
160#endif
161
162#ifndef S_TYPEISSHM
163# ifdef S_INSHD
164#  define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
165# else
166#  define S_TYPEISSHM(p) 0
167# endif
168#endif
169
170/* high performance ("contiguous data") */
171#ifndef S_ISCTG
172# define S_ISCTG(p) 0
173#endif
174
175/* Cray DMF (data migration facility): off line, with data  */
176#ifndef S_ISOFD
177# define S_ISOFD(p) 0
178#endif
179
180/* Cray DMF (data migration facility): off line, with no data  */
181#ifndef S_ISOFL
182# define S_ISOFL(p) 0
183#endif
184
185/* 4.4BSD whiteout */
186#ifndef S_ISWHT
187# define S_ISWHT(m) 0
188#endif
189
190/* If any of the following are undefined,
191   define them to their de facto standard values.  */
192#if !S_ISUID
193# define S_ISUID 04000
194#endif
195#if !S_ISGID
196# define S_ISGID 02000
197#endif
198
199/* S_ISVTX is a common extension to POSIX.  */
200#ifndef S_ISVTX
201# define S_ISVTX 01000
202#endif
203
204#if !S_IRUSR && S_IREAD
205# define S_IRUSR S_IREAD
206#endif
207#if !S_IRUSR
208# define S_IRUSR 00400
209#endif
210#if !S_IRGRP
211# define S_IRGRP (S_IRUSR >> 3)
212#endif
213#if !S_IROTH
214# define S_IROTH (S_IRUSR >> 6)
215#endif
216
217#if !S_IWUSR && S_IWRITE
218# define S_IWUSR S_IWRITE
219#endif
220#if !S_IWUSR
221# define S_IWUSR 00200
222#endif
223#if !S_IWGRP
224# define S_IWGRP (S_IWUSR >> 3)
225#endif
226#if !S_IWOTH
227# define S_IWOTH (S_IWUSR >> 6)
228#endif
229
230#if !S_IXUSR && S_IEXEC
231# define S_IXUSR S_IEXEC
232#endif
233#if !S_IXUSR
234# define S_IXUSR 00100
235#endif
236#if !S_IXGRP
237# define S_IXGRP (S_IXUSR >> 3)
238#endif
239#if !S_IXOTH
240# define S_IXOTH (S_IXUSR >> 6)
241#endif
242
243#if !S_IRWXU
244# define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
245#endif
246#if !S_IRWXG
247# define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
248#endif
249#if !S_IRWXO
250# define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
251#endif
252
253/* S_IXUGO is a common extension to POSIX.  */
254#if !S_IXUGO
255# define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
256#endif
257
258#ifndef S_IRWXUGO
259# define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
260#endif
261
262/* mingw does not support symlinks, therefore it does not have lstat.  But
263   without links, stat does just fine.  */
264#if ! @HAVE_LSTAT@
265# define lstat stat
266#endif
267
268/* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
269   Additionally, it declares _mkdir (and depending on compile flags, an
270   alias mkdir), only in the nonstandard io.h.  */
271#if ! @HAVE_DECL_MKDIR@ && @HAVE_IO_H@
272# include <io.h>
273
274static inline int
275rpl_mkdir (char const *name, mode_t mode)
276{
277  return _mkdir (name);
278}
279
280# define mkdir rpl_mkdir
281#endif
282
283#endif /* _GL_SYS_STAT_H */
284#endif /* _GL_SYS_STAT_H */
285