Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 1 | #ifndef _DIRENT_H |
| 2 | #define _DIRENT_H |
| 3 | |
| 4 | #ifdef __cplusplus |
| 5 | extern "C" { |
| 6 | #endif |
| 7 | |
Rich Felker | c1a9658 | 2012-09-07 23:13:55 -0400 | [diff] [blame] | 8 | #include <features.h> |
Rich Felker | 400c5e5 | 2012-09-06 22:44:55 -0400 | [diff] [blame] | 9 | |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 10 | #define __NEED_ino_t |
| 11 | #define __NEED_off_t |
Rich Felker | 769fd4c | 2012-12-03 16:57:01 -0500 | [diff] [blame] | 12 | #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) |
Rich Felker | 9a470b0 | 2012-08-24 14:23:16 -0400 | [diff] [blame] | 13 | #define __NEED_size_t |
| 14 | #endif |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 15 | |
| 16 | #include <bits/alltypes.h> |
| 17 | |
Rich Felker | 9448b05 | 2013-07-22 11:22:36 -0400 | [diff] [blame] | 18 | typedef struct __dirstream DIR; |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 19 | |
Rostislav Skudnov | 1bc10ff | 2018-01-12 17:06:03 +0000 | [diff] [blame] | 20 | #define _DIRENT_HAVE_D_RECLEN |
| 21 | #define _DIRENT_HAVE_D_OFF |
| 22 | #define _DIRENT_HAVE_D_TYPE |
| 23 | |
Rich Felker | befa586 | 2016-07-03 14:40:11 -0400 | [diff] [blame] | 24 | struct dirent { |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 25 | ino_t d_ino; |
| 26 | off_t d_off; |
| 27 | unsigned short d_reclen; |
| 28 | unsigned char d_type; |
Rich Felker | da88b16 | 2011-06-06 18:04:28 -0400 | [diff] [blame] | 29 | char d_name[256]; |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 30 | }; |
| 31 | |
Rich Felker | 06baa2b | 2011-04-03 10:24:59 -0400 | [diff] [blame] | 32 | #define d_fileno d_ino |
| 33 | |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 34 | int closedir(DIR *); |
| 35 | DIR *fdopendir(int); |
| 36 | DIR *opendir(const char *); |
| 37 | struct dirent *readdir(DIR *); |
Rich Felker | 400c5e5 | 2012-09-06 22:44:55 -0400 | [diff] [blame] | 38 | int readdir_r(DIR *__restrict, struct dirent *__restrict, struct dirent **__restrict); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 39 | void rewinddir(DIR *); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 40 | int dirfd(DIR *); |
| 41 | |
| 42 | int alphasort(const struct dirent **, const struct dirent **); |
| 43 | int scandir(const char *, struct dirent ***, int (*)(const struct dirent *), int (*)(const struct dirent **, const struct dirent **)); |
| 44 | |
Rich Felker | 7597fc2 | 2016-10-20 17:20:01 -0400 | [diff] [blame] | 45 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) |
| 46 | void seekdir(DIR *, long); |
| 47 | long telldir(DIR *); |
| 48 | #endif |
| 49 | |
Rich Felker | 419ae6d | 2012-05-22 21:52:08 -0400 | [diff] [blame] | 50 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) |
Rich Felker | 5d0d6d9 | 2011-03-07 18:32:36 -0500 | [diff] [blame] | 51 | #define DT_UNKNOWN 0 |
| 52 | #define DT_FIFO 1 |
| 53 | #define DT_CHR 2 |
| 54 | #define DT_DIR 4 |
| 55 | #define DT_BLK 6 |
| 56 | #define DT_REG 8 |
| 57 | #define DT_LNK 10 |
| 58 | #define DT_SOCK 12 |
| 59 | #define DT_WHT 14 |
| 60 | #define IFTODT(x) ((x)>>12 & 017) |
| 61 | #define DTTOIF(x) ((x)<<12) |
Rich Felker | 769fd4c | 2012-12-03 16:57:01 -0500 | [diff] [blame] | 62 | int getdents(int, struct dirent *, size_t); |
Rich Felker | 91f7db2 | 2011-03-08 17:34:26 -0500 | [diff] [blame] | 63 | #endif |
Rich Felker | 5d0d6d9 | 2011-03-07 18:32:36 -0500 | [diff] [blame] | 64 | |
Rich Felker | fbffcee | 2012-06-13 11:14:38 -0400 | [diff] [blame] | 65 | #ifdef _GNU_SOURCE |
| 66 | int versionsort(const struct dirent **, const struct dirent **); |
| 67 | #endif |
| 68 | |
Rich Felker | 3b94dab | 2012-06-04 08:03:56 -0400 | [diff] [blame] | 69 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) |
Rich Felker | 2dd8d5e | 2012-05-04 00:13:23 -0400 | [diff] [blame] | 70 | #define dirent64 dirent |
| 71 | #define readdir64 readdir |
| 72 | #define readdir64_r readdir_r |
| 73 | #define scandir64 scandir |
| 74 | #define alphasort64 alphasort |
Rich Felker | fbffcee | 2012-06-13 11:14:38 -0400 | [diff] [blame] | 75 | #define versionsort64 versionsort |
Rich Felker | 2dd8d5e | 2012-05-04 00:13:23 -0400 | [diff] [blame] | 76 | #define off64_t off_t |
| 77 | #define ino64_t ino_t |
Rich Felker | 0c42beb | 2012-08-13 14:50:30 -0400 | [diff] [blame] | 78 | #define getdents64 getdents |
| 79 | #endif |
Rich Felker | 2dd8d5e | 2012-05-04 00:13:23 -0400 | [diff] [blame] | 80 | |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 81 | #ifdef __cplusplus |
Rich Felker | 91f7db2 | 2011-03-08 17:34:26 -0500 | [diff] [blame] | 82 | } |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 83 | #endif |
| 84 | |
| 85 | #endif |