Allow check_ifstatus to accept version=2c
[monitoring-plugins.git] / gl / sys_stat.in.h
blobdc7ef51171e8c0b7a22d1a375d4478f930446988
1 /* Provide a more complete sys/stat header file.
2 Copyright (C) 2005-2010 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 3, or (at your option)
7 any later version.
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. */
24 #if __GNUC__ >= 3
25 @PRAGMA_SYSTEM_HEADER@
26 #endif
28 #if defined __need_system_sys_stat_h
29 /* Special invocation convention. */
31 #@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
33 #else
34 /* Normal invocation convention. */
36 #ifndef _GL_SYS_STAT_H
38 /* Get nlink_t. */
39 #include <sys/types.h>
41 /* Get struct timespec. */
42 #include <time.h>
44 /* The include_next requires a split double-inclusion guard. */
45 #@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
47 #ifndef _GL_SYS_STAT_H
48 #define _GL_SYS_STAT_H
50 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
52 /* The definition of _GL_ARG_NONNULL is copied here. */
54 /* The definition of _GL_WARN_ON_USE is copied here. */
56 /* Before doing "#define mkdir rpl_mkdir" below, we need to include all
57 headers that may declare mkdir(). */
58 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
59 # include <io.h> /* mingw32, mingw64 */
60 # include <direct.h> /* mingw64 */
61 #endif
63 #ifndef S_IFMT
64 # define S_IFMT 0170000
65 #endif
67 #if STAT_MACROS_BROKEN
68 # undef S_ISBLK
69 # undef S_ISCHR
70 # undef S_ISDIR
71 # undef S_ISFIFO
72 # undef S_ISLNK
73 # undef S_ISNAM
74 # undef S_ISMPB
75 # undef S_ISMPC
76 # undef S_ISNWK
77 # undef S_ISREG
78 # undef S_ISSOCK
79 #endif
81 #ifndef S_ISBLK
82 # ifdef S_IFBLK
83 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
84 # else
85 # define S_ISBLK(m) 0
86 # endif
87 #endif
89 #ifndef S_ISCHR
90 # ifdef S_IFCHR
91 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
92 # else
93 # define S_ISCHR(m) 0
94 # endif
95 #endif
97 #ifndef S_ISDIR
98 # ifdef S_IFDIR
99 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
100 # else
101 # define S_ISDIR(m) 0
102 # endif
103 #endif
105 #ifndef S_ISDOOR /* Solaris 2.5 and up */
106 # define S_ISDOOR(m) 0
107 #endif
109 #ifndef S_ISFIFO
110 # ifdef S_IFIFO
111 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
112 # else
113 # define S_ISFIFO(m) 0
114 # endif
115 #endif
117 #ifndef S_ISLNK
118 # ifdef S_IFLNK
119 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
120 # else
121 # define S_ISLNK(m) 0
122 # endif
123 #endif
125 #ifndef S_ISMPB /* V7 */
126 # ifdef S_IFMPB
127 # define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
128 # define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
129 # else
130 # define S_ISMPB(m) 0
131 # define S_ISMPC(m) 0
132 # endif
133 #endif
135 #ifndef S_ISNAM /* Xenix */
136 # ifdef S_IFNAM
137 # define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
138 # else
139 # define S_ISNAM(m) 0
140 # endif
141 #endif
143 #ifndef S_ISNWK /* HP/UX */
144 # ifdef S_IFNWK
145 # define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
146 # else
147 # define S_ISNWK(m) 0
148 # endif
149 #endif
151 #ifndef S_ISPORT /* Solaris 10 and up */
152 # define S_ISPORT(m) 0
153 #endif
155 #ifndef S_ISREG
156 # ifdef S_IFREG
157 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
158 # else
159 # define S_ISREG(m) 0
160 # endif
161 #endif
163 #ifndef S_ISSOCK
164 # ifdef S_IFSOCK
165 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
166 # else
167 # define S_ISSOCK(m) 0
168 # endif
169 #endif
172 #ifndef S_TYPEISMQ
173 # define S_TYPEISMQ(p) 0
174 #endif
176 #ifndef S_TYPEISTMO
177 # define S_TYPEISTMO(p) 0
178 #endif
181 #ifndef S_TYPEISSEM
182 # ifdef S_INSEM
183 # define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
184 # else
185 # define S_TYPEISSEM(p) 0
186 # endif
187 #endif
189 #ifndef S_TYPEISSHM
190 # ifdef S_INSHD
191 # define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
192 # else
193 # define S_TYPEISSHM(p) 0
194 # endif
195 #endif
197 /* high performance ("contiguous data") */
198 #ifndef S_ISCTG
199 # define S_ISCTG(p) 0
200 #endif
202 /* Cray DMF (data migration facility): off line, with data */
203 #ifndef S_ISOFD
204 # define S_ISOFD(p) 0
205 #endif
207 /* Cray DMF (data migration facility): off line, with no data */
208 #ifndef S_ISOFL
209 # define S_ISOFL(p) 0
210 #endif
212 /* 4.4BSD whiteout */
213 #ifndef S_ISWHT
214 # define S_ISWHT(m) 0
215 #endif
217 /* If any of the following are undefined,
218 define them to their de facto standard values. */
219 #if !S_ISUID
220 # define S_ISUID 04000
221 #endif
222 #if !S_ISGID
223 # define S_ISGID 02000
224 #endif
226 /* S_ISVTX is a common extension to POSIX. */
227 #ifndef S_ISVTX
228 # define S_ISVTX 01000
229 #endif
231 #if !S_IRUSR && S_IREAD
232 # define S_IRUSR S_IREAD
233 #endif
234 #if !S_IRUSR
235 # define S_IRUSR 00400
236 #endif
237 #if !S_IRGRP
238 # define S_IRGRP (S_IRUSR >> 3)
239 #endif
240 #if !S_IROTH
241 # define S_IROTH (S_IRUSR >> 6)
242 #endif
244 #if !S_IWUSR && S_IWRITE
245 # define S_IWUSR S_IWRITE
246 #endif
247 #if !S_IWUSR
248 # define S_IWUSR 00200
249 #endif
250 #if !S_IWGRP
251 # define S_IWGRP (S_IWUSR >> 3)
252 #endif
253 #if !S_IWOTH
254 # define S_IWOTH (S_IWUSR >> 6)
255 #endif
257 #if !S_IXUSR && S_IEXEC
258 # define S_IXUSR S_IEXEC
259 #endif
260 #if !S_IXUSR
261 # define S_IXUSR 00100
262 #endif
263 #if !S_IXGRP
264 # define S_IXGRP (S_IXUSR >> 3)
265 #endif
266 #if !S_IXOTH
267 # define S_IXOTH (S_IXUSR >> 6)
268 #endif
270 #if !S_IRWXU
271 # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
272 #endif
273 #if !S_IRWXG
274 # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
275 #endif
276 #if !S_IRWXO
277 # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
278 #endif
280 /* S_IXUGO is a common extension to POSIX. */
281 #if !S_IXUGO
282 # define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
283 #endif
285 #ifndef S_IRWXUGO
286 # define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
287 #endif
289 /* Macros for futimens and utimensat. */
290 #ifndef UTIME_NOW
291 # define UTIME_NOW (-1)
292 # define UTIME_OMIT (-2)
293 #endif
296 #if @GNULIB_FCHMODAT@
297 # if !@HAVE_FCHMODAT@
298 _GL_FUNCDECL_SYS (fchmodat, int,
299 (int fd, char const *file, mode_t mode, int flag)
300 _GL_ARG_NONNULL ((2)));
301 # endif
302 _GL_CXXALIAS_SYS (fchmodat, int,
303 (int fd, char const *file, mode_t mode, int flag));
304 _GL_CXXALIASWARN (fchmodat);
305 #elif defined GNULIB_POSIXCHECK
306 # undef fchmodat
307 # if HAVE_RAW_DECL_FCHMODAT
308 _GL_WARN_ON_USE (fchmodat, "fchmodat is not portable - "
309 "use gnulib module openat for portability");
310 # endif
311 #endif
314 #if @REPLACE_FSTAT@
315 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
316 # define fstat rpl_fstat
317 # endif
318 _GL_FUNCDECL_RPL (fstat, int, (int fd, struct stat *buf) _GL_ARG_NONNULL ((2)));
319 _GL_CXXALIAS_RPL (fstat, int, (int fd, struct stat *buf));
320 #else
321 _GL_CXXALIAS_SYS (fstat, int, (int fd, struct stat *buf));
322 #endif
323 _GL_CXXALIASWARN (fstat);
326 #if @GNULIB_FSTATAT@
327 # if @REPLACE_FSTATAT@
328 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
329 # undef fstatat
330 # define fstatat rpl_fstatat
331 # endif
332 _GL_FUNCDECL_RPL (fstatat, int,
333 (int fd, char const *name, struct stat *st, int flags)
334 _GL_ARG_NONNULL ((2, 3)));
335 _GL_CXXALIAS_RPL (fstatat, int,
336 (int fd, char const *name, struct stat *st, int flags));
337 # else
338 # if !@HAVE_FSTATAT@
339 _GL_FUNCDECL_SYS (fstatat, int,
340 (int fd, char const *name, struct stat *st, int flags)
341 _GL_ARG_NONNULL ((2, 3)));
342 # endif
343 _GL_CXXALIAS_SYS (fstatat, int,
344 (int fd, char const *name, struct stat *st, int flags));
345 # endif
346 _GL_CXXALIASWARN (fstatat);
347 #elif defined GNULIB_POSIXCHECK
348 # undef fstatat
349 # if HAVE_RAW_DECL_FSTATAT
350 _GL_WARN_ON_USE (fstatat, "fstatat is not portable - "
351 "use gnulib module openat for portability");
352 # endif
353 #endif
356 #if @GNULIB_FUTIMENS@
357 # if @REPLACE_FUTIMENS@
358 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
359 # undef futimens
360 # define futimens rpl_futimens
361 # endif
362 _GL_FUNCDECL_RPL (futimens, int, (int fd, struct timespec const times[2]));
363 _GL_CXXALIAS_RPL (futimens, int, (int fd, struct timespec const times[2]));
364 # else
365 # if !@HAVE_FUTIMENS@
366 _GL_FUNCDECL_SYS (futimens, int, (int fd, struct timespec const times[2]));
367 # endif
368 _GL_CXXALIAS_SYS (futimens, int, (int fd, struct timespec const times[2]));
369 # endif
370 _GL_CXXALIASWARN (futimens);
371 #elif defined GNULIB_POSIXCHECK
372 # undef futimens
373 # if HAVE_RAW_DECL_FUTIMENS
374 _GL_WARN_ON_USE (futimens, "futimens is not portable - "
375 "use gnulib module futimens for portability");
376 # endif
377 #endif
380 #if @GNULIB_LCHMOD@
381 /* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
382 denotes a symbolic link. */
383 # if !@HAVE_LCHMOD@
384 /* The lchmod replacement follows symbolic links. Callers should take
385 this into account; lchmod should be applied only to arguments that
386 are known to not be symbolic links. On hosts that lack lchmod,
387 this can lead to race conditions between the check and the
388 invocation of lchmod, but we know of no workarounds that are
389 reliable in general. You might try requesting support for lchmod
390 from your operating system supplier. */
391 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
392 # define lchmod chmod
393 # endif
394 /* Need to cast, because on mingw, the second parameter of chmod is
395 int mode. */
396 _GL_CXXALIAS_RPL_CAST_1 (lchmod, chmod, int,
397 (const char *filename, mode_t mode));
398 # else
399 # if 0 /* assume already declared */
400 _GL_FUNCDECL_SYS (lchmod, int, (const char *filename, mode_t mode)
401 _GL_ARG_NONNULL ((1)));
402 # endif
403 _GL_CXXALIAS_SYS (lchmod, int, (const char *filename, mode_t mode));
404 # endif
405 # if @HAVE_LCHMOD@
406 _GL_CXXALIASWARN (lchmod);
407 # endif
408 #elif defined GNULIB_POSIXCHECK
409 # undef lchmod
410 # if HAVE_RAW_DECL_LCHMOD
411 _GL_WARN_ON_USE (lchmod, "lchmod is unportable - "
412 "use gnulib module lchmod for portability");
413 # endif
414 #endif
417 #if @GNULIB_LSTAT@
418 # if ! @HAVE_LSTAT@
419 /* mingw does not support symlinks, therefore it does not have lstat. But
420 without links, stat does just fine. */
421 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
422 # define lstat stat
423 # endif
424 _GL_CXXALIAS_RPL_1 (lstat, stat, int, (const char *name, struct stat *buf));
425 # elif @REPLACE_LSTAT@
426 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
427 # undef lstat
428 # define lstat rpl_lstat
429 # endif
430 _GL_FUNCDECL_RPL (lstat, int, (const char *name, struct stat *buf)
431 _GL_ARG_NONNULL ((1, 2)));
432 _GL_CXXALIAS_RPL (lstat, int, (const char *name, struct stat *buf));
433 # else
434 _GL_CXXALIAS_SYS (lstat, int, (const char *name, struct stat *buf));
435 # endif
436 # if @HAVE_LSTAT@
437 _GL_CXXALIASWARN (lstat);
438 # endif
439 #elif defined GNULIB_POSIXCHECK
440 # undef lstat
441 # if HAVE_RAW_DECL_LSTAT
442 _GL_WARN_ON_USE (lstat, "lstat is unportable - "
443 "use gnulib module lstat for portability");
444 # endif
445 #endif
448 #if @REPLACE_MKDIR@
449 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
450 # undef mkdir
451 # define mkdir rpl_mkdir
452 # endif
453 _GL_FUNCDECL_RPL (mkdir, int, (char const *name, mode_t mode)
454 _GL_ARG_NONNULL ((1)));
455 _GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode));
456 #else
457 /* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
458 Additionally, it declares _mkdir (and depending on compile flags, an
459 alias mkdir), only in the nonstandard includes <direct.h> and <io.h>,
460 which are included above. */
461 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
463 static inline int
464 rpl_mkdir (char const *name, mode_t mode)
466 return _mkdir (name);
469 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
470 # define mkdir rpl_mkdir
471 # endif
472 _GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode));
473 # else
474 _GL_CXXALIAS_SYS (mkdir, int, (char const *name, mode_t mode));
475 # endif
476 #endif
477 _GL_CXXALIASWARN (mkdir);
480 #if @GNULIB_MKDIRAT@
481 # if !@HAVE_MKDIRAT@
482 _GL_FUNCDECL_SYS (mkdirat, int, (int fd, char const *file, mode_t mode)
483 _GL_ARG_NONNULL ((2)));
484 # endif
485 _GL_CXXALIAS_SYS (mkdirat, int, (int fd, char const *file, mode_t mode));
486 _GL_CXXALIASWARN (mkdirat);
487 #elif defined GNULIB_POSIXCHECK
488 # undef mkdirat
489 # if HAVE_RAW_DECL_MKDIRAT
490 _GL_WARN_ON_USE (mkdirat, "mkdirat is not portable - "
491 "use gnulib module openat for portability");
492 # endif
493 #endif
496 #if @GNULIB_MKFIFO@
497 # if @REPLACE_MKFIFO@
498 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
499 # undef mkfifo
500 # define mkfifo rpl_mkfifo
501 # endif
502 _GL_FUNCDECL_RPL (mkfifo, int, (char const *file, mode_t mode)
503 _GL_ARG_NONNULL ((1)));
504 _GL_CXXALIAS_RPL (mkfifo, int, (char const *file, mode_t mode));
505 # else
506 # if !@HAVE_MKFIFO@
507 _GL_FUNCDECL_SYS (mkfifo, int, (char const *file, mode_t mode)
508 _GL_ARG_NONNULL ((1)));
509 # endif
510 _GL_CXXALIAS_SYS (mkfifo, int, (char const *file, mode_t mode));
511 # endif
512 _GL_CXXALIASWARN (mkfifo);
513 #elif defined GNULIB_POSIXCHECK
514 # undef mkfifo
515 # if HAVE_RAW_DECL_MKFIFO
516 _GL_WARN_ON_USE (mkfifo, "mkfifo is not portable - "
517 "use gnulib module mkfifo for portability");
518 # endif
519 #endif
522 #if @GNULIB_MKFIFOAT@
523 # if !@HAVE_MKFIFOAT@
524 _GL_FUNCDECL_SYS (mkfifoat, int, (int fd, char const *file, mode_t mode)
525 _GL_ARG_NONNULL ((2)));
526 # endif
527 _GL_CXXALIAS_SYS (mkfifoat, int, (int fd, char const *file, mode_t mode));
528 _GL_CXXALIASWARN (mkfifoat);
529 #elif defined GNULIB_POSIXCHECK
530 # undef mkfifoat
531 # if HAVE_RAW_DECL_MKFIFOAT
532 _GL_WARN_ON_USE (mkfifoat, "mkfifoat is not portable - "
533 "use gnulib module mkfifoat for portability");
534 # endif
535 #endif
538 #if @GNULIB_MKNOD@
539 # if @REPLACE_MKNOD@
540 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
541 # undef mknod
542 # define mknod rpl_mknod
543 # endif
544 _GL_FUNCDECL_RPL (mknod, int, (char const *file, mode_t mode, dev_t dev)
545 _GL_ARG_NONNULL ((1)));
546 _GL_CXXALIAS_RPL (mknod, int, (char const *file, mode_t mode, dev_t dev));
547 # else
548 # if !@HAVE_MKNOD@
549 _GL_FUNCDECL_SYS (mknod, int, (char const *file, mode_t mode, dev_t dev)
550 _GL_ARG_NONNULL ((1)));
551 # endif
552 _GL_CXXALIAS_SYS (mknod, int, (char const *file, mode_t mode, dev_t dev));
553 # endif
554 _GL_CXXALIASWARN (mknod);
555 #elif defined GNULIB_POSIXCHECK
556 # undef mknod
557 # if HAVE_RAW_DECL_MKNOD
558 _GL_WARN_ON_USE (mknod, "mknod is not portable - "
559 "use gnulib module mknod for portability");
560 # endif
561 #endif
564 #if @GNULIB_MKNODAT@
565 # if !@HAVE_MKNODAT@
566 _GL_FUNCDECL_SYS (mknodat, int,
567 (int fd, char const *file, mode_t mode, dev_t dev)
568 _GL_ARG_NONNULL ((2)));
569 # endif
570 _GL_CXXALIAS_SYS (mknodat, int,
571 (int fd, char const *file, mode_t mode, dev_t dev));
572 _GL_CXXALIASWARN (mknodat);
573 #elif defined GNULIB_POSIXCHECK
574 # undef mknodat
575 # if HAVE_RAW_DECL_MKNODAT
576 _GL_WARN_ON_USE (mknodat, "mknodat is not portable - "
577 "use gnulib module mkfifoat for portability");
578 # endif
579 #endif
582 #if @GNULIB_STAT@
583 # if @REPLACE_STAT@
584 /* We can't use the object-like #define stat rpl_stat, because of
585 struct stat. This means that rpl_stat will not be used if the user
586 does (stat)(a,b). Oh well. */
587 # undef stat
588 # ifdef _LARGE_FILES
589 /* With _LARGE_FILES defined, AIX (only) defines stat to stat64,
590 so we have to replace stat64() instead of stat(). */
591 # define stat stat64
592 # undef stat64
593 # define stat64(name, st) rpl_stat (name, st)
594 # else /* !_LARGE_FILES */
595 # define stat(name, st) rpl_stat (name, st)
596 # endif /* !_LARGE_FILES */
597 _GL_EXTERN_C int stat (const char *name, struct stat *buf) _GL_ARG_NONNULL ((1, 2));
598 # endif
599 #elif defined GNULIB_POSIXCHECK
600 # undef stat
601 # if HAVE_RAW_DECL_STAT
602 _GL_WARN_ON_USE (stat, "stat is unportable - "
603 "use gnulib module stat for portability");
604 # endif
605 #endif
608 #if @GNULIB_UTIMENSAT@
609 # if @REPLACE_UTIMENSAT@
610 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
611 # undef utimensat
612 # define utimensat rpl_utimensat
613 # endif
614 _GL_FUNCDECL_RPL (utimensat, int, (int fd, char const *name,
615 struct timespec const times[2], int flag)
616 _GL_ARG_NONNULL ((2)));
617 _GL_CXXALIAS_RPL (utimensat, int, (int fd, char const *name,
618 struct timespec const times[2], int flag));
619 # else
620 # if !@HAVE_UTIMENSAT@
621 _GL_FUNCDECL_SYS (utimensat, int, (int fd, char const *name,
622 struct timespec const times[2], int flag)
623 _GL_ARG_NONNULL ((2)));
624 # endif
625 _GL_CXXALIAS_SYS (utimensat, int, (int fd, char const *name,
626 struct timespec const times[2], int flag));
627 # endif
628 _GL_CXXALIASWARN (utimensat);
629 #elif defined GNULIB_POSIXCHECK
630 # undef utimensat
631 # if HAVE_RAW_DECL_UTIMENSAT
632 _GL_WARN_ON_USE (utimensat, "utimensat is not portable - "
633 "use gnulib module utimensat for portability");
634 # endif
635 #endif
638 #endif /* _GL_SYS_STAT_H */
639 #endif /* _GL_SYS_STAT_H */
640 #endif