maint: use pragma consistently across replacement headers
[gnulib.git] / 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 #if __GNUC__ >= 3
18 @PRAGMA_SYSTEM_HEADER@
19 #endif
20
21 #ifndef _GL_DIRENT_H
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 # if !@HAVE_DECL_DIRFD@ && !defined dirfd
54 /* Return the file descriptor associated with the given directory stream,
55    or -1 if none exists.  */
56 _GL_EXTERN_C int dirfd (DIR *dir) _GL_ARG_NONNULL ((1));
57 # endif
58 #elif defined GNULIB_POSIXCHECK
59 # undef dirfd
60 # if HAVE_RAW_DECL_DIRFD
61 _GL_WARN_ON_USE (dirfd, "dirfd is unportable - "
62                  "use gnulib module dirfd for portability");
63 # endif
64 #endif
65
66 #if @GNULIB_FDOPENDIR@
67 /* Open a directory stream visiting the given directory file
68    descriptor.  Return NULL and set errno if fd is not visiting a
69    directory.  On success, this function consumes fd (it will be
70    implicitly closed either by this function or by a subsequent
71    closedir).  */
72 # if @REPLACE_FDOPENDIR@
73 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
74 #   undef fdopendir
75 #   define fdopendir rpl_fdopendir
76 #  endif
77 _GL_FUNCDECL_RPL (fdopendir, DIR *, (int fd));
78 _GL_CXXALIAS_RPL (fdopendir, DIR *, (int fd));
79 # else
80 #  if !@HAVE_FDOPENDIR@
81 _GL_FUNCDECL_SYS (fdopendir, DIR *, (int fd));
82 #  endif
83 _GL_CXXALIAS_SYS (fdopendir, DIR *, (int fd));
84 # endif
85 _GL_CXXALIASWARN (fdopendir);
86 #elif defined GNULIB_POSIXCHECK
87 # undef fdopendir
88 # if HAVE_RAW_DECL_FDOPENDIR
89 _GL_WARN_ON_USE (fdopendir, "fdopendir is unportable - "
90                  "use gnulib module fdopendir for portability");
91 # endif
92 #endif
93
94 #if @REPLACE_OPENDIR@
95 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
96 #  define opendir rpl_opendir
97 # endif
98 _GL_FUNCDECL_RPL (opendir, DIR *, (const char *) _GL_ARG_NONNULL ((1)));
99 _GL_CXXALIAS_RPL (opendir, DIR *, (const char *));
100 #else
101 _GL_CXXALIAS_SYS (opendir, DIR *, (const char *));
102 #endif
103 _GL_CXXALIASWARN (opendir);
104
105 #if @GNULIB_SCANDIR@
106 /* Scan the directory DIR, calling FILTER on each directory entry.
107    Entries for which FILTER returns nonzero are individually malloc'd,
108    sorted using qsort with CMP, and collected in a malloc'd array in
109    *NAMELIST.  Returns the number of entries selected, or -1 on error.  */
110 # if !@HAVE_SCANDIR@
111 _GL_FUNCDECL_SYS (scandir, int,
112                   (const char *dir, struct dirent ***namelist,
113                    int (*filter) (const struct dirent *),
114                    int (*cmp) (const struct dirent **, const struct dirent **))
115                   _GL_ARG_NONNULL ((1, 2, 4)));
116 # endif
117 /* Need to cast, because on glibc systems, the fourth parameter is
118                         int (*cmp) (const void *, const void *).  */
119 _GL_CXXALIAS_SYS_CAST (scandir, int,
120                        (const char *dir, struct dirent ***namelist,
121                         int (*filter) (const struct dirent *),
122                         int (*cmp) (const struct dirent **, const struct dirent **)));
123 _GL_CXXALIASWARN (scandir);
124 #elif defined GNULIB_POSIXCHECK
125 # undef scandir
126 # if HAVE_RAW_DECL_SCANDIR
127 _GL_WARN_ON_USE (scandir, "scandir is unportable - "
128                  "use gnulib module scandir for portability");
129 # endif
130 #endif
131
132 #if @GNULIB_ALPHASORT@
133 /* Compare two 'struct dirent' entries alphabetically.  */
134 # if !@HAVE_ALPHASORT@
135 _GL_FUNCDECL_SYS (alphasort, int,
136                   (const struct dirent **, const struct dirent **)
137                   _GL_ARG_NONNULL ((1, 2)));
138 # endif
139 /* Need to cast, because on glibc systems, the parameters are
140                        (const void *, const void *).  */
141 _GL_CXXALIAS_SYS_CAST (alphasort, int,
142                        (const struct dirent **, const struct dirent **));
143 _GL_CXXALIASWARN (alphasort);
144 #elif defined GNULIB_POSIXCHECK
145 # undef alphasort
146 # if HAVE_RAW_DECL_ALPHASORT
147 _GL_WARN_ON_USE (alphasort, "alphasort is unportable - "
148                  "use gnulib module alphasort for portability");
149 # endif
150 #endif
151
152
153 #endif /* _GL_DIRENT_H */
154 #endif /* _GL_DIRENT_H */