Debian Codegraph @

gnulib/dirent.in.h

raw symbols SCIP
1 /* A GNU-like <dirent.h>.
2 Copyright (C) 2006-2024 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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, see <https://www.gnu.org/licenses/>. */
16
17 #ifndef _@GUARD_PREFIX@_DIRENT_H
18
19 #if __GNUC__ >= 3
20 @PRAGMA_SYSTEM_HEADER@
21 #endif
22 @PRAGMA_COLUMNS@
23
24 /* The include_next requires a split double-inclusion guard. */
25 #if @HAVE_DIRENT_H@
26 # @INCLUDE_NEXT@ @NEXT_DIRENT_H@
27 #endif
28
29 #ifndef _@GUARD_PREFIX@_DIRENT_H
30 #define _@GUARD_PREFIX@_DIRENT_H
31
32 /* This file uses _GL_ATTRIBUTE_DEALLOC, _GL_ATTRIBUTE_MALLOC,
33 _GL_ATTRIBUTE_PURE, GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */
34 #if !_GL_CONFIG_H_INCLUDED
35 #error "Please include config.h first."
36 #endif
37
38 /* Get ino_t. Needed on some systems, including glibc 2.8. */
39 #include <sys/types.h>
40
41 #if !@HAVE_DIRENT_H@
42 /* Define types DIR and 'struct dirent'. */
43 # if !GNULIB_defined_struct_dirent
44 struct dirent
45 {
46 char d_type;
47 char d_name[1];
48 };
49 /* Possible values for 'd_type'. */
50 # define DT_UNKNOWN 0
51 # define DT_FIFO 1 /* FIFO */
52 # define DT_CHR 2 /* character device */
53 # define DT_DIR 4 /* directory */
54 # define DT_BLK 6 /* block device */
55 # define DT_REG 8 /* regular file */
56 # define DT_LNK 10 /* symbolic link */
57 # define DT_SOCK 12 /* socket */
58 # define DT_WHT 14 /* whiteout */
59 # define GNULIB_defined_struct_dirent 1
60 # endif
61 #endif
62
63 #if !@DIR_HAS_FD_MEMBER@
64 # if !GNULIB_defined_DIR
65 /* struct gl_directory is a type with a field 'int fd_to_close'.
66 It is needed for implementing fdopendir(). */
67 struct gl_directory;
68 # if @HAVE_DIRENT_H@
69 # define DIR struct gl_directory
70 # else
71 typedef struct gl_directory DIR;
72 # endif
73 # define GNULIB_defined_DIR 1
74 # endif
75 #endif
76
77 /* _GL_ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers
78 that can be freed by passing them as the Ith argument to the
79 function F. */
80 #ifndef _GL_ATTRIBUTE_DEALLOC
81 # if __GNUC__ >= 11 && !defined __clang__
82 # define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i)))
83 # else
84 # define _GL_ATTRIBUTE_DEALLOC(f, i)
85 # endif
86 #endif
87
88 /* _GL_ATTRIBUTE_MALLOC declares that the function returns a pointer to freshly
89 allocated memory. */
90 /* Applies to: functions. */
91 #ifndef _GL_ATTRIBUTE_MALLOC
92 # if __GNUC__ >= 3 || defined __clang__
93 # define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
94 # else
95 # define _GL_ATTRIBUTE_MALLOC
96 # endif
97 #endif
98
99 /* The __attribute__ feature is available in gcc versions 2.5 and later.
100 The attribute __pure__ was added in gcc 2.96. */
101 #ifndef _GL_ATTRIBUTE_PURE
102 # if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) || defined __clang__
103 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
104 # else
105 # define _GL_ATTRIBUTE_PURE /* empty */
106 # endif
107 #endif
108
109 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
110
111 /* The definition of _GL_ARG_NONNULL is copied here. */
112
113 /* The definition of _GL_WARN_ON_USE is copied here. */
114
115
116 /* Declare overridden functions. */
117
118 #if @GNULIB_CLOSEDIR@
119 # if @REPLACE_CLOSEDIR@
120 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
121 # undef closedir
122 # define closedir rpl_closedir
123 # define GNULIB_defined_closedir 1
124 # endif
125 _GL_FUNCDECL_RPL (closedir, int, (DIR *dirp) _GL_ARG_NONNULL ((1)));
126 _GL_CXXALIAS_RPL (closedir, int, (DIR *dirp));
127 # else
128 # if !@HAVE_CLOSEDIR@
129 _GL_FUNCDECL_SYS (closedir, int, (DIR *dirp) _GL_ARG_NONNULL ((1)));
130 # endif
131 _GL_CXXALIAS_SYS (closedir, int, (DIR *dirp));
132 # endif
133 _GL_CXXALIASWARN (closedir);
134 #elif defined GNULIB_POSIXCHECK
135 # undef closedir
136 # if HAVE_RAW_DECL_CLOSEDIR
137 _GL_WARN_ON_USE (closedir, "closedir is not portable - "
138 "use gnulib module closedir for portability");
139 # endif
140 #endif
141
142 #if @GNULIB_OPENDIR@
143 # if @REPLACE_OPENDIR@
144 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
145 # undef opendir
146 # define opendir rpl_opendir
147 # define GNULIB_defined_opendir 1
148 # endif
149 _GL_FUNCDECL_RPL (opendir, DIR *,
150 (const char *dir_name)
151 _GL_ARG_NONNULL ((1))
152 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (closedir, 1));
153 _GL_CXXALIAS_RPL (opendir, DIR *, (const char *dir_name));
154 # else
155 # if !@HAVE_OPENDIR@ || (__GNUC__ >= 11 && !defined __clang__)
156 _GL_FUNCDECL_SYS (opendir, DIR *,
157 (const char *dir_name)
158 _GL_ARG_NONNULL ((1))
159 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (closedir, 1));
160 # endif
161 _GL_CXXALIAS_SYS (opendir, DIR *, (const char *dir_name));
162 # endif
163 _GL_CXXALIASWARN (opendir);
164 #else
165 # if @GNULIB_CLOSEDIR@ && !GNULIB_defined_DIR \
166 && (__GNUC__ >= 11 && !defined __clang__) && !defined opendir
167 /* For -Wmismatched-dealloc: Associate opendir with closedir or
168 rpl_closedir. */
169 _GL_FUNCDECL_SYS (opendir, DIR *,
170 (const char *dir_name)
171 _GL_ARG_NONNULL ((1))
172 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (closedir, 1));
173 # endif
174 # if defined GNULIB_POSIXCHECK
175 # undef opendir
176 # if HAVE_RAW_DECL_OPENDIR
177 _GL_WARN_ON_USE (opendir, "opendir is not portable - "
178 "use gnulib module opendir for portability");
179 # endif
180 # endif
181 #endif
182
183 #if @GNULIB_READDIR@
184 # if @REPLACE_READDIR@
185 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
186 # undef readdir
187 # define readdir rpl_readdir
188 # endif
189 _GL_FUNCDECL_RPL (readdir, struct dirent *, (DIR *dirp) _GL_ARG_NONNULL ((1)));
190 _GL_CXXALIAS_RPL (readdir, struct dirent *, (DIR *dirp));
191 # else
192 # if !@HAVE_READDIR@
193 _GL_FUNCDECL_SYS (readdir, struct dirent *, (DIR *dirp) _GL_ARG_NONNULL ((1)));
194 # endif
195 _GL_CXXALIAS_SYS (readdir, struct dirent *, (DIR *dirp));
196 # endif
197 _GL_CXXALIASWARN (readdir);
198 #elif defined GNULIB_POSIXCHECK
199 # undef readdir
200 # if HAVE_RAW_DECL_READDIR
201 _GL_WARN_ON_USE (readdir, "readdir is not portable - "
202 "use gnulib module readdir for portability");
203 # endif
204 #endif
205
206 #if @GNULIB_REWINDDIR@
207 # if @REPLACE_REWINDDIR@
208 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
209 # undef rewinddir
210 # define rewinddir rpl_rewinddir
211 # endif
212 _GL_FUNCDECL_RPL (rewinddir, void, (DIR *dirp) _GL_ARG_NONNULL ((1)));
213 _GL_CXXALIAS_RPL (rewinddir, void, (DIR *dirp));
214 # else
215 # if !@HAVE_REWINDDIR@
216 _GL_FUNCDECL_SYS (rewinddir, void, (DIR *dirp) _GL_ARG_NONNULL ((1)));
217 # endif
218 _GL_CXXALIAS_SYS (rewinddir, void, (DIR *dirp));
219 # endif
220 _GL_CXXALIASWARN (rewinddir);
221 #elif defined GNULIB_POSIXCHECK
222 # undef rewinddir
223 # if HAVE_RAW_DECL_REWINDDIR
224 _GL_WARN_ON_USE (rewinddir, "rewinddir is not portable - "
225 "use gnulib module rewinddir for portability");
226 # endif
227 #endif
228
229 #if @GNULIB_DIRFD@
230 /* Return the file descriptor associated with the given directory stream,
231 or -1 if none exists. */
232 # if @REPLACE_DIRFD@
233 /* On kLIBC, dirfd() is a macro that does not work. Undefine it. */
234 # if !(defined __cplusplus && defined GNULIB_NAMESPACE) || defined dirfd
235 # undef dirfd
236 # define dirfd rpl_dirfd
237 # endif
238 _GL_FUNCDECL_RPL (dirfd, int, (DIR *) _GL_ARG_NONNULL ((1)));
239 _GL_CXXALIAS_RPL (dirfd, int, (DIR *));
240
241 # else
242 # if defined __cplusplus && defined GNULIB_NAMESPACE && defined dirfd
243 /* dirfd is defined as a macro and not as a function.
244 Turn it into a function and get rid of the macro. */
245 static inline int (dirfd) (DIR *dp) { return dirfd (dp); }
246 # undef dirfd
247 # endif
248 # if !(@HAVE_DECL_DIRFD@ || defined dirfd)
249 _GL_FUNCDECL_SYS (dirfd, int, (DIR *) _GL_ARG_NONNULL ((1)));
250 # endif
251 _GL_CXXALIAS_SYS (dirfd, int, (DIR *));
252 # endif
253 _GL_CXXALIASWARN (dirfd);
254 #elif defined GNULIB_POSIXCHECK
255 # undef dirfd
256 # if HAVE_RAW_DECL_DIRFD
257 _GL_WARN_ON_USE (dirfd, "dirfd is unportable - "
258 "use gnulib module dirfd for portability");
259 # endif
260 #endif
261
262 #if @GNULIB_FDOPENDIR@
263 /* Open a directory stream visiting the given directory file
264 descriptor. Return NULL and set errno if fd is not visiting a
265 directory. On success, this function consumes fd (it will be
266 implicitly closed either by this function or by a subsequent
267 closedir). */
268 # if @REPLACE_FDOPENDIR@
269 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
270 # undef fdopendir
271 # define fdopendir rpl_fdopendir
272 # endif
273 _GL_FUNCDECL_RPL (fdopendir, DIR *,
274 (int fd)
275 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (closedir, 1));
276 _GL_CXXALIAS_RPL (fdopendir, DIR *, (int fd));
277 # else
278 # if !@HAVE_FDOPENDIR@ || !@HAVE_DECL_FDOPENDIR@ \
279 || (__GNUC__ >= 11 && !defined __clang__)
280 _GL_FUNCDECL_SYS (fdopendir, DIR *,
281 (int fd)
282 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (closedir, 1));
283 # endif
284 _GL_CXXALIAS_SYS (fdopendir, DIR *, (int fd));
285 # endif
286 _GL_CXXALIASWARN (fdopendir);
287 #else
288 # if @GNULIB_CLOSEDIR@ \
289 && (__GNUC__ >= 11 && !defined __clang__) && !defined fdopendir
290 /* For -Wmismatched-dealloc: Associate fdopendir with closedir or
291 rpl_closedir. */
292 _GL_FUNCDECL_SYS (fdopendir, DIR *,
293 (int fd)
294 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (closedir, 1));
295 # endif
296 # if defined GNULIB_POSIXCHECK
297 # undef fdopendir
298 # if HAVE_RAW_DECL_FDOPENDIR
299 _GL_WARN_ON_USE (fdopendir, "fdopendir is unportable - "
300 "use gnulib module fdopendir for portability");
301 # endif
302 # endif
303 #endif
304
305 #if @GNULIB_SCANDIR@
306 /* Scan the directory DIR, calling FILTER on each directory entry.
307 Entries for which FILTER returns nonzero are individually malloc'd,
308 sorted using qsort with CMP, and collected in a malloc'd array in
309 *NAMELIST. Returns the number of entries selected, or -1 on error. */
310 # if !@HAVE_SCANDIR@
311 _GL_FUNCDECL_SYS (scandir, int,
312 (const char *dir, struct dirent ***namelist,
313 int (*filter) (const struct dirent *),
314 int (*cmp) (const struct dirent **, const struct dirent **))
315 _GL_ARG_NONNULL ((1, 2, 4)));
316 # endif
317 /* Need to cast, because on glibc systems, the fourth parameter is
318 int (*cmp) (const void *, const void *). */
319 _GL_CXXALIAS_SYS_CAST (scandir, int,
320 (const char *dir, struct dirent ***namelist,
321 int (*filter) (const struct dirent *),
322 int (*cmp) (const struct dirent **, const struct dirent **)));
323 _GL_CXXALIASWARN (scandir);
324 #elif defined GNULIB_POSIXCHECK
325 # undef scandir
326 # if HAVE_RAW_DECL_SCANDIR
327 _GL_WARN_ON_USE (scandir, "scandir is unportable - "
328 "use gnulib module scandir for portability");
329 # endif
330 #endif
331
332 #if @GNULIB_ALPHASORT@
333 /* Compare two 'struct dirent' entries alphabetically. */
334 # if !@HAVE_ALPHASORT@
335 _GL_FUNCDECL_SYS (alphasort, int,
336 (const struct dirent **, const struct dirent **)
337 _GL_ATTRIBUTE_PURE
338 _GL_ARG_NONNULL ((1, 2)));
339 # endif
340 /* Need to cast, because on glibc systems, the parameters are
341 (const void *, const void *). */
342 _GL_CXXALIAS_SYS_CAST (alphasort, int,
343 (const struct dirent **, const struct dirent **));
344 _GL_CXXALIASWARN (alphasort);
345 #elif defined GNULIB_POSIXCHECK
346 # undef alphasort
347 # if HAVE_RAW_DECL_ALPHASORT
348 _GL_WARN_ON_USE (alphasort, "alphasort is unportable - "
349 "use gnulib module alphasort for portability");
350 # endif
351 #endif
352
353
354 #endif /* _@GUARD_PREFIX@_DIRENT_H */
355 #endif /* _@GUARD_PREFIX@_DIRENT_H */