modernc.org/cc@v1.0.1/v2/headers/linux_arm/usr/include/dirent.h (about) 1 /* Copyright (C) 1991-2016 Free Software Foundation, Inc. 2 This file is part of the GNU C Library. 3 4 The GNU C Library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 2.1 of the License, or (at your option) any later version. 8 9 The GNU C Library 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 GNU 12 Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General Public 15 License along with the GNU C Library; if not, see 16 <http://www.gnu.org/licenses/>. */ 17 18 /* 19 * POSIX Standard: 5.1.2 Directory Operations <dirent.h> 20 */ 21 22 #ifndef _DIRENT_H 23 #define _DIRENT_H 1 24 25 #include <features.h> 26 27 __BEGIN_DECLS 28 #include <bits/types.h> 29 #ifdef __USE_XOPEN 30 #ifndef __ino_t_defined 31 #ifndef __USE_FILE_OFFSET64 32 typedef __ino_t ino_t; 33 #else 34 typedef __ino64_t ino_t; 35 #endif 36 #define __ino_t_defined 37 #endif 38 #if defined __USE_LARGEFILE64 && !defined __ino64_t_defined 39 typedef __ino64_t ino64_t; 40 #define __ino64_t_defined 41 #endif 42 #endif 43 44 /* This file defines `struct dirent'. 45 46 It defines the macro `_DIRENT_HAVE_D_NAMLEN' iff there is a `d_namlen' 47 member that gives the length of `d_name'. 48 49 It defines the macro `_DIRENT_HAVE_D_RECLEN' iff there is a `d_reclen' 50 member that gives the size of the entire directory entry. 51 52 It defines the macro `_DIRENT_HAVE_D_OFF' iff there is a `d_off' 53 member that gives the file offset of the next directory entry. 54 55 It defines the macro `_DIRENT_HAVE_D_TYPE' iff there is a `d_type' 56 member that gives the type of the file. 57 */ 58 59 #include <bits/dirent.h> 60 61 #if defined __USE_MISC && !defined d_fileno 62 #define d_ino d_fileno /* Backward compatibility. */ 63 #endif 64 65 /* These macros extract size information from a `struct dirent *'. 66 They may evaluate their argument multiple times, so it must not 67 have side effects. Each of these may involve a relatively costly 68 call to `strlen' on some systems, so these values should be cached. 69 70 _D_EXACT_NAMLEN (DP) returns the length of DP->d_name, not including 71 its terminating null character. 72 73 _D_ALLOC_NAMLEN (DP) returns a size at least (_D_EXACT_NAMLEN (DP) + 1); 74 that is, the allocation size needed to hold the DP->d_name string. 75 Use this macro when you don't need the exact length, just an upper bound. 76 This macro is less likely to require calling `strlen' than _D_EXACT_NAMLEN. 77 */ 78 79 #ifdef _DIRENT_HAVE_D_NAMLEN 80 #define _D_EXACT_NAMLEN(d) ((d)->d_namlen) 81 #define _D_ALLOC_NAMLEN(d) (_D_EXACT_NAMLEN (d) + 1) 82 #else 83 #define _D_EXACT_NAMLEN(d) (strlen ((d)->d_name)) 84 #ifdef _DIRENT_HAVE_D_RECLEN 85 #define _D_ALLOC_NAMLEN(d) (((char *) (d) + (d)->d_reclen) - &(d)->d_name[0]) 86 #else 87 #define _D_ALLOC_NAMLEN(d) (sizeof (d)->d_name > 1 ? sizeof (d)->d_name : \ 88 _D_EXACT_NAMLEN (d) + 1) 89 #endif 90 #endif 91 92 #ifdef __USE_MISC 93 /* File types for `d_type'. */ 94 enum { 95 DT_UNKNOWN = 0, 96 #define DT_UNKNOWN DT_UNKNOWN 97 DT_FIFO = 1, 98 #define DT_FIFO DT_FIFO 99 DT_CHR = 2, 100 #define DT_CHR DT_CHR 101 DT_DIR = 4, 102 #define DT_DIR DT_DIR 103 DT_BLK = 6, 104 #define DT_BLK DT_BLK 105 DT_REG = 8, 106 #define DT_REG DT_REG 107 DT_LNK = 10, 108 #define DT_LNK DT_LNK 109 DT_SOCK = 12, 110 #define DT_SOCK DT_SOCK 111 DT_WHT = 14 112 #define DT_WHT DT_WHT 113 }; 114 115 /* Convert between stat structure types and directory types. */ 116 #define IFTODT(mode) (((mode) & 0170000) >> 12) 117 #define DTTOIF(dirtype) ((dirtype) << 12) 118 #endif 119 120 /* This is the data type of directory stream objects. 121 The actual structure is opaque to users. */ 122 typedef struct __dirstream DIR; 123 124 /* Open a directory stream on NAME. 125 Return a DIR stream on the directory, or NULL if it could not be opened. 126 127 This function is a possible cancellation point and therefore not 128 marked with __THROW. */ 129 extern DIR *opendir(const char *__name) __nonnull((1)); 130 131 #ifdef __USE_XOPEN2K8 132 /* Same as opendir, but open the stream on the file descriptor FD. 133 134 This function is a possible cancellation point and therefore not 135 marked with __THROW. */ 136 extern DIR *fdopendir(int __fd); 137 #endif 138 139 /* Close the directory stream DIRP. 140 Return 0 if successful, -1 if not. 141 142 This function is a possible cancellation point and therefore not 143 marked with __THROW. */ 144 extern int closedir(DIR * __dirp) __nonnull((1)); 145 146 /* Read a directory entry from DIRP. Return a pointer to a `struct 147 dirent' describing the entry, or NULL for EOF or error. The 148 storage returned may be overwritten by a later readdir call on the 149 same DIR stream. 150 151 If the Large File Support API is selected we have to use the 152 appropriate interface. 153 154 This function is a possible cancellation point and therefore not 155 marked with __THROW. */ 156 #ifndef __USE_FILE_OFFSET64 157 extern struct dirent *readdir(DIR * __dirp) __nonnull((1)); 158 #else 159 #ifdef __REDIRECT 160 extern struct dirent *__REDIRECT(readdir, (DIR * __dirp), readdir64) __nonnull((1)); 161 #else 162 #define readdir readdir64 163 #endif 164 #endif 165 166 #ifdef __USE_LARGEFILE64 167 extern struct dirent64 *readdir64(DIR * __dirp) __nonnull((1)); 168 #endif 169 170 #ifdef __USE_POSIX 171 /* Reentrant version of `readdir'. Return in RESULT a pointer to the 172 next entry. 173 174 This function is a possible cancellation point and therefore not 175 marked with __THROW. */ 176 #ifndef __USE_FILE_OFFSET64 177 extern int readdir_r(DIR * __restrict __dirp, struct dirent *__restrict __entry, struct dirent **__restrict __result) __nonnull((1, 2, 3)) __attribute_deprecated__; 178 #else 179 #ifdef __REDIRECT 180 extern int __REDIRECT(readdir_r, (DIR * __restrict __dirp, struct dirent * __restrict __entry, struct dirent ** __restrict __result), readdir64_r) __nonnull((1, 2, 3)) __attribute_deprecated__; 181 #else 182 #define readdir_r readdir64_r 183 #endif 184 #endif 185 186 #ifdef __USE_LARGEFILE64 187 extern int readdir64_r(DIR * __restrict __dirp, struct dirent64 *__restrict __entry, struct dirent64 **__restrict __result) __nonnull((1, 2, 3)) __attribute_deprecated__; 188 #endif 189 #endif /* POSIX or misc */ 190 191 /* Rewind DIRP to the beginning of the directory. */ 192 extern void rewinddir(DIR * __dirp) 193 __THROW __nonnull((1)); 194 195 #if defined __USE_MISC || defined __USE_XOPEN 196 #include <bits/types.h> 197 198 /* Seek to position POS on DIRP. */ 199 extern void seekdir(DIR * __dirp, long int __pos) 200 __THROW __nonnull((1)); 201 202 /* Return the current position of DIRP. */ 203 extern long int telldir(DIR * __dirp) 204 __THROW __nonnull((1)); 205 #endif 206 207 #ifdef __USE_XOPEN2K8 208 209 /* Return the file descriptor used by DIRP. */ 210 extern int dirfd(DIR * __dirp) 211 __THROW __nonnull((1)); 212 213 #if defined __OPTIMIZE__ && defined _DIR_dirfd 214 #define dirfd(dirp) _DIR_dirfd (dirp) 215 #endif 216 217 #ifdef __USE_MISC 218 #ifndef MAXNAMLEN 219 /* Get the definitions of the POSIX.1 limits. */ 220 #include <bits/posix1_lim.h> 221 222 /* `MAXNAMLEN' is the BSD name for what POSIX calls `NAME_MAX'. */ 223 #ifdef NAME_MAX 224 #define MAXNAMLEN NAME_MAX 225 #else 226 #define MAXNAMLEN 255 227 #endif 228 #endif 229 #endif 230 231 #define __need_size_t 232 #include <stddef.h> 233 234 /* Scan the directory DIR, calling SELECTOR on each directory entry. 235 Entries for which SELECT returns nonzero are individually malloc'd, 236 sorted using qsort with CMP, and collected in a malloc'd array in 237 *NAMELIST. Returns the number of entries selected, or -1 on error. 238 239 This function is a cancellation point and therefore not marked with 240 __THROW. */ 241 #ifndef __USE_FILE_OFFSET64 242 extern int scandir(const char *__restrict __dir, struct dirent ***__restrict __namelist, int (*__selector) (const struct dirent *), int (*__cmp) (const struct dirent **, const struct dirent **)) __nonnull((1, 2)); 243 #else 244 #ifdef __REDIRECT 245 extern int __REDIRECT(scandir, (const char *__restrict __dir, struct dirent *** __restrict __namelist, int (*__selector) (const struct dirent *), int (*__cmp) (const struct dirent **, const struct dirent **)), scandir64) __nonnull((1, 2)); 246 #else 247 #define scandir scandir64 248 #endif 249 #endif 250 251 #if defined __USE_GNU && defined __USE_LARGEFILE64 252 /* This function is like `scandir' but it uses the 64bit dirent structure. 253 Please note that the CMP function must now work with struct dirent64 **. */ 254 extern int scandir64(const char *__restrict __dir, struct dirent64 ***__restrict __namelist, int (*__selector) (const struct dirent64 *), int (*__cmp) (const struct dirent64 **, const struct dirent64 **)) __nonnull((1, 2)); 255 #endif 256 257 #ifdef __USE_GNU 258 /* Similar to `scandir' but a relative DIR name is interpreted relative 259 to the directory for which DFD is a descriptor. 260 261 This function is a cancellation point and therefore not marked with 262 __THROW. */ 263 #ifndef __USE_FILE_OFFSET64 264 extern int scandirat(int __dfd, const char *__restrict __dir, struct dirent ***__restrict __namelist, int (*__selector) (const struct dirent *), int (*__cmp) (const struct dirent **, const struct dirent **)) __nonnull((2, 3)); 265 #else 266 #ifdef __REDIRECT 267 extern int __REDIRECT(scandirat, (int __dfd, const char *__restrict __dir, struct dirent *** __restrict __namelist, int (*__selector) (const struct dirent *), int (*__cmp) (const struct dirent **, const struct dirent **)), scandirat64) __nonnull((2, 3)); 268 #else 269 #define scandirat scandirat64 270 #endif 271 #endif 272 273 /* This function is like `scandir' but it uses the 64bit dirent structure. 274 Please note that the CMP function must now work with struct dirent64 **. */ 275 extern int scandirat64(int __dfd, const char *__restrict __dir, struct dirent64 ***__restrict __namelist, int (*__selector) (const struct dirent64 *), int (*__cmp) (const struct dirent64 **, const struct dirent64 **)) __nonnull((2, 3)); 276 #endif 277 278 /* Function to compare two `struct dirent's alphabetically. */ 279 #ifndef __USE_FILE_OFFSET64 280 extern int alphasort(const struct dirent **__e1, const struct dirent **__e2) 281 __THROW __attribute_pure__ __nonnull((1, 2)); 282 #else 283 #ifdef __REDIRECT 284 extern int __REDIRECT_NTH(alphasort, (const struct dirent ** __e1, const struct dirent ** __e2), alphasort64) 285 __attribute_pure__ __nonnull((1, 2)); 286 #else 287 #define alphasort alphasort64 288 #endif 289 #endif 290 291 #if defined __USE_GNU && defined __USE_LARGEFILE64 292 extern int alphasort64(const struct dirent64 **__e1, const struct dirent64 **__e2) 293 __THROW __attribute_pure__ __nonnull((1, 2)); 294 #endif 295 #endif /* Use XPG7. */ 296 297 #ifdef __USE_MISC 298 /* Read directory entries from FD into BUF, reading at most NBYTES. 299 Reading starts at offset *BASEP, and *BASEP is updated with the new 300 position after reading. Returns the number of bytes read; zero when at 301 end of directory; or -1 for errors. */ 302 #ifndef __USE_FILE_OFFSET64 303 extern __ssize_t getdirentries(int __fd, char *__restrict __buf, size_t __nbytes, __off_t * __restrict __basep) 304 __THROW __nonnull((2, 4)); 305 #else 306 #ifdef __REDIRECT 307 extern __ssize_t __REDIRECT_NTH(getdirentries, (int __fd, char *__restrict __buf, size_t __nbytes, __off64_t * __restrict __basep), getdirentries64) __nonnull((2, 4)); 308 #else 309 #define getdirentries getdirentries64 310 #endif 311 #endif 312 313 #ifdef __USE_LARGEFILE64 314 extern __ssize_t getdirentries64(int __fd, char *__restrict __buf, size_t __nbytes, __off64_t * __restrict __basep) 315 __THROW __nonnull((2, 4)); 316 #endif 317 #endif /* Use misc. */ 318 319 #ifdef __USE_GNU 320 /* Function to compare two `struct dirent's by name & version. */ 321 #ifndef __USE_FILE_OFFSET64 322 extern int versionsort(const struct dirent **__e1, const struct dirent **__e2) 323 __THROW __attribute_pure__ __nonnull((1, 2)); 324 #else 325 #ifdef __REDIRECT 326 extern int __REDIRECT_NTH(versionsort, (const struct dirent ** __e1, const struct dirent ** __e2), versionsort64) 327 __attribute_pure__ __nonnull((1, 2)); 328 #else 329 #define versionsort versionsort64 330 #endif 331 #endif 332 333 #ifdef __USE_LARGEFILE64 334 extern int versionsort64(const struct dirent64 **__e1, const struct dirent64 **__e2) 335 __THROW __attribute_pure__ __nonnull((1, 2)); 336 #endif 337 #endif /* Use GNU. */ 338 339 __END_DECLS 340 #endif /* dirent.h */