futimens: new module
[gnulib.git] / lib / sys_stat.in.h
1 /* Provide a more complete sys/stat header file.
2    Copyright (C) 2005-2009 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 #if __GNUC__ >= 3
25 @PRAGMA_SYSTEM_HEADER@
26 #endif
27
28 #if defined __need_system_sys_stat_h
29 /* Special invocation convention.  */
30
31 #@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
32
33 #else
34 /* Normal invocation convention.  */
35
36 #ifndef _GL_SYS_STAT_H
37
38 /* Get nlink_t.  */
39 #include <sys/types.h>
40
41 /* The include_next requires a split double-inclusion guard.  */
42 #@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
43
44 #ifndef _GL_SYS_STAT_H
45 #define _GL_SYS_STAT_H
46
47 /* The definition of GL_LINK_WARNING is copied here.  */
48
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__
52 # include <io.h>
53 #endif
54
55 #ifndef S_IFMT
56 # define S_IFMT 0170000
57 #endif
58
59 #if STAT_MACROS_BROKEN
60 # undef S_ISBLK
61 # undef S_ISCHR
62 # undef S_ISDIR
63 # undef S_ISFIFO
64 # undef S_ISLNK
65 # undef S_ISNAM
66 # undef S_ISMPB
67 # undef S_ISMPC
68 # undef S_ISNWK
69 # undef S_ISREG
70 # undef S_ISSOCK
71 #endif
72
73 #ifndef S_ISBLK
74 # ifdef S_IFBLK
75 #  define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
76 # else
77 #  define S_ISBLK(m) 0
78 # endif
79 #endif
80
81 #ifndef S_ISCHR
82 # ifdef S_IFCHR
83 #  define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
84 # else
85 #  define S_ISCHR(m) 0
86 # endif
87 #endif
88
89 #ifndef S_ISDIR
90 # ifdef S_IFDIR
91 #  define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
92 # else
93 #  define S_ISDIR(m) 0
94 # endif
95 #endif
96
97 #ifndef S_ISDOOR /* Solaris 2.5 and up */
98 # define S_ISDOOR(m) 0
99 #endif
100
101 #ifndef S_ISFIFO
102 # ifdef S_IFIFO
103 #  define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
104 # else
105 #  define S_ISFIFO(m) 0
106 # endif
107 #endif
108
109 #ifndef S_ISLNK
110 # ifdef S_IFLNK
111 #  define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
112 # else
113 #  define S_ISLNK(m) 0
114 # endif
115 #endif
116
117 #ifndef S_ISMPB /* V7 */
118 # ifdef S_IFMPB
119 #  define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
120 #  define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
121 # else
122 #  define S_ISMPB(m) 0
123 #  define S_ISMPC(m) 0
124 # endif
125 #endif
126
127 #ifndef S_ISNAM /* Xenix */
128 # ifdef S_IFNAM
129 #  define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
130 # else
131 #  define S_ISNAM(m) 0
132 # endif
133 #endif
134
135 #ifndef S_ISNWK /* HP/UX */
136 # ifdef S_IFNWK
137 #  define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
138 # else
139 #  define S_ISNWK(m) 0
140 # endif
141 #endif
142
143 #ifndef S_ISPORT /* Solaris 10 and up */
144 # define S_ISPORT(m) 0
145 #endif
146
147 #ifndef S_ISREG
148 # ifdef S_IFREG
149 #  define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
150 # else
151 #  define S_ISREG(m) 0
152 # endif
153 #endif
154
155 #ifndef S_ISSOCK
156 # ifdef S_IFSOCK
157 #  define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
158 # else
159 #  define S_ISSOCK(m) 0
160 # endif
161 #endif
162
163
164 #ifndef S_TYPEISMQ
165 # define S_TYPEISMQ(p) 0
166 #endif
167
168 #ifndef S_TYPEISTMO
169 # define S_TYPEISTMO(p) 0
170 #endif
171
172
173 #ifndef S_TYPEISSEM
174 # ifdef S_INSEM
175 #  define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
176 # else
177 #  define S_TYPEISSEM(p) 0
178 # endif
179 #endif
180
181 #ifndef S_TYPEISSHM
182 # ifdef S_INSHD
183 #  define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
184 # else
185 #  define S_TYPEISSHM(p) 0
186 # endif
187 #endif
188
189 /* high performance ("contiguous data") */
190 #ifndef S_ISCTG
191 # define S_ISCTG(p) 0
192 #endif
193
194 /* Cray DMF (data migration facility): off line, with data  */
195 #ifndef S_ISOFD
196 # define S_ISOFD(p) 0
197 #endif
198
199 /* Cray DMF (data migration facility): off line, with no data  */
200 #ifndef S_ISOFL
201 # define S_ISOFL(p) 0
202 #endif
203
204 /* 4.4BSD whiteout */
205 #ifndef S_ISWHT
206 # define S_ISWHT(m) 0
207 #endif
208
209 /* If any of the following are undefined,
210    define them to their de facto standard values.  */
211 #if !S_ISUID
212 # define S_ISUID 04000
213 #endif
214 #if !S_ISGID
215 # define S_ISGID 02000
216 #endif
217
218 /* S_ISVTX is a common extension to POSIX.  */
219 #ifndef S_ISVTX
220 # define S_ISVTX 01000
221 #endif
222
223 #if !S_IRUSR && S_IREAD
224 # define S_IRUSR S_IREAD
225 #endif
226 #if !S_IRUSR
227 # define S_IRUSR 00400
228 #endif
229 #if !S_IRGRP
230 # define S_IRGRP (S_IRUSR >> 3)
231 #endif
232 #if !S_IROTH
233 # define S_IROTH (S_IRUSR >> 6)
234 #endif
235
236 #if !S_IWUSR && S_IWRITE
237 # define S_IWUSR S_IWRITE
238 #endif
239 #if !S_IWUSR
240 # define S_IWUSR 00200
241 #endif
242 #if !S_IWGRP
243 # define S_IWGRP (S_IWUSR >> 3)
244 #endif
245 #if !S_IWOTH
246 # define S_IWOTH (S_IWUSR >> 6)
247 #endif
248
249 #if !S_IXUSR && S_IEXEC
250 # define S_IXUSR S_IEXEC
251 #endif
252 #if !S_IXUSR
253 # define S_IXUSR 00100
254 #endif
255 #if !S_IXGRP
256 # define S_IXGRP (S_IXUSR >> 3)
257 #endif
258 #if !S_IXOTH
259 # define S_IXOTH (S_IXUSR >> 6)
260 #endif
261
262 #if !S_IRWXU
263 # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
264 #endif
265 #if !S_IRWXG
266 # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
267 #endif
268 #if !S_IRWXO
269 # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
270 #endif
271
272 /* S_IXUGO is a common extension to POSIX.  */
273 #if !S_IXUGO
274 # define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
275 #endif
276
277 #ifndef S_IRWXUGO
278 # define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
279 #endif
280
281 /* Macros for futimens and utimensat.  */
282 #ifndef UTIME_NOW
283 # define UTIME_NOW (-1)
284 # define UTIME_OMIT (-2)
285 #endif
286
287
288 #ifdef __cplusplus
289 extern "C" {
290 #endif
291
292
293 #if @GNULIB_LSTAT@
294 # if ! @HAVE_LSTAT@
295 /* mingw does not support symlinks, therefore it does not have lstat.  But
296    without links, stat does just fine.  */
297 #  define lstat stat
298 # elif @REPLACE_LSTAT@
299 #  undef lstat
300 #  define lstat rpl_lstat
301 extern int rpl_lstat (const char *name, struct stat *buf);
302 # endif
303 #elif defined GNULIB_POSIXCHECK
304 # undef lstat
305 # define lstat(p,b)                                                     \
306   (GL_LINK_WARNING ("lstat is unportable - "                            \
307                     "use gnulib module lstat for portability"),         \
308    lstat (p, b))
309 #endif
310
311 #if @GNULIB_STAT@
312 # if @REPLACE_STAT@
313 /* We can't use the object-like #define stat rpl_stat, because of
314    struct stat.  This means that rpl_stat will not be used if the user
315    does (stat)(a,b).  Oh well.  */
316 #  undef stat
317 #  define stat(name, st) rpl_stat (name, st)
318 extern int stat (const char *name, struct stat *buf);
319 # endif
320 #elif defined GNULIB_POSIXCHECK
321 # undef stat
322 # define stat(p,b)                                                      \
323   (GL_LINK_WARNING ("stat is unportable - "                             \
324                     "use gnulib module stat for portability"),          \
325    stat (p, b))
326 #endif
327
328 #if @GNULIB_FCHMODAT@
329 # if !@HAVE_FCHMODAT@
330 extern int fchmodat (int fd, char const *file, mode_t mode, int flag);
331 # endif
332 #elif defined GNULIB_POSIXCHECK
333 # undef fchmodat
334 # define fchmodat(d,n,m,f)                         \
335     (GL_LINK_WARNING ("fchmodat is not portable - " \
336                       "use gnulib module openat for portability"), \
337      fchmodat (d, n, m, f))
338 #endif
339
340
341 #if @GNULIB_FSTATAT@
342 # if @REPLACE_FSTATAT@
343 #  undef fstatat
344 #  define fstatat rpl_fstatat
345 # endif
346 # if !@HAVE_FSTATAT@ || @REPLACE_FSTATAT@
347 extern int fstatat (int fd, char const *name, struct stat *st, int flags);
348 # endif
349 #elif defined GNULIB_POSIXCHECK
350 # undef fstatat
351 # define fstatat(d,n,s,f)                         \
352     (GL_LINK_WARNING ("fstatat is not portable - " \
353                       "use gnulib module openat for portability"), \
354      fstatat (d, n, s, f))
355 #endif
356
357
358 #if @GNULIB_FUTIMENS@
359 # if @REPLACE_FUTIMENS@
360 #  undef futimens
361 #  define futimens rpl_futimens
362 # endif
363 # if !@HAVE_FUTIMENS@ || @REPLACE_FUTIMENS@
364 extern int futimens (int fd, struct timespec const times[2]);
365 # endif
366 #elif defined GNULIB_POSIXCHECK
367 # undef futimens
368 # define futimens(f,t)                         \
369     (GL_LINK_WARNING ("futimens is not portable - " \
370                       "use gnulib module futimens for portability"), \
371      futimens (f, t))
372 #endif
373
374
375 #if @GNULIB_MKDIRAT@
376 # if !@HAVE_MKDIRAT@
377 extern int mkdirat (int fd, char const *file, mode_t mode);
378 # endif
379 #elif defined GNULIB_POSIXCHECK
380 # undef mkdirat
381 # define mkdirat(d,n,m)                         \
382     (GL_LINK_WARNING ("mkdirat is not portable - " \
383                       "use gnulib module openat for portability"), \
384      mkdirat (d, n, m))
385 #endif
386
387 #if @GNULIB_MKFIFOAT@
388 # if !@HAVE_MKFIFOAT@
389 int mkfifoat (int fd, char const *file, mode_t mode);
390 # endif
391 #elif defined GNULIB_POSIXCHECK
392 # undef mkfifoat
393 # define mkfifoat(d,n,m)                                     \
394     (GL_LINK_WARNING ("mkfifoat is not portable - " \
395                       "use gnulib module mkfifoat for portability"), \
396      mkfifoat (d, n, m))
397 #endif
398
399 #if @GNULIB_MKNODAT@
400 # if !@HAVE_MKNODAT@
401 int mknodat (int fd, char const *file, mode_t mode, dev_t dev);
402 # endif
403 #elif defined GNULIB_POSIXCHECK
404 # undef mknodat
405 # define mknodat(f,n,m,d)                            \
406     (GL_LINK_WARNING ("mknodat is not portable - " \
407                       "use gnulib module mkfifoat for portability"), \
408      mknodat (f, n, m, d))
409 #endif
410
411 #if @REPLACE_FSTAT@
412 # define fstat rpl_fstat
413 extern int fstat (int fd, struct stat *buf);
414 #endif
415
416 #if @REPLACE_MKDIR@
417 # undef mkdir
418 # define mkdir rpl_mkdir
419 extern int mkdir (char const *name, mode_t mode);
420 #else
421 /* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
422    Additionally, it declares _mkdir (and depending on compile flags, an
423    alias mkdir), only in the nonstandard <io.h>, which is included above.  */
424 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
425
426 static inline int
427 rpl_mkdir (char const *name, mode_t mode)
428 {
429   return _mkdir (name);
430 }
431
432 #  define mkdir rpl_mkdir
433 # endif
434 #endif
435
436
437 /* Declare BSD extensions.  */
438
439 #if @GNULIB_LCHMOD@
440 /* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
441    denotes a symbolic link.  */
442 # if !@HAVE_LCHMOD@
443 /* The lchmod replacement follows symbolic links.  Callers should take
444    this into account; lchmod should be applied only to arguments that
445    are known to not be symbolic links.  On hosts that lack lchmod,
446    this can lead to race conditions between the check and the
447    invocation of lchmod, but we know of no workarounds that are
448    reliable in general.  You might try requesting support for lchmod
449    from your operating system supplier.  */
450 #  define lchmod chmod
451 # endif
452 # if 0 /* assume already declared */
453 extern int lchmod (const char *filename, mode_t mode);
454 # endif
455 #elif defined GNULIB_POSIXCHECK
456 # undef lchmod
457 # define lchmod(f,m) \
458     (GL_LINK_WARNING ("lchmod is unportable - " \
459                       "use gnulib module lchmod for portability"), \
460      lchmod (f, m))
461 #endif
462
463
464 #ifdef __cplusplus
465 }
466 #endif
467
468
469 #endif /* _GL_SYS_STAT_H */
470 #endif /* _GL_SYS_STAT_H */
471 #endif