blob: e0a8fe6a2f47666ec46755060d38a4a4867ff353 [file] [log] [blame]
Rich Felker0b44a032011-02-12 00:22:29 -05001#ifndef _DIRENT_H
2#define _DIRENT_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
Rich Felkerc1a96582012-09-07 23:13:55 -04008#include <features.h>
Rich Felker400c5e52012-09-06 22:44:55 -04009
Rich Felker0b44a032011-02-12 00:22:29 -050010#define __NEED_ino_t
11#define __NEED_off_t
Rich Felker769fd4c2012-12-03 16:57:01 -050012#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
Rich Felker9a470b02012-08-24 14:23:16 -040013#define __NEED_size_t
14#endif
Rich Felker0b44a032011-02-12 00:22:29 -050015
16#include <bits/alltypes.h>
17
Rich Felker9448b052013-07-22 11:22:36 -040018typedef struct __dirstream DIR;
Rich Felker0b44a032011-02-12 00:22:29 -050019
Rostislav Skudnov1bc10ff2018-01-12 17:06:03 +000020#define _DIRENT_HAVE_D_RECLEN
21#define _DIRENT_HAVE_D_OFF
22#define _DIRENT_HAVE_D_TYPE
23
Rich Felkerbefa5862016-07-03 14:40:11 -040024struct dirent {
Rich Felker0b44a032011-02-12 00:22:29 -050025 ino_t d_ino;
26 off_t d_off;
27 unsigned short d_reclen;
28 unsigned char d_type;
Rich Felkerda88b162011-06-06 18:04:28 -040029 char d_name[256];
Rich Felker0b44a032011-02-12 00:22:29 -050030};
31
Rich Felker06baa2b2011-04-03 10:24:59 -040032#define d_fileno d_ino
33
Rich Felker0b44a032011-02-12 00:22:29 -050034int closedir(DIR *);
35DIR *fdopendir(int);
36DIR *opendir(const char *);
37struct dirent *readdir(DIR *);
Rich Felker400c5e52012-09-06 22:44:55 -040038int readdir_r(DIR *__restrict, struct dirent *__restrict, struct dirent **__restrict);
Rich Felker0b44a032011-02-12 00:22:29 -050039void rewinddir(DIR *);
Rich Felker0b44a032011-02-12 00:22:29 -050040int dirfd(DIR *);
41
42int alphasort(const struct dirent **, const struct dirent **);
43int scandir(const char *, struct dirent ***, int (*)(const struct dirent *), int (*)(const struct dirent **, const struct dirent **));
44
Rich Felker7597fc22016-10-20 17:20:01 -040045#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
46void seekdir(DIR *, long);
47long telldir(DIR *);
48#endif
49
Rich Felker419ae6d2012-05-22 21:52:08 -040050#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
Rich Felker5d0d6d92011-03-07 18:32:36 -050051#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 Felker769fd4c2012-12-03 16:57:01 -050062int getdents(int, struct dirent *, size_t);
Rich Felker91f7db22011-03-08 17:34:26 -050063#endif
Rich Felker5d0d6d92011-03-07 18:32:36 -050064
Rich Felkerfbffcee2012-06-13 11:14:38 -040065#ifdef _GNU_SOURCE
66int versionsort(const struct dirent **, const struct dirent **);
67#endif
68
Rich Felker3b94dab2012-06-04 08:03:56 -040069#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
Rich Felker2dd8d5e2012-05-04 00:13:23 -040070#define dirent64 dirent
71#define readdir64 readdir
72#define readdir64_r readdir_r
73#define scandir64 scandir
74#define alphasort64 alphasort
Rich Felkerfbffcee2012-06-13 11:14:38 -040075#define versionsort64 versionsort
Rich Felker2dd8d5e2012-05-04 00:13:23 -040076#define off64_t off_t
77#define ino64_t ino_t
Rich Felker0c42beb2012-08-13 14:50:30 -040078#define getdents64 getdents
79#endif
Rich Felker2dd8d5e2012-05-04 00:13:23 -040080
Rich Felker0b44a032011-02-12 00:22:29 -050081#ifdef __cplusplus
Rich Felker91f7db22011-03-08 17:34:26 -050082}
Rich Felker0b44a032011-02-12 00:22:29 -050083#endif
84
85#endif