Debian Codegraph @

libphobos/libdruntime/core/sys/posix/dirent.d

raw
1 /**
2 * D header file for POSIX.
3 *
4 * Copyright: Copyright Sean Kelly 2005 - 2009.
5 * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
6 * Authors: Sean Kelly,
7 Alex Rønne Petersn
8 * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
9 */
10
11 /* Copyright Sean Kelly 2005 - 2009.
12 * Distributed under the Boost Software License, Version 1.0.
13 * (See accompanying file LICENSE or copy at
14 * http://www.boost.org/LICENSE_1_0.txt)
15 */
16 module core.sys.posix.dirent;
17
18 import core.sys.posix.config;
19 public import core.sys.posix.sys.types; // for ino_t
20
21 version (OSX)
22 version = Darwin;
23 else version (iOS)
24 version = Darwin;
25 else version (TVOS)
26 version = Darwin;
27 else version (WatchOS)
28 version = Darwin;
29
30 version (Posix):
31 extern (C):
32 nothrow:
33 @nogc:
34
35 //
36 // Required
37 //
38 /*
39 struct dirent
40 {
41 char[] d_name;
42 }
43 */
44
45 version (CRuntime_Bionic)
46 {
47 struct dirent
48 {
49 ulong d_ino;
50 long d_off;
51 ushort d_reclen;
52 ubyte d_type;
53 char[256] d_name = 0;
54 }
55 }
56 else version (linux)
57 {
58 struct dirent
59 {
60 ino_t d_ino;
61 off_t d_off;
62 ushort d_reclen;
63 ubyte d_type;
64 char[256] d_name = 0;
65 }
66 }
67 else version (Darwin)
68 {
69 // _DARWIN_FEATURE_64_BIT_INODE dirent is default for Mac OSX >10.5 and is
70 // only meaningful type for other OS X/Darwin variants (e.g. iOS).
71 // man dir(5) has some info, man stat(2) gives details.
72 struct dirent
73 {
74 ino_t d_ino;
75 alias d_fileno = d_ino;
76 ulong d_seekoff;
77 ushort d_reclen;
78 ushort d_namlen;
79 ubyte d_type;
80 char[1024] d_name = 0;
81 }
82 }
83 else version (FreeBSD)
84 {
85 import core.sys.freebsd.config;
86
87 static if (__FreeBSD_version >= 1200000)
88 {
89 struct dirent
90 {
91 ino_t d_fileno;
92 off_t d_off;
93 ushort d_reclen;
94 ubyte d_type;
95 ubyte d_pad0;
96 ushort d_namlen;
97 ushort d_pad1;
98 char[256] d_name = 0;
99 }
100 }
101 else
102 {
103 align(4)
104 struct dirent
105 {
106 uint d_fileno;
107 ushort d_reclen;
108 ubyte d_type;
109 ubyte d_namlen;
110 char[256] d_name = 0;
111 }
112 }
113 }
114 else version (NetBSD)
115 {
116 struct dirent
117 {
118 ulong d_fileno;
119 ushort d_reclen;
120 ushort d_namlen;
121 ubyte d_type;
122 char[512] d_name = 0;
123 }
124 }
125 else version (OpenBSD)
126 {
127 align(4)
128 struct dirent
129 {
130 ino_t d_fileno;
131 off_t d_off;
132 ushort d_reclen;
133 ubyte d_type;
134 ubyte d_namlen;
135 ubyte[4] __d_padding;
136 char[256] d_name = 0;
137 }
138 }
139 else version (DragonFlyBSD)
140 {
141 struct dirent
142 {
143 ino_t d_fileno; /* file number of entry */
144 ushort d_reclen; /* strlen(d_name) */
145 ubyte d_type; /* file type, see blow */
146 ubyte d_unused1; /* padding, reserved */
147 uint d_unused2; /* reserved */
148 char[256] d_name = 0; /* name, NUL-terminated */
149 }
150 }
151 else version (Solaris)
152 {
153 struct dirent
154 {
155 ino_t d_ino;
156 off_t d_off;
157 ushort d_reclen;
158 char[1] d_name = 0;
159 }
160 }
161 else
162 {
163 static assert(false, "Unsupported platform");
164 }
165
166 /*
167 DIR
168
169 int closedir(DIR*);
170 DIR* opendir(const scope char*);
171 dirent* readdir(DIR*);
172 void rewinddir(DIR*);
173 */
174
175 version (CRuntime_Glibc)
176 {
177 // NOTE: The following constants are non-standard Linux definitions
178 // for dirent.d_type.
179 enum
180 {
181 DT_UNKNOWN = 0,
182 DT_FIFO = 1,
183 DT_CHR = 2,
184 DT_DIR = 4,
185 DT_BLK = 6,
186 DT_REG = 8,
187 DT_LNK = 10,
188 DT_SOCK = 12,
189 DT_WHT = 14
190 }
191
192 struct DIR
193 {
194 // Managed by OS
195 }
196
197 static if ( __USE_FILE_OFFSET64 )
198 {
199 dirent* readdir64(DIR*);
200 alias readdir64 readdir;
201 }
202 else
203 {
204 dirent* readdir(DIR*);
205 }
206 }
207 else version (Darwin)
208 {
209 enum
210 {
211 DT_UNKNOWN = 0,
212 DT_FIFO = 1,
213 DT_CHR = 2,
214 DT_DIR = 4,
215 DT_BLK = 6,
216 DT_REG = 8,
217 DT_LNK = 10,
218 DT_SOCK = 12,
219 DT_WHT = 14
220 }
221
222 struct DIR
223 {
224 // Managed by OS
225 }
226
227 // OS X maintains backwards compatibility with older binaries using 32-bit
228 // inode functions by appending $INODE64 to newer 64-bit inode functions.
229 // Other Darwin variants (iOS, TVOS, WatchOS) only support 64-bit inodes,
230 // no suffix needed
231 version (OSX)
232 {
233 version (AArch64)
234 dirent* readdir(DIR*);
235 else
236 pragma(mangle, "readdir$INODE64") dirent* readdir(DIR*);
237 }
238 else
239 dirent* readdir(DIR*);
240 }
241 else version (FreeBSD)
242 {
243 import core.sys.freebsd.config;
244
245 // https://github.com/freebsd/freebsd/blob/master/sys/sys/dirent.h
246 enum
247 {
248 DT_UNKNOWN = 0,
249 DT_FIFO = 1,
250 DT_CHR = 2,
251 DT_DIR = 4,
252 DT_BLK = 6,
253 DT_REG = 8,
254 DT_LNK = 10,
255 DT_SOCK = 12,
256 DT_WHT = 14
257 }
258
259 alias void* DIR;
260
261 version (GNU)
262 {
263 dirent* readdir(DIR*);
264 }
265 else
266 {
267 static if (__FreeBSD_version >= 1200000)
268 pragma(mangle, "readdir@FBSD_1.5") dirent* readdir(DIR*);
269 else
270 pragma(mangle, "readdir@FBSD_1.0") dirent* readdir(DIR*);
271 }
272 }
273 else version (NetBSD)
274 {
275 enum
276 {
277 DT_UNKNOWN = 0,
278 DT_FIFO = 1,
279 DT_CHR = 2,
280 DT_DIR = 4,
281 DT_BLK = 6,
282 DT_REG = 8,
283 DT_LNK = 10,
284 DT_SOCK = 12,
285 DT_WHT = 14
286 }
287
288 alias void* DIR;
289
290 dirent* __readdir30(DIR*);
291 alias __readdir30 readdir;
292 }
293 else version (OpenBSD)
294 {
295 enum
296 {
297 DT_UNKNOWN = 0,
298 DT_FIFO = 1,
299 DT_CHR = 2,
300 DT_DIR = 4,
301 DT_BLK = 6,
302 DT_REG = 8,
303 DT_LNK = 10,
304 DT_SOCK = 12,
305 }
306
307 alias void* DIR;
308
309 dirent* readdir(DIR*);
310 }
311 else version (DragonFlyBSD)
312 {
313 enum
314 {
315 DT_UNKNOWN = 0,
316 DT_FIFO = 1,
317 DT_CHR = 2,
318 DT_DIR = 4,
319 DT_BLK = 6,
320 DT_REG = 8,
321 DT_LNK = 10,
322 DT_SOCK = 12,
323 DT_WHT = 14,
324 DT_DBF = 15, /* database record file */
325 }
326
327 alias void* DIR;
328
329 dirent* readdir(DIR*);
330 }
331 else version (Solaris)
332 {
333 struct DIR
334 {
335 int dd_fd;
336 int dd_loc;
337 int dd_size;
338 char* dd_buf;
339 }
340
341 version (D_LP64)
342 {
343 dirent* readdir(DIR*);
344 alias readdir64 = readdir;
345 }
346 else
347 {
348 static if (__USE_LARGEFILE64)
349 {
350 dirent* readdir64(DIR*);
351 alias readdir64 readdir;
352 }
353 else
354 {
355 dirent* readdir(DIR*);
356 }
357 }
358 }
359 else version (CRuntime_Bionic)
360 {
361 enum
362 {
363 DT_UNKNOWN = 0,
364 DT_FIFO = 1,
365 DT_CHR = 2,
366 DT_DIR = 4,
367 DT_BLK = 6,
368 DT_REG = 8,
369 DT_LNK = 10,
370 DT_SOCK = 12,
371 DT_WHT = 14
372 }
373
374 struct DIR
375 {
376 }
377
378 dirent* readdir(DIR*);
379 }
380 else version (CRuntime_Musl)
381 {
382 enum
383 {
384 DT_UNKNOWN = 0,
385 DT_FIFO = 1,
386 DT_CHR = 2,
387 DT_DIR = 4,
388 DT_BLK = 6,
389 DT_REG = 8,
390 DT_LNK = 10,
391 DT_SOCK = 12,
392 DT_WHT = 14
393 }
394
395 struct DIR
396 {
397 }
398
399 static if ( __USE_FILE_OFFSET64 )
400 {
401 dirent* readdir64(DIR*);
402 alias readdir64 readdir;
403 }
404 else
405 {
406 dirent* readdir(DIR*);
407 }
408 }
409 else version (CRuntime_UClibc)
410 {
411 // NOTE: The following constants are non-standard Linux definitions
412 // for dirent.d_type.
413 enum
414 {
415 DT_UNKNOWN = 0,
416 DT_FIFO = 1,
417 DT_CHR = 2,
418 DT_DIR = 4,
419 DT_BLK = 6,
420 DT_REG = 8,
421 DT_LNK = 10,
422 DT_SOCK = 12,
423 DT_WHT = 14
424 }
425
426 struct DIR
427 {
428 // Managed by OS
429 }
430
431 static if ( __USE_FILE_OFFSET64 )
432 {
433 dirent* readdir64(DIR*);
434 alias readdir64 readdir;
435 }
436 else
437 {
438 dirent* readdir(DIR*);
439 }
440 }
441 else
442 {
443 static assert(false, "Unsupported platform");
444 }
445
446 // Only OS X out of the Darwin family needs special treatment. Other Darwins
447 // (iOS, TVOS, WatchOS) are fine with normal symbol names for these functions
448 // in else below.
449 version (OSX)
450 {
451 version (AArch64)
452 {
453 int closedir(DIR*);
454 DIR* opendir(const scope char*);
455 void rewinddir(DIR*);
456 }
457 else version (D_LP64)
458 {
459 int closedir(DIR*);
460 pragma(mangle, "opendir$INODE64") DIR* opendir(const scope char*);
461 pragma(mangle, "rewinddir$INODE64") void rewinddir(DIR*);
462 }
463 else
464 {
465 // 32-bit mangles __DARWIN_UNIX03 specific functions with $UNIX2003 to
466 // maintain backward compatibility with binaries build pre 10.5
467 pragma(mangle, "closedir$UNIX2003") int closedir(DIR*);
468 pragma(mangle, "opendir$INODE64$UNIX2003") DIR* opendir(const scope char*);
469 pragma(mangle, "rewinddir$INODE64$UNIX2003") void rewinddir(DIR*);
470 }
471 }
472 else version (NetBSD)
473 {
474 int closedir(DIR*);
475 DIR* __opendir30(const scope char*);
476 alias __opendir30 opendir;
477 void rewinddir(DIR*);
478 }
479 else
480 {
481 int closedir(DIR*);
482 DIR* opendir(const scope char*);
483 //dirent* readdir(DIR*);
484 void rewinddir(DIR*);
485 }
486
487 //
488 // Thread-Safe Functions (TSF)
489 //
490 /*
491 int readdir_r(DIR*, dirent*, dirent**);
492 */
493
494 version (CRuntime_Glibc)
495 {
496 static if ( __USE_LARGEFILE64 )
497 {
498 int readdir64_r(DIR*, dirent*, dirent**);
499 alias readdir64_r readdir_r;
500 }
501 else
502 {
503 int readdir_r(DIR*, dirent*, dirent**);
504 }
505 }
506 else version (Darwin)
507 {
508 version (OSX)
509 pragma(mangle, "readdir_r$INODE64") int readdir_r(DIR*, dirent*, dirent**);
510 else
511 int readdir_r(DIR*, dirent*, dirent**);
512 }
513 else version (FreeBSD)
514 {
515 version (GNU)
516 {
517 int readdir_r(DIR*, dirent*, dirent**);
518 }
519 else
520 {
521 static if (__FreeBSD_version >= 1200000)
522 pragma(mangle, "readdir_r@FBSD_1.5") int readdir_r(DIR*, dirent*, dirent**);
523 else
524 pragma(mangle, "readdir_r@FBSD_1.0") int readdir_r(DIR*, dirent*, dirent**);
525 }
526 }
527 else version (DragonFlyBSD)
528 {
529 int readdir_r(DIR*, dirent*, dirent**);
530 }
531 else version (NetBSD)
532 {
533 int __readdir_r30(DIR*, dirent*, dirent**);
534 alias __readdir_r30 readdir_r;
535 }
536 else version (OpenBSD)
537 {
538 int readdir_r(DIR*, dirent*, dirent**);
539 }
540 else version (Solaris)
541 {
542 static if (__USE_LARGEFILE64)
543 {
544 int readdir64_r(DIR*, dirent*, dirent**);
545 alias readdir64_r readdir_r;
546 }
547 else
548 {
549 int readdir_r(DIR*, dirent*, dirent**);
550 }
551 }
552 else version (CRuntime_Bionic)
553 {
554 int readdir_r(DIR*, dirent*, dirent**);
555 }
556 else version (CRuntime_Musl)
557 {
558 int readdir_r(DIR*, dirent*, dirent**);
559 }
560 else version (CRuntime_UClibc)
561 {
562 static if ( __USE_LARGEFILE64 )
563 {
564 int readdir64_r(DIR*, dirent*, dirent**);
565 alias readdir64_r readdir_r;
566 }
567 else
568 {
569 int readdir_r(DIR*, dirent*, dirent**);
570 }
571 }
572 else
573 {
574 static assert(false, "Unsupported platform");
575 }
576
577 //
578 // XOpen (XSI)
579 //
580 /*
581 void seekdir(DIR*, c_long);
582 c_long telldir(DIR*);
583 */
584
585 version (CRuntime_Glibc)
586 {
587 void seekdir(DIR*, c_long);
588 c_long telldir(DIR*);
589 }
590 else version (FreeBSD)
591 {
592 version (GNU)
593 {
594 void seekdir(DIR*, c_long);
595 c_long telldir(DIR*);
596 }
597 else
598 {
599 pragma(mangle, "seekdir@@FBSD_1.0") void seekdir(DIR*, c_long);
600 pragma(mangle, "telldir@@FBSD_1.0") c_long telldir(DIR*);
601 }
602 }
603 else version (NetBSD)
604 {
605 void seekdir(DIR*, c_long);
606 c_long telldir(DIR*);
607 }
608 else version (OpenBSD)
609 {
610 void seekdir(DIR*, c_long);
611 c_long telldir(DIR*);
612 }
613 else version (DragonFlyBSD)
614 {
615 void seekdir(DIR*, c_long);
616 c_long telldir(DIR*);
617 }
618 else version (Darwin)
619 {
620 version (OSX)
621 {
622 version (D_LP64)
623 {
624 pragma(mangle, "seekdir$INODE64") void seekdir(DIR*, c_long);
625 pragma(mangle, "telldir$INODE64") c_long telldir(DIR*);
626 }
627 else
628 {
629 // 32-bit mangles __DARWIN_UNIX03 specific functions with $UNIX2003 to
630 // maintain backward compatibility with binaries build pre 10.5
631 pragma(mangle, "seekdir$INODE64$UNIX2003") void seekdir(DIR*, c_long);
632 pragma(mangle, "telldir$INODE64$UNIX2003") c_long telldir(DIR*);
633 }
634 }
635 else // other Darwins (e.g. iOS, TVOS, WatchOS)
636 {
637 void seekdir(DIR*, c_long);
638 c_long telldir(DIR*);
639 }
640 }
641 else version (Solaris)
642 {
643 c_long telldir(DIR*);
644 void seekdir(DIR*, c_long);
645 }
646 else version (CRuntime_Bionic)
647 {
648 }
649 else version (CRuntime_Musl)
650 {
651 void seekdir(DIR*, c_long);
652 c_long telldir(DIR*);
653 }
654 else version (CRuntime_UClibc)
655 {
656 void seekdir(DIR*, c_long);
657 c_long telldir(DIR*);
658 }
659 else
660 {
661 static assert(false, "Unsupported platform");
662 }