1 /* A GNU-like <dirent.h>.
2 Copyright (C) 2006-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 of the License, or
7 (at your option) 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, see <http://www.gnu.org/licenses/>. */
20 @PRAGMA_SYSTEM_HEADER@
23 /* The include_next requires a split double-inclusion guard. */
24 #@INCLUDE_NEXT@ @NEXT_DIRENT_H@
29 /* Get ino_t. Needed on some systems, including glibc 2.8. */
30 #include <sys/types.h>
32 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
34 /* The definition of _GL_ARG_NONNULL is copied here. */
36 /* The definition of _GL_WARN_ON_USE is copied here. */
39 /* Declare overridden functions. */
41 #if @REPLACE_CLOSEDIR@
42 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
43 # define closedir rpl_closedir
45 _GL_FUNCDECL_RPL (closedir, int, (DIR *) _GL_ARG_NONNULL ((1)));
46 _GL_CXXALIAS_RPL (closedir, int, (DIR *));
48 _GL_CXXALIAS_SYS (closedir, int, (DIR *));
50 _GL_CXXALIASWARN (closedir);
53 /* Return the file descriptor associated with the given directory stream,
54 or -1 if none exists. */
56 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
58 # define dirfd rpl_dirfd
60 _GL_FUNCDECL_RPL (dirfd, int, (DIR *) _GL_ARG_NONNULL ((1)));
61 _GL_CXXALIAS_RPL (dirfd, int, (DIR *));
63 # if !(@HAVE_DECL_DIRFD@ || defined dirfd)
64 _GL_FUNCDECL_SYS (dirfd, int, (DIR *) _GL_ARG_NONNULL ((1)));
66 _GL_CXXALIAS_SYS (dirfd, int, (DIR *));
68 _GL_CXXALIASWARN (dirfd);
69 #elif defined GNULIB_POSIXCHECK
71 # if HAVE_RAW_DECL_DIRFD
72 _GL_WARN_ON_USE (dirfd, "dirfd is unportable - "
73 "use gnulib module dirfd for portability");
77 #if @GNULIB_FDOPENDIR@
78 /* Open a directory stream visiting the given directory file
79 descriptor. Return NULL and set errno if fd is not visiting a
80 directory. On success, this function consumes fd (it will be
81 implicitly closed either by this function or by a subsequent
83 # if @REPLACE_FDOPENDIR@
84 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
86 # define fdopendir rpl_fdopendir
88 _GL_FUNCDECL_RPL (fdopendir, DIR *, (int fd));
89 _GL_CXXALIAS_RPL (fdopendir, DIR *, (int fd));
91 # if !@HAVE_FDOPENDIR@ || !@HAVE_DECL_FDOPENDIR@
92 _GL_FUNCDECL_SYS (fdopendir, DIR *, (int fd));
94 _GL_CXXALIAS_SYS (fdopendir, DIR *, (int fd));
96 _GL_CXXALIASWARN (fdopendir);
97 #elif defined GNULIB_POSIXCHECK
99 # if HAVE_RAW_DECL_FDOPENDIR
100 _GL_WARN_ON_USE (fdopendir, "fdopendir is unportable - "
101 "use gnulib module fdopendir for portability");
105 #if @REPLACE_OPENDIR@
106 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
107 # define opendir rpl_opendir
109 _GL_FUNCDECL_RPL (opendir, DIR *, (const char *) _GL_ARG_NONNULL ((1)));
110 _GL_CXXALIAS_RPL (opendir, DIR *, (const char *));
112 _GL_CXXALIAS_SYS (opendir, DIR *, (const char *));
114 _GL_CXXALIASWARN (opendir);
117 /* Scan the directory DIR, calling FILTER on each directory entry.
118 Entries for which FILTER returns nonzero are individually malloc'd,
119 sorted using qsort with CMP, and collected in a malloc'd array in
120 *NAMELIST. Returns the number of entries selected, or -1 on error. */
122 _GL_FUNCDECL_SYS (scandir, int,
123 (const char *dir, struct dirent ***namelist,
124 int (*filter) (const struct dirent *),
125 int (*cmp) (const struct dirent **, const struct dirent **))
126 _GL_ARG_NONNULL ((1, 2, 4)));
128 /* Need to cast, because on glibc systems, the fourth parameter is
129 int (*cmp) (const void *, const void *). */
130 _GL_CXXALIAS_SYS_CAST (scandir, int,
131 (const char *dir, struct dirent ***namelist,
132 int (*filter) (const struct dirent *),
133 int (*cmp) (const struct dirent **, const struct dirent **)));
134 _GL_CXXALIASWARN (scandir);
135 #elif defined GNULIB_POSIXCHECK
137 # if HAVE_RAW_DECL_SCANDIR
138 _GL_WARN_ON_USE (scandir, "scandir is unportable - "
139 "use gnulib module scandir for portability");
143 #if @GNULIB_ALPHASORT@
144 /* Compare two 'struct dirent' entries alphabetically. */
145 # if !@HAVE_ALPHASORT@
146 _GL_FUNCDECL_SYS (alphasort, int,
147 (const struct dirent **, const struct dirent **)
148 _GL_ARG_NONNULL ((1, 2)));
150 /* Need to cast, because on glibc systems, the parameters are
151 (const void *, const void *). */
152 _GL_CXXALIAS_SYS_CAST (alphasort, int,
153 (const struct dirent **, const struct dirent **));
154 _GL_CXXALIASWARN (alphasort);
155 #elif defined GNULIB_POSIXCHECK
157 # if HAVE_RAW_DECL_ALPHASORT
158 _GL_WARN_ON_USE (alphasort, "alphasort is unportable - "
159 "use gnulib module alphasort for portability");
164 #endif /* _GL_DIRENT_H */
165 #endif /* _GL_DIRENT_H */