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