blob: 5aa8510bfd4330ba10d76c9ac7cc9756981f0bbe [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
20struct dirent
21{
22 ino_t d_ino;
23 off_t d_off;
24 unsigned short d_reclen;
25 unsigned char d_type;
Rich Felkerda88b162011-06-06 18:04:28 -040026 char d_name[256];
Rich Felker0b44a032011-02-12 00:22:29 -050027};
28
Rich Felker06baa2b2011-04-03 10:24:59 -040029#define d_fileno d_ino
30
Rich Felker0b44a032011-02-12 00:22:29 -050031int closedir(DIR *);
32DIR *fdopendir(int);
33DIR *opendir(const char *);
34struct dirent *readdir(DIR *);
Rich Felker400c5e52012-09-06 22:44:55 -040035int readdir_r(DIR *__restrict, struct dirent *__restrict, struct dirent **__restrict);
Rich Felker0b44a032011-02-12 00:22:29 -050036void rewinddir(DIR *);
37void seekdir(DIR *, long);
38long telldir(DIR *);
39int dirfd(DIR *);
40
41int alphasort(const struct dirent **, const struct dirent **);
42int scandir(const char *, struct dirent ***, int (*)(const struct dirent *), int (*)(const struct dirent **, const struct dirent **));
43
Rich Felker419ae6d2012-05-22 21:52:08 -040044#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
Rich Felker5d0d6d92011-03-07 18:32:36 -050045#define DT_UNKNOWN 0
46#define DT_FIFO 1
47#define DT_CHR 2
48#define DT_DIR 4
49#define DT_BLK 6
50#define DT_REG 8
51#define DT_LNK 10
52#define DT_SOCK 12
53#define DT_WHT 14
54#define IFTODT(x) ((x)>>12 & 017)
55#define DTTOIF(x) ((x)<<12)
Rich Felker769fd4c2012-12-03 16:57:01 -050056int getdents(int, struct dirent *, size_t);
Rich Felker91f7db22011-03-08 17:34:26 -050057#endif
Rich Felker5d0d6d92011-03-07 18:32:36 -050058
Rich Felkerfbffcee2012-06-13 11:14:38 -040059#ifdef _GNU_SOURCE
60int versionsort(const struct dirent **, const struct dirent **);
61#endif
62
Rich Felker3b94dab2012-06-04 08:03:56 -040063#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
Rich Felker2dd8d5e2012-05-04 00:13:23 -040064#define dirent64 dirent
65#define readdir64 readdir
66#define readdir64_r readdir_r
67#define scandir64 scandir
68#define alphasort64 alphasort
Rich Felkerfbffcee2012-06-13 11:14:38 -040069#define versionsort64 versionsort
Rich Felker2dd8d5e2012-05-04 00:13:23 -040070#define off64_t off_t
71#define ino64_t ino_t
Rich Felker0c42beb2012-08-13 14:50:30 -040072#define getdents64 getdents
73#endif
Rich Felker2dd8d5e2012-05-04 00:13:23 -040074
Rich Felker0b44a032011-02-12 00:22:29 -050075#ifdef __cplusplus
Rich Felker91f7db22011-03-08 17:34:26 -050076}
Rich Felker0b44a032011-02-12 00:22:29 -050077#endif
78
79#endif