1 /**
2  * D header file for POSIX.
3  *
4  * Copyright: Public Domain
5  * License:   Public Domain
6  * Authors:   Sean Kelly
7  * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
8  */
9 module tango.stdc.posix.dirent;
10 
11 private import tango.stdc.posix.config;
12 public import tango.stdc.posix.sys.types; // for ino_t
13 
14 extern (C):
15 
16 //
17 // Required
18 //
19 /*
20 DIR
21 
22 struct dirent
23 {
24     char[] d_name;
25 }
26 
27 int     closedir(DIR*);
28 DIR*    opendir(in char*);
29 dirent* readdir(DIR*);
30 void    rewinddir(DIR*);
31 */
32 
33 version( linux )
34 {
35     // NOTE: The following constants are non-standard Linux definitions
36     //       for dirent.d_type.
37     enum
38     {
39         DT_UNKNOWN  = 0,
40         DT_FIFO     = 1,
41         DT_CHR      = 2,
42         DT_DIR      = 4,
43         DT_BLK      = 6,
44         DT_REG      = 8,
45         DT_LNK      = 10,
46         DT_SOCK     = 12,
47         DT_WHT      = 14
48     }
49 
50     struct dirent
51     {
52         inol_t       d_ino;
53         off_t       d_off;
54         ushort      d_reclen;
55         ubyte       d_type;
56         char[256]   d_name;
57     }
58 
59     struct DIR
60     {
61         // Managed by OS
62     }
63 
64     static if( __USE_LARGEFILE64 )
65     {
66         dirent* readdir64(DIR*);
67         alias   readdir64 readdir;
68     }
69     else
70     {
71         dirent* readdir(DIR*);
72     }
73 }
74 else version( darwin )
75 {
76     enum
77     {
78         DT_UNKNOWN  = 0,
79         DT_FIFO     = 1,
80         DT_CHR      = 2,
81         DT_DIR      = 4,
82         DT_BLK      = 6,
83         DT_REG      = 8,
84         DT_LNK      = 10,
85         DT_SOCK     = 12,
86         DT_WHT      = 14
87     }
88 
89     align(4)
90     struct dirent
91     {
92         ino_t       d_ino;
93         ushort      d_reclen;
94         ubyte       d_type;
95         ubyte       d_namlen;
96         char[256]   d_name;
97     }
98 
99     struct DIR
100     {
101         // Managed by OS
102     }
103 
104     dirent* readdir(DIR*);
105 }
106 else version( FreeBSD )
107 {
108     enum
109     {
110         DT_UNKNOWN  = 0,
111         DT_FIFO     = 1,
112         DT_CHR      = 2,
113         DT_DIR      = 4,
114         DT_BLK      = 6,
115         DT_REG      = 8,
116         DT_LNK      = 10,
117         DT_SOCK     = 12,
118         DT_WHT      = 14
119     }
120 
121     align(4)
122     struct dirent
123     {
124         uint      d_fileno;
125         ushort    d_reclen;
126         ubyte     d_type;
127         ubyte     d_namelen;
128         char[256] d_name;
129     }
130 
131     struct _telldir;
132     struct DIR
133     {
134         int       dd_fd;
135         c_long    dd_loc;
136         c_long    dd_size;
137         char*     dd_buf;
138         int       dd_len;
139         c_long    dd_seek;
140         c_long    dd_rewind;
141         int       dd_flags;
142         void*     dd_lock;
143         _telldir* dd_td;
144     }
145 
146     dirent* readdir(DIR*);
147 }
148 else version( solaris )
149 {
150     // NOTE: The following constants are non-standard Linux definitions
151     //       for dirent.d_type.
152     enum
153     {
154         DT_UNKNOWN  = 0,
155         DT_FIFO     = 1,
156         DT_CHR      = 2,
157         DT_DIR      = 4,
158         DT_BLK      = 6,
159         DT_REG      = 8,
160         DT_LNK      = 10,
161         DT_SOCK     = 12,
162         DT_WHT      = 14
163     }
164     
165     struct dirent
166     {
167         inol_t       d_ino;      /* "inode number" of entry */
168         off_t       d_off;      /* offset of disk directory entry */
169         ushort      d_reclen;   /* length of this record */
170         char[256]   d_name;     /* name of file */
171     }
172     
173     struct DIR
174     {
175         int         d_fd;       /* file descriptor */
176         int         d_loc;      /* offset in block */
177         int         d_size;     /* amount of valid data */
178         char*       d_buf;      /* directory block */
179     }
180     
181     static if( __USE_LARGEFILE64 )
182     {
183         dirent* readdir64(DIR*);
184         alias   readdir64 readdir;
185     }
186     else
187     {
188         dirent* readdir(DIR*);
189     }
190 }
191 else
192 {
193     dirent* readdir(DIR*);
194 }
195 
196 int     closedir(DIR*);
197 DIR*    opendir(in char*);
198 //dirent* readdir(DIR*);
199 void    rewinddir(DIR*);
200 
201 //
202 // Thread-Safe Functions (TSF)
203 //
204 /*
205 int readdir_r(DIR*, dirent*, dirent**);
206 */
207 
208 version( linux )
209 {
210   static if( __USE_LARGEFILE64 )
211   {
212     int   readdir64_r(DIR*, dirent*, dirent**);
213     alias readdir64_r readdir_r;
214   }
215   else
216   {
217     int readdir_r(DIR*, dirent*, dirent**);
218   }
219 }
220 else version( darwin )
221 {
222     int readdir_r(DIR*, dirent*, dirent**);
223 }
224 else version( FreeBSD )
225 {
226     int readdir_r(DIR*, dirent*, dirent**);
227 }
228 else version( solaris )
229 {
230   static if( __USE_LARGEFILE64 )
231   {
232     int   readdir64_r(DIR*, dirent*, dirent**);
233     alias readdir64_r readdir_r;
234   }
235   else
236   {
237     int readdir_r(DIR*, dirent*, dirent**);
238   }
239 }
240 
241 //
242 // XOpen (XSI)
243 //
244 /*
245 void   seekdir(DIR*, c_long);
246 c_long telldir(DIR*);
247 */
248 
249 version( linux )
250 {
251     void   seekdir(DIR*, c_long);
252     c_long telldir(DIR*);
253 }