fts, getcwd, glob: audit for dirfd returning -1
[pspp] / lib / dirent.in.h
1 /* A GNU-like <dirent.h>.
2    Copyright (C) 2006-2010 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 3 of the License, or
7    (at your option) 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, see <http://www.gnu.org/licenses/>.  */
16
17 #ifndef _GL_DIRENT_H
18
19 #if __GNUC__ >= 3
20 @PRAGMA_SYSTEM_HEADER@
21 #endif
22
23 /* The include_next requires a split double-inclusion guard.  */
24 #@INCLUDE_NEXT@ @NEXT_DIRENT_H@
25
26 #ifndef _GL_DIRENT_H
27 #define _GL_DIRENT_H
28
29 /* Get ino_t.  Needed on some systems, including glibc 2.8.  */
30 #include <sys/types.h>
31
32 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
33
34 /* The definition of _GL_ARG_NONNULL is copied here.  */
35
36 /* The definition of _GL_WARN_ON_USE is copied here.  */
37
38
39 /* Declare overridden functions.  */
40
41 #if @REPLACE_CLOSEDIR@
42 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
43 #  define closedir rpl_closedir
44 # endif
45 _GL_FUNCDECL_RPL (closedir, int, (DIR *) _GL_ARG_NONNULL ((1)));
46 _GL_CXXALIAS_RPL (closedir, int, (DIR *));
47 #else
48 _GL_CXXALIAS_SYS (closedir, int, (DIR *));
49 #endif
50 _GL_CXXALIASWARN (closedir);
51
52 #if @GNULIB_DIRFD@
53 /* Return the file descriptor associated with the given directory stream,
54    or -1 if none exists.  */
55 # if @REPLACE_DIRFD@
56 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
57 #   undef dirfd
58 #   define dirfd rpl_dirfd
59 #  endif
60 _GL_FUNCDECL_RPL (dirfd, int, (DIR *) _GL_ARG_NONNULL ((1)));
61 _GL_CXXALIAS_RPL (dirfd, int, (DIR *));
62 # else
63 #  if defined __cplusplus && defined GNULIB_NAMESPACE && defined dirfd
64     /* dirfd is defined as a macro and not as a function.
65        Turn it into a function and get rid of the macro.  */
66 static inline int (dirfd) (DIR *dp) { return dirfd (dp); }
67 #   undef dirfd
68 #  endif
69 #  if !(@HAVE_DECL_DIRFD@ || defined dirfd)
70 _GL_FUNCDECL_SYS (dirfd, int, (DIR *) _GL_ARG_NONNULL ((1)));
71 #  endif
72 _GL_CXXALIAS_SYS (dirfd, int, (DIR *));
73 # endif
74 _GL_CXXALIASWARN (dirfd);
75 #elif defined GNULIB_POSIXCHECK
76 # undef dirfd
77 # if HAVE_RAW_DECL_DIRFD
78 _GL_WARN_ON_USE (dirfd, "dirfd is unportable - "
79                  "use gnulib module dirfd for portability");
80 # endif
81 #endif
82
83 #if @GNULIB_FDOPENDIR@
84 /* Open a directory stream visiting the given directory file
85    descriptor.  Return NULL and set errno if fd is not visiting a
86    directory.  On success, this function consumes fd (it will be
87    implicitly closed either by this function or by a subsequent
88    closedir).  */
89 # if @REPLACE_FDOPENDIR@
90 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
91 #   undef fdopendir
92 #   define fdopendir rpl_fdopendir
93 #  endif
94 _GL_FUNCDECL_RPL (fdopendir, DIR *, (int fd));
95 _GL_CXXALIAS_RPL (fdopendir, DIR *, (int fd));
96 # else
97 #  if !@HAVE_FDOPENDIR@ || !@HAVE_DECL_FDOPENDIR@
98 _GL_FUNCDECL_SYS (fdopendir, DIR *, (int fd));
99 #  endif
100 _GL_CXXALIAS_SYS (fdopendir, DIR *, (int fd));
101 # endif
102 _GL_CXXALIASWARN (fdopendir);
103 #elif defined GNULIB_POSIXCHECK
104 # undef fdopendir
105 # if HAVE_RAW_DECL_FDOPENDIR
106 _GL_WARN_ON_USE (fdopendir, "fdopendir is unportable - "
107                  "use gnulib module fdopendir for portability");
108 # endif
109 #endif
110
111 #if @REPLACE_OPENDIR@
112 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
113 #  define opendir rpl_opendir
114 # endif
115 _GL_FUNCDECL_RPL (opendir, DIR *, (const char *) _GL_ARG_NONNULL ((1)));
116 _GL_CXXALIAS_RPL (opendir, DIR *, (const char *));
117 #else
118 _GL_CXXALIAS_SYS (opendir, DIR *, (const char *));
119 #endif
120 _GL_CXXALIASWARN (opendir);
121
122 #if @GNULIB_SCANDIR@
123 /* Scan the directory DIR, calling FILTER on each directory entry.
124    Entries for which FILTER returns nonzero are individually malloc'd,
125    sorted using qsort with CMP, and collected in a malloc'd array in
126    *NAMELIST.  Returns the number of entries selected, or -1 on error.  */
127 # if !@HAVE_SCANDIR@
128 _GL_FUNCDECL_SYS (scandir, int,
129                   (const char *dir, struct dirent ***namelist,
130                    int (*filter) (const struct dirent *),
131                    int (*cmp) (const struct dirent **, const struct dirent **))
132                   _GL_ARG_NONNULL ((1, 2, 4)));
133 # endif
134 /* Need to cast, because on glibc systems, the fourth parameter is
135                         int (*cmp) (const void *, const void *).  */
136 _GL_CXXALIAS_SYS_CAST (scandir, int,
137                        (const char *dir, struct dirent ***namelist,
138                         int (*filter) (const struct dirent *),
139                         int (*cmp) (const struct dirent **, const struct dirent **)));
140 _GL_CXXALIASWARN (scandir);
141 #elif defined GNULIB_POSIXCHECK
142 # undef scandir
143 # if HAVE_RAW_DECL_SCANDIR
144 _GL_WARN_ON_USE (scandir, "scandir is unportable - "
145                  "use gnulib module scandir for portability");
146 # endif
147 #endif
148
149 #if @GNULIB_ALPHASORT@
150 /* Compare two 'struct dirent' entries alphabetically.  */
151 # if !@HAVE_ALPHASORT@
152 _GL_FUNCDECL_SYS (alphasort, int,
153                   (const struct dirent **, const struct dirent **)
154                   _GL_ARG_NONNULL ((1, 2)));
155 # endif
156 /* Need to cast, because on glibc systems, the parameters are
157                        (const void *, const void *).  */
158 _GL_CXXALIAS_SYS_CAST (alphasort, int,
159                        (const struct dirent **, const struct dirent **));
160 _GL_CXXALIASWARN (alphasort);
161 #elif defined GNULIB_POSIXCHECK
162 # undef alphasort
163 # if HAVE_RAW_DECL_ALPHASORT
164 _GL_WARN_ON_USE (alphasort, "alphasort is unportable - "
165                  "use gnulib module alphasort for portability");
166 # endif
167 #endif
168
169
170 #endif /* _GL_DIRENT_H */
171 #endif /* _GL_DIRENT_H */