1 /* A GNU-like <dirent.h>. 2 Copyright (C) 2006-2020 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 <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 /* Get ino_t. Needed on some systems, including glibc 2.8. */ 33 #include <sys/types.h> 34 35 #if !@HAVE_DIRENT_H@ 36 /* Define types DIR and 'struct dirent'. */ 37 # if !GNULIB_defined_struct_dirent 38 struct dirent 39 { 40 char d_type; 41 char d_name[1]; 42 }; 43 /* Possible values for 'd_type'. */ 44 # define DT_UNKNOWN 0 45 # define DT_FIFO 1 /* FIFO */ 46 # define DT_CHR 2 /* character device */ 47 # define DT_DIR 4 /* directory */ 48 # define DT_BLK 6 /* block device */ 49 # define DT_REG 8 /* regular file */ 50 # define DT_LNK 10 /* symbolic link */ 51 # define DT_SOCK 12 /* socket */ 52 # define DT_WHT 14 /* whiteout */ 53 typedef struct gl_directory DIR; 54 # define GNULIB_defined_struct_dirent 1 55 # endif 56 #endif 57 58 /* The __attribute__ feature is available in gcc versions 2.5 and later. 59 The attribute __pure__ was added in gcc 2.96. */ 60 #ifndef _GL_ATTRIBUTE_PURE 61 # if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) 62 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__)) 63 # else 64 # define _GL_ATTRIBUTE_PURE /* empty */ 65 # endif 66 #endif 67 68 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ 69 70 /* The definition of _GL_ARG_NONNULL is copied here. */ 71 72 /* The definition of _GL_WARN_ON_USE is copied here. */ 73 74 75 /* Declare overridden functions. */ 76 77 #if @GNULIB_OPENDIR@ 78 # if @REPLACE_OPENDIR@ 79 # if !(defined __cplusplus && defined GNULIB_NAMESPACE) 80 # undef opendir 81 # define opendir rpl_opendir 82 # define GNULIB_defined_opendir 1 83 # endif 84 _GL_FUNCDECL_RPL (opendir, DIR *, (const char *dir_name) _GL_ARG_NONNULL ((1))); 85 _GL_CXXALIAS_RPL (opendir, DIR *, (const char *dir_name)); 86 # else 87 # if !@HAVE_OPENDIR@ 88 _GL_FUNCDECL_SYS (opendir, DIR *, (const char *dir_name) _GL_ARG_NONNULL ((1))); 89 # endif 90 _GL_CXXALIAS_SYS (opendir, DIR *, (const char *dir_name)); 91 # endif 92 _GL_CXXALIASWARN (opendir); 93 #elif defined GNULIB_POSIXCHECK 94 # undef opendir 95 # if HAVE_RAW_DECL_OPENDIR 96 _GL_WARN_ON_USE (opendir, "opendir is not portable - " 97 "use gnulib module opendir for portability"); 98 # endif 99 #endif 100 101 #if @GNULIB_READDIR@ 102 # if !@HAVE_READDIR@ 103 _GL_FUNCDECL_SYS (readdir, struct dirent *, (DIR *dirp) _GL_ARG_NONNULL ((1))); 104 # endif 105 _GL_CXXALIAS_SYS (readdir, struct dirent *, (DIR *dirp)); 106 _GL_CXXALIASWARN (readdir); 107 #elif defined GNULIB_POSIXCHECK 108 # undef readdir 109 # if HAVE_RAW_DECL_READDIR 110 _GL_WARN_ON_USE (readdir, "readdir is not portable - " 111 "use gnulib module readdir for portability"); 112 # endif 113 #endif 114 115 #if @GNULIB_REWINDDIR@ 116 # if !@HAVE_REWINDDIR@ 117 _GL_FUNCDECL_SYS (rewinddir, void, (DIR *dirp) _GL_ARG_NONNULL ((1))); 118 # endif 119 _GL_CXXALIAS_SYS (rewinddir, void, (DIR *dirp)); 120 _GL_CXXALIASWARN (rewinddir); 121 #elif defined GNULIB_POSIXCHECK 122 # undef rewinddir 123 # if HAVE_RAW_DECL_REWINDDIR 124 _GL_WARN_ON_USE (rewinddir, "rewinddir is not portable - " 125 "use gnulib module rewinddir for portability"); 126 # endif 127 #endif 128 129 #if @GNULIB_CLOSEDIR@ 130 # if @REPLACE_CLOSEDIR@ 131 # if !(defined __cplusplus && defined GNULIB_NAMESPACE) 132 # undef closedir 133 # define closedir rpl_closedir 134 # define GNULIB_defined_closedir 1 135 # endif 136 _GL_FUNCDECL_RPL (closedir, int, (DIR *dirp) _GL_ARG_NONNULL ((1))); 137 _GL_CXXALIAS_RPL (closedir, int, (DIR *dirp)); 138 # else 139 # if !@HAVE_CLOSEDIR@ 140 _GL_FUNCDECL_SYS (closedir, int, (DIR *dirp) _GL_ARG_NONNULL ((1))); 141 # endif 142 _GL_CXXALIAS_SYS (closedir, int, (DIR *dirp)); 143 # endif 144 _GL_CXXALIASWARN (closedir); 145 #elif defined GNULIB_POSIXCHECK 146 # undef closedir 147 # if HAVE_RAW_DECL_CLOSEDIR 148 _GL_WARN_ON_USE (closedir, "closedir is not portable - " 149 "use gnulib module closedir for portability"); 150 # endif 151 #endif 152 153 #if @GNULIB_DIRFD@ 154 /* Return the file descriptor associated with the given directory stream, 155 or -1 if none exists. */ 156 # if @REPLACE_DIRFD@ 157 # if !(defined __cplusplus && defined GNULIB_NAMESPACE) 158 # undef dirfd 159 # define dirfd rpl_dirfd 160 # endif 161 _GL_FUNCDECL_RPL (dirfd, int, (DIR *) _GL_ARG_NONNULL ((1))); 162 _GL_CXXALIAS_RPL (dirfd, int, (DIR *)); 163 164 # ifdef __KLIBC__ 165 /* Gnulib internal hooks needed to maintain the dirfd metadata. */ 166 _GL_EXTERN_C int _gl_register_dirp_fd (int fd, DIR *dirp) 167 _GL_ARG_NONNULL ((2)); 168 _GL_EXTERN_C void _gl_unregister_dirp_fd (int fd); 169 # endif 170 # else 171 # if defined __cplusplus && defined GNULIB_NAMESPACE && defined dirfd 172 /* dirfd is defined as a macro and not as a function. 173 Turn it into a function and get rid of the macro. */ 174 static inline int (dirfd) (DIR *dp) { return dirfd (dp); } 175 # undef dirfd 176 # endif 177 # if !(@HAVE_DECL_DIRFD@ || defined dirfd) 178 _GL_FUNCDECL_SYS (dirfd, int, (DIR *) _GL_ARG_NONNULL ((1))); 179 # endif 180 _GL_CXXALIAS_SYS (dirfd, int, (DIR *)); 181 # endif 182 _GL_CXXALIASWARN (dirfd); 183 #elif defined GNULIB_POSIXCHECK 184 # undef dirfd 185 # if HAVE_RAW_DECL_DIRFD 186 _GL_WARN_ON_USE (dirfd, "dirfd is unportable - " 187 "use gnulib module dirfd for portability"); 188 # endif 189 #endif 190 191 #if @GNULIB_FDOPENDIR@ 192 /* Open a directory stream visiting the given directory file 193 descriptor. Return NULL and set errno if fd is not visiting a 194 directory. On success, this function consumes fd (it will be 195 implicitly closed either by this function or by a subsequent 196 closedir). */ 197 # if @REPLACE_FDOPENDIR@ 198 # if !(defined __cplusplus && defined GNULIB_NAMESPACE) 199 # undef fdopendir 200 # define fdopendir rpl_fdopendir 201 # endif 202 _GL_FUNCDECL_RPL (fdopendir, DIR *, (int fd)); 203 _GL_CXXALIAS_RPL (fdopendir, DIR *, (int fd)); 204 # else 205 # if !@HAVE_FDOPENDIR@ || !@HAVE_DECL_FDOPENDIR@ 206 _GL_FUNCDECL_SYS (fdopendir, DIR *, (int fd)); 207 # endif 208 _GL_CXXALIAS_SYS (fdopendir, DIR *, (int fd)); 209 # endif 210 _GL_CXXALIASWARN (fdopendir); 211 #elif defined GNULIB_POSIXCHECK 212 # undef fdopendir 213 # if HAVE_RAW_DECL_FDOPENDIR 214 _GL_WARN_ON_USE (fdopendir, "fdopendir is unportable - " 215 "use gnulib module fdopendir for portability"); 216 # endif 217 #endif 218 219 #if @GNULIB_SCANDIR@ 220 /* Scan the directory DIR, calling FILTER on each directory entry. 221 Entries for which FILTER returns nonzero are individually malloc'd, 222 sorted using qsort with CMP, and collected in a malloc'd array in 223 *NAMELIST. Returns the number of entries selected, or -1 on error. */ 224 # if !@HAVE_SCANDIR@ 225 _GL_FUNCDECL_SYS (scandir, int, 226 (const char *dir, struct dirent ***namelist, 227 int (*filter) (const struct dirent *), 228 int (*cmp) (const struct dirent **, const struct dirent **)) 229 _GL_ARG_NONNULL ((1, 2, 4))); 230 # endif 231 /* Need to cast, because on glibc systems, the fourth parameter is 232 int (*cmp) (const void *, const void *). */ 233 _GL_CXXALIAS_SYS_CAST (scandir, int, 234 (const char *dir, struct dirent ***namelist, 235 int (*filter) (const struct dirent *), 236 int (*cmp) (const struct dirent **, const struct dirent **))); 237 _GL_CXXALIASWARN (scandir); 238 #elif defined GNULIB_POSIXCHECK 239 # undef scandir 240 # if HAVE_RAW_DECL_SCANDIR 241 _GL_WARN_ON_USE (scandir, "scandir is unportable - " 242 "use gnulib module scandir for portability"); 243 # endif 244 #endif 245 246 #if @GNULIB_ALPHASORT@ 247 /* Compare two 'struct dirent' entries alphabetically. */ 248 # if !@HAVE_ALPHASORT@ 249 _GL_FUNCDECL_SYS (alphasort, int, 250 (const struct dirent **, const struct dirent **) 251 _GL_ATTRIBUTE_PURE 252 _GL_ARG_NONNULL ((1, 2))); 253 # endif 254 /* Need to cast, because on glibc systems, the parameters are 255 (const void *, const void *). */ 256 _GL_CXXALIAS_SYS_CAST (alphasort, int, 257 (const struct dirent **, const struct dirent **)); 258 _GL_CXXALIASWARN (alphasort); 259 #elif defined GNULIB_POSIXCHECK 260 # undef alphasort 261 # if HAVE_RAW_DECL_ALPHASORT 262 _GL_WARN_ON_USE (alphasort, "alphasort is unportable - " 263 "use gnulib module alphasort for portability"); 264 # endif 265 #endif 266 267 268 #endif /* _@GUARD_PREFIX@_DIRENT_H */ 269 #endif /* _@GUARD_PREFIX@_DIRENT_H */ 270