annotate lib/dirent.in.h @ 11038:6c37790abb93

New module 'scandir'.
author Bruno Haible <bruno@clisp.org>
date Sun, 18 Jan 2009 12:28:05 +0100
parents 2b0380d48ff6
children 8842f30244d1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10659
fb8bcb95d71a New module 'dirent'.
Bruno Haible <bruno@clisp.org>
parents: 10655
diff changeset
1 /* A GNU-like <dirent.h>.
11038
6c37790abb93 New module 'scandir'.
Bruno Haible <bruno@clisp.org>
parents: 10663
diff changeset
2 Copyright (C) 2006-2009 Free Software Foundation, Inc.
9246
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9246
diff changeset
4 This program is free software: you can redistribute it and/or modify
9246
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9246
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9246
diff changeset
7 (at your option) any later version.
9246
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9246
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
9246
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 #ifndef _GL_DIRENT_H
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
10655
8668b19a7032 Avoid gcc warnings because of #pragma GCC system_header on older gcc.
Bruno Haible <bruno@clisp.org>
parents: 10375
diff changeset
19 #if __GNUC__ >= 3
10375
f96e845fc36d Avoid some "gcc -pedantic" warnings.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
20 @PRAGMA_SYSTEM_HEADER@
10655
8668b19a7032 Avoid gcc warnings because of #pragma GCC system_header on older gcc.
Bruno Haible <bruno@clisp.org>
parents: 10375
diff changeset
21 #endif
10375
f96e845fc36d Avoid some "gcc -pedantic" warnings.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
22
9246
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 /* The include_next requires a split double-inclusion guard. */
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #@INCLUDE_NEXT@ @NEXT_DIRENT_H@
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #ifndef _GL_DIRENT_H
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #define _GL_DIRENT_H
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28
10663
2b0380d48ff6 Move the dirfd() declaration to <dirent.h>.
Bruno Haible <bruno@clisp.org>
parents: 10659
diff changeset
29 /* The definition of GL_LINK_WARNING is copied here. */
9246
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 #ifdef __cplusplus
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 extern "C" {
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 #endif
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35
10663
2b0380d48ff6 Move the dirfd() declaration to <dirent.h>.
Bruno Haible <bruno@clisp.org>
parents: 10659
diff changeset
36 /* Declare overridden functions. */
2b0380d48ff6 Move the dirfd() declaration to <dirent.h>.
Bruno Haible <bruno@clisp.org>
parents: 10659
diff changeset
37
9246
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 #if @REPLACE_FCHDIR@
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 # define opendir rpl_opendir
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 extern DIR * opendir (const char *);
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 # define closedir rpl_closedir
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 extern int closedir (DIR *);
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 #endif
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44
11038
6c37790abb93 New module 'scandir'.
Bruno Haible <bruno@clisp.org>
parents: 10663
diff changeset
45 /* Declare other POSIX functions. */
10663
2b0380d48ff6 Move the dirfd() declaration to <dirent.h>.
Bruno Haible <bruno@clisp.org>
parents: 10659
diff changeset
46
2b0380d48ff6 Move the dirfd() declaration to <dirent.h>.
Bruno Haible <bruno@clisp.org>
parents: 10659
diff changeset
47 #if @GNULIB_DIRFD@
2b0380d48ff6 Move the dirfd() declaration to <dirent.h>.
Bruno Haible <bruno@clisp.org>
parents: 10659
diff changeset
48 # if !@HAVE_DECL_DIRFD@ && !defined dirfd
2b0380d48ff6 Move the dirfd() declaration to <dirent.h>.
Bruno Haible <bruno@clisp.org>
parents: 10659
diff changeset
49 /* Return the file descriptor associated with the given directory stream,
2b0380d48ff6 Move the dirfd() declaration to <dirent.h>.
Bruno Haible <bruno@clisp.org>
parents: 10659
diff changeset
50 or -1 if none exists. */
2b0380d48ff6 Move the dirfd() declaration to <dirent.h>.
Bruno Haible <bruno@clisp.org>
parents: 10659
diff changeset
51 extern int dirfd (DIR const *dir);
2b0380d48ff6 Move the dirfd() declaration to <dirent.h>.
Bruno Haible <bruno@clisp.org>
parents: 10659
diff changeset
52 # endif
2b0380d48ff6 Move the dirfd() declaration to <dirent.h>.
Bruno Haible <bruno@clisp.org>
parents: 10659
diff changeset
53 #elif defined GNULIB_POSIXCHECK
2b0380d48ff6 Move the dirfd() declaration to <dirent.h>.
Bruno Haible <bruno@clisp.org>
parents: 10659
diff changeset
54 # undef dirfd
2b0380d48ff6 Move the dirfd() declaration to <dirent.h>.
Bruno Haible <bruno@clisp.org>
parents: 10659
diff changeset
55 # define dirfd(d) \
2b0380d48ff6 Move the dirfd() declaration to <dirent.h>.
Bruno Haible <bruno@clisp.org>
parents: 10659
diff changeset
56 (GL_LINK_WARNING ("dirfd is unportable - " \
2b0380d48ff6 Move the dirfd() declaration to <dirent.h>.
Bruno Haible <bruno@clisp.org>
parents: 10659
diff changeset
57 "use gnulib module dirfd for portability"), \
2b0380d48ff6 Move the dirfd() declaration to <dirent.h>.
Bruno Haible <bruno@clisp.org>
parents: 10659
diff changeset
58 dirfd (d))
2b0380d48ff6 Move the dirfd() declaration to <dirent.h>.
Bruno Haible <bruno@clisp.org>
parents: 10659
diff changeset
59 #endif
2b0380d48ff6 Move the dirfd() declaration to <dirent.h>.
Bruno Haible <bruno@clisp.org>
parents: 10659
diff changeset
60
11038
6c37790abb93 New module 'scandir'.
Bruno Haible <bruno@clisp.org>
parents: 10663
diff changeset
61 #if @GNULIB_SCANDIR@
6c37790abb93 New module 'scandir'.
Bruno Haible <bruno@clisp.org>
parents: 10663
diff changeset
62 /* Scan the directory DIR, calling FILTER on each directory entry.
6c37790abb93 New module 'scandir'.
Bruno Haible <bruno@clisp.org>
parents: 10663
diff changeset
63 Entries for which FILTER returns nonzero are individually malloc'd,
6c37790abb93 New module 'scandir'.
Bruno Haible <bruno@clisp.org>
parents: 10663
diff changeset
64 sorted using qsort with CMP, and collected in a malloc'd array in
6c37790abb93 New module 'scandir'.
Bruno Haible <bruno@clisp.org>
parents: 10663
diff changeset
65 *NAMELIST. Returns the number of entries selected, or -1 on error. */
6c37790abb93 New module 'scandir'.
Bruno Haible <bruno@clisp.org>
parents: 10663
diff changeset
66 # if !@HAVE_SCANDIR@
6c37790abb93 New module 'scandir'.
Bruno Haible <bruno@clisp.org>
parents: 10663
diff changeset
67 extern int scandir (const char *dir, struct dirent ***namelist,
6c37790abb93 New module 'scandir'.
Bruno Haible <bruno@clisp.org>
parents: 10663
diff changeset
68 int (*filter) (const struct dirent *),
6c37790abb93 New module 'scandir'.
Bruno Haible <bruno@clisp.org>
parents: 10663
diff changeset
69 int (*cmp) (const struct dirent **, const struct dirent **));
6c37790abb93 New module 'scandir'.
Bruno Haible <bruno@clisp.org>
parents: 10663
diff changeset
70 # endif
6c37790abb93 New module 'scandir'.
Bruno Haible <bruno@clisp.org>
parents: 10663
diff changeset
71 #elif defined GNULIB_POSIXCHECK
6c37790abb93 New module 'scandir'.
Bruno Haible <bruno@clisp.org>
parents: 10663
diff changeset
72 # undef scandir
6c37790abb93 New module 'scandir'.
Bruno Haible <bruno@clisp.org>
parents: 10663
diff changeset
73 # define scandir(d,n,f,c) \
6c37790abb93 New module 'scandir'.
Bruno Haible <bruno@clisp.org>
parents: 10663
diff changeset
74 (GL_LINK_WARNING ("scandir is unportable - " \
6c37790abb93 New module 'scandir'.
Bruno Haible <bruno@clisp.org>
parents: 10663
diff changeset
75 "use gnulib module scandir for portability"), \
6c37790abb93 New module 'scandir'.
Bruno Haible <bruno@clisp.org>
parents: 10663
diff changeset
76 scandir (d, n, f, c))
6c37790abb93 New module 'scandir'.
Bruno Haible <bruno@clisp.org>
parents: 10663
diff changeset
77 #endif
6c37790abb93 New module 'scandir'.
Bruno Haible <bruno@clisp.org>
parents: 10663
diff changeset
78
9246
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 #ifdef __cplusplus
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 }
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 #endif
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 #endif /* _GL_DIRENT_H */
eb22327879c5 Rename dirent_.h to dirent.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 #endif /* _GL_DIRENT_H */