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, Alex Rønne Petersen
7  * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
8  */
9 
10 /*          Copyright Sean Kelly 2005 - 2009.
11  * Distributed under the Boost Software License, Version 1.0.
12  *    (See accompanying file LICENSE or copy at
13  *          http://www.boost.org/LICENSE_1_0.txt)
14  */
15 module core.sys.posix.sys.stat;
16 
17 import core.sys.posix.config;
18 import core.stdc.stdint;
19 import core.sys.posix.time;     // for timespec
20 public import core.sys.posix.sys.types; // for off_t, mode_t
21 
22 version (OSX)
23     version = Darwin;
24 else version (iOS)
25     version = Darwin;
26 else version (TVOS)
27     version = Darwin;
28 else version (WatchOS)
29     version = Darwin;
30 
31 version (RISCV32) version = RISCV_Any;
32 version (RISCV64) version = RISCV_Any;
33 version (SPARC)   version = SPARC_Any;
34 version (SPARC64) version = SPARC_Any;
35 
36 version (Posix):
37 extern (C) nothrow @nogc:
38 
39 //
40 // Required
41 //
42 /*
43 struct stat
44 {
45     dev_t   st_dev;
46     ino_t   st_ino;
47     mode_t  st_mode;
48     nlink_t st_nlink;
49     uid_t   st_uid;
50     gid_t   st_gid;
51     off_t   st_size;
52     time_t  st_atime;
53     time_t  st_mtime;
54     time_t  st_ctime;
55 }
56 
57 S_ISUID
58 S_ISGID
59 S_ISVTX
60 
61 S_TYPEISMQ(buf)
62 S_TYPEISSEM(buf)
63 S_TYPEISSHM(buf)
64  */
65 
66 version (linux)
67 {
68     version (X86)
69     {
70         struct stat_t
71         {
72             dev_t       st_dev;
73             ushort      __pad1;
74             static if (!__USE_FILE_OFFSET64)
75             {
76                 ino_t       st_ino;
77             }
78             else
79             {
80                 uint        __st_ino;
81             }
82             mode_t      st_mode;
83             nlink_t     st_nlink;
84             uid_t       st_uid;
85             gid_t       st_gid;
86             dev_t       st_rdev;
87             ushort      __pad2;
88             off_t       st_size;
89             blksize_t   st_blksize;
90             blkcnt_t    st_blocks;
91             static if (_DEFAULT_SOURCE || _XOPEN_SOURCE >= 700)
92             {
93                 timespec    st_atim;
94                 timespec    st_mtim;
95                 timespec    st_ctim;
96                 extern(D) @safe @property inout pure nothrow
97                 {
98                     ref inout(time_t) st_atime() return { return st_atim.tv_sec; }
99                     ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; }
100                     ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; }
101                 }
102             }
103             else
104             {
105                 time_t      st_atime;
106                 ulong_t     st_atimensec;
107                 time_t      st_mtime;
108                 ulong_t     st_mtimensec;
109                 time_t      st_ctime;
110                 ulong_t     st_ctimensec;
111             }
112             static if (__USE_FILE_OFFSET64)
113             {
114                 ino_t       st_ino;
115             }
116             else
117             {
118                 c_ulong     __unused4;
119                 c_ulong     __unused5;
120             }
121         }
122     }
123     else version (X86_64)
124     {
125         struct stat_t
126         {
127             dev_t       st_dev;
128             ino_t       st_ino;
129             nlink_t     st_nlink;
130             mode_t      st_mode;
131             uid_t       st_uid;
132             gid_t       st_gid;
133             uint        __pad0;
134             dev_t       st_rdev;
135             off_t       st_size;
136             blksize_t   st_blksize;
137             blkcnt_t    st_blocks;
138             static if (_DEFAULT_SOURCE || _XOPEN_SOURCE >= 700)
139             {
140                 timespec    st_atim;
141                 timespec    st_mtim;
142                 timespec    st_ctim;
143                 extern(D) @safe @property inout pure nothrow
144                 {
145                     ref inout(time_t) st_atime() return { return st_atim.tv_sec; }
146                     ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; }
147                     ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; }
148                 }
149             }
150             else
151             {
152                 time_t      st_atime;
153                 ulong_t     st_atimensec;
154                 time_t      st_mtime;
155                 ulong_t     st_mtimensec;
156                 time_t      st_ctime;
157                 ulong_t     st_ctimensec;
158             }
159             slong_t[3]     __unused;
160         }
161     }
162     else version (HPPA)
163     {
164         private
165         {
166             alias __dev_t = ulong;
167             alias __ino_t = c_ulong;
168             alias __ino64_t = ulong;
169             alias __mode_t = uint;
170             alias __nlink_t = size_t;
171             alias __uid_t = uint;
172             alias __gid_t = uint;
173             alias __off_t = c_long;
174             alias __off64_t = long;
175             alias __blksize_t = c_long;
176             alias __blkcnt_t = c_long;
177             alias __blkcnt64_t = long;
178             alias __timespec = timespec;
179             alias __time_t = time_t;
180         }
181         struct stat_t
182         {
183             __dev_t st_dev;
184             ushort __pad1;
185 
186             static if (!__USE_FILE_OFFSET64)
187             {
188                 __ino_t st_ino;
189             }
190             else
191             {
192                 __ino_t __st_ino;
193             }
194             __mode_t st_mode;
195             __nlink_t st_nlink;
196             __uid_t st_uid;
197             __gid_t st_gid;
198             __dev_t st_rdev;
199             ushort __pad2;
200 
201             static if (!__USE_FILE_OFFSET64)
202             {
203                 __off_t st_size;
204             }
205             else
206             {
207                 __off64_t st_size;
208             }
209             __blksize_t st_blksize;
210 
211             static if (!__USE_FILE_OFFSET64)
212             {
213                 __blkcnt_t st_blocks;
214             }
215             else
216             {
217                 __blkcnt64_t st_blocks;
218             }
219 
220             static if ( _DEFAULT_SOURCE || _XOPEN_SOURCE >= 700)
221             {
222                 __timespec st_atim;
223                 __timespec st_mtim;
224                 __timespec st_ctim;
225                 extern(D) @safe @property inout pure nothrow
226                 {
227                     ref inout(time_t) st_atime() return { return st_atim.tv_sec; }
228                     ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; }
229                     ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; }
230                 }
231             }
232             else
233             {
234                 __time_t st_atime;
235                 c_ulong st_atimensec;
236                 __time_t st_mtime;
237                 c_ulong st_mtimensec;
238                 __time_t st_ctime;
239                 c_ulong st_ctimensec;
240             }
241 
242             static if (!__USE_FILE_OFFSET64)
243             {
244                 c_ulong __unused4;
245                 c_ulong __unused5;
246             }
247             else
248             {
249                 __ino64_t st_ino;
250             }
251         }
252         static if (__USE_FILE_OFFSET64)
253             static assert(stat_t.sizeof == 104);
254         else
255             static assert(stat_t.sizeof == 88);
256     }
257     else version (MIPS_O32)
258     {
259         struct stat_t
260         {
261             c_ulong     st_dev;
262             c_long[3]   st_pad1;
263             ino_t       st_ino;
264             mode_t      st_mode;
265             nlink_t     st_nlink;
266             uid_t       st_uid;
267             gid_t       st_gid;
268             c_ulong     st_rdev;
269             static if (!__USE_FILE_OFFSET64)
270             {
271                 c_long[2]   st_pad2;
272                 off_t       st_size;
273                 c_long      st_pad3;
274             }
275             else
276             {
277                 c_long[3]   st_pad2;
278                 off_t       st_size;
279             }
280             static if (_DEFAULT_SOURCE || _XOPEN_SOURCE >= 700)
281             {
282                 timespec    st_atim;
283                 timespec    st_mtim;
284                 timespec    st_ctim;
285                 extern(D) @safe @property inout pure nothrow
286                 {
287                     ref inout(time_t) st_atime() return { return st_atim.tv_sec; }
288                     ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; }
289                     ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; }
290                 }
291             }
292             else
293             {
294                 time_t      st_atime;
295                 c_ulong     st_atimensec;
296                 time_t      st_mtime;
297                 c_ulong     st_mtimensec;
298                 time_t      st_ctime;
299                 c_ulong     st_ctimensec;
300             }
301             blksize_t   st_blksize;
302             static if (!__USE_FILE_OFFSET64)
303             {
304                 blkcnt_t    st_blocks;
305             }
306             else
307             {
308                 c_long      st_pad4;
309                 blkcnt_t    st_blocks;
310             }
311             c_long[14]  st_pad5;
312         }
313         static if (!__USE_FILE_OFFSET64)
314             static assert(stat_t.sizeof == 144);
315         else
316             static assert(stat_t.sizeof == 160);
317     }
318     else version (MIPS64)
319     {
320         struct stat_t
321         {
322             dev_t       st_dev;
323             int[3]      st_pad1;
324             ino_t       st_ino;
325             mode_t      st_mode;
326             nlink_t     st_nlink;
327             uid_t       st_uid;
328             gid_t       st_gid;
329             dev_t       st_rdev;
330             static if (!__USE_FILE_OFFSET64)
331             {
332                 uint[2]     st_pad2;
333                 off_t       st_size;
334                 int         st_pad3;
335             }
336             else
337             {
338                 uint[3]     st_pad2;
339                 off_t       st_size;
340             }
341             static if (_DEFAULT_SOURCE || _XOPEN_SOURCE >= 700)
342             {
343                 timespec    st_atim;
344                 timespec    st_mtim;
345                 timespec    st_ctim;
346                 extern(D) @safe @property inout pure nothrow
347                 {
348                     ref inout(time_t) st_atime() return { return st_atim.tv_sec; }
349                     ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; }
350                     ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; }
351                 }
352             }
353             else
354             {
355                 time_t      st_atime;
356                 c_ulong     st_atimensec;
357                 time_t      st_mtime;
358                 c_ulong     st_mtimensec;
359                 time_t      st_ctime;
360                 c_ulong     st_ctimensec;
361             }
362             blksize_t   st_blksize;
363             uint        st_pad4;
364             blkcnt_t    st_blocks;
365             int[14]     st_pad5;
366         }
367         version (MIPS_N32)
368         {
369             static if (!__USE_FILE_OFFSET64)
370                 static assert(stat_t.sizeof == 160);
371             else
372                 static assert(stat_t.sizeof == 176);
373         }
374         else version (MIPS_O64)
375         {
376             static if (!__USE_FILE_OFFSET64)
377                 static assert(stat_t.sizeof == 160);
378             else
379                 static assert(stat_t.sizeof == 176);
380         }
381         else
382         {
383             static assert(stat_t.sizeof == 216);
384         }
385     }
386     else version (PPC)
387     {
388         struct stat_t
389         {
390             dev_t       st_dev;
391             static if (!__USE_FILE_OFFSET64)
392             {
393                 ushort  __pad1;
394                 ino_t   st_ino;
395             }
396             else
397                 ino_t   st_ino;
398             mode_t      st_mode;
399             nlink_t     st_nlink;
400             uid_t       st_uid;
401             gid_t       st_gid;
402             dev_t       st_rdev;
403             ushort      __pad2;
404             off_t       st_size;
405             blksize_t   st_blksize;
406             blkcnt_t    st_blocks;
407             static if (_DEFAULT_SOURCE || _XOPEN_SOURCE >= 700)
408             {
409                 timespec    st_atim;
410                 timespec    st_mtim;
411                 timespec    st_ctim;
412                 extern(D) @safe @property inout pure nothrow
413                 {
414                     ref inout(time_t) st_atime() return { return st_atim.tv_sec; }
415                     ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; }
416                     ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; }
417                 }
418             }
419             else
420             {
421                 time_t      st_atime;
422                 c_ulong     st_atimensec;
423                 time_t      st_mtime;
424                 c_ulong     st_mtimensec;
425                 time_t      st_ctime;
426                 c_ulong     st_ctimensec;
427             }
428             c_ulong     __unused4;
429             c_ulong     __unused5;
430         }
431         static if (__USE_FILE_OFFSET64)
432             static assert(stat_t.sizeof == 104);
433         else
434             static assert(stat_t.sizeof == 88);
435     }
436     else version (PPC64)
437     {
438         struct stat_t
439         {
440             dev_t       st_dev;
441             ino_t       st_ino;
442             nlink_t     st_nlink;
443             mode_t      st_mode;
444             uid_t       st_uid;
445             gid_t       st_gid;
446             int         __pad2;
447             dev_t       st_rdev;
448             off_t       st_size;
449             blksize_t   st_blksize;
450             blkcnt_t    st_blocks;
451             static if (_DEFAULT_SOURCE || _XOPEN_SOURCE >= 700)
452             {
453                 timespec    st_atim;
454                 timespec    st_mtim;
455                 timespec    st_ctim;
456                 extern(D) @safe @property inout pure nothrow
457                 {
458                     ref inout(time_t) st_atime() return { return st_atim.tv_sec; }
459                     ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; }
460                     ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; }
461                 }
462             }
463             else
464             {
465                 time_t      st_atime;
466                 c_ulong     st_atimensec;
467                 time_t      st_mtime;
468                 c_ulong     st_mtimensec;
469                 time_t      st_ctime;
470                 c_ulong     st_ctimensec;
471             }
472             c_ulong     __unused4;
473             c_ulong     __unused5;
474             c_ulong     __unused6;
475         }
476         static assert(stat_t.sizeof == 144);
477     }
478     else version (RISCV_Any)
479     {
480         private
481         {
482             alias __dev_t = ulong;
483             alias __ino_t = c_ulong;
484             alias __ino64_t = ulong;
485             alias __mode_t = uint;
486             alias __nlink_t = uint;
487             alias __uid_t = uint;
488             alias __gid_t = uint;
489             alias __off_t = c_long;
490             alias __off64_t = long;
491             alias __blksize_t = int;
492             alias __blkcnt_t = c_long;
493             alias __blkcnt64_t = long;
494             alias __timespec = timespec;
495             alias __time_t = time_t;
496         }
497         struct stat_t
498         {
499             __dev_t st_dev;
500 
501             static if (__USE_FILE_OFFSET64)
502             {
503                 __ino64_t st_ino;
504             }
505             else
506             {
507                 __ino_t st_ino;
508             }
509             __mode_t st_mode;
510             __nlink_t st_nlink;
511             __uid_t st_uid;
512             __gid_t st_gid;
513             __dev_t st_rdev;
514             __dev_t __pad1;
515 
516             static if (__USE_FILE_OFFSET64)
517             {
518                 __off64_t st_size;
519             }
520             else
521             {
522                 __off_t st_size;
523             }
524             __blksize_t st_blksize;
525             int __pad2;
526 
527             static if (__USE_FILE_OFFSET64)
528             {
529                 __blkcnt64_t st_blocks;
530             }
531             else
532             {
533                 __blkcnt_t st_blocks;
534             }
535 
536             static if (_DEFAULT_SOURCE)
537             {
538                 __timespec st_atim;
539                 __timespec st_mtim;
540                 __timespec st_ctim;
541                 extern(D) @safe @property inout pure nothrow
542                 {
543                     ref inout(time_t) st_atime() return { return st_atim.tv_sec; }
544                     ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; }
545                     ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; }
546                 }
547             }
548             else
549             {
550                 __time_t st_atime;
551                 c_ulong st_atimensec;
552                 __time_t st_mtime;
553                 c_ulong st_mtimensec;
554                 __time_t st_ctime;
555                 c_ulong st_ctimensec;
556             }
557             int[2] __unused;
558         }
559     }
560     else version (ARM)
561     {
562         private
563         {
564             alias __dev_t = ulong;
565             alias __ino_t = c_ulong;
566             alias __ino64_t = ulong;
567             alias __mode_t = uint;
568             alias __nlink_t = size_t;
569             alias __uid_t = uint;
570             alias __gid_t = uint;
571             alias __off_t = c_long;
572             alias __off64_t = long;
573             alias __blksize_t = c_long;
574             alias __blkcnt_t = c_long;
575             alias __blkcnt64_t = long;
576             alias __timespec = timespec;
577             alias __time_t = time_t;
578         }
579         struct stat_t
580         {
581             __dev_t st_dev;
582             ushort __pad1;
583 
584             static if (!__USE_FILE_OFFSET64)
585             {
586                 __ino_t st_ino;
587             }
588             else
589             {
590                 __ino_t __st_ino;
591             }
592             __mode_t st_mode;
593             __nlink_t st_nlink;
594             __uid_t st_uid;
595             __gid_t st_gid;
596             __dev_t st_rdev;
597             ushort __pad2;
598 
599             static if (!__USE_FILE_OFFSET64)
600             {
601                 __off_t st_size;
602             }
603             else
604             {
605                 __off64_t st_size;
606             }
607             __blksize_t st_blksize;
608 
609             static if (!__USE_FILE_OFFSET64)
610             {
611                 __blkcnt_t st_blocks;
612             }
613             else
614             {
615                 __blkcnt64_t st_blocks;
616             }
617 
618             static if ( _DEFAULT_SOURCE || _XOPEN_SOURCE >= 700)
619             {
620                 __timespec st_atim;
621                 __timespec st_mtim;
622                 __timespec st_ctim;
623                 extern(D) @safe @property inout pure nothrow
624                 {
625                     ref inout(time_t) st_atime() return { return st_atim.tv_sec; }
626                     ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; }
627                     ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; }
628                 }
629             }
630             else
631             {
632                 __time_t st_atime;
633                 c_ulong st_atimensec;
634                 __time_t st_mtime;
635                 c_ulong st_mtimensec;
636                 __time_t st_ctime;
637                 c_ulong st_ctimensec;
638             }
639 
640             static if (!__USE_FILE_OFFSET64)
641             {
642                 c_ulong __unused4;
643                 c_ulong __unused5;
644             }
645             else
646             {
647                 __ino64_t st_ino;
648             }
649         }
650         static if (__USE_FILE_OFFSET64)
651             static assert(stat_t.sizeof == 104);
652         else
653             static assert(stat_t.sizeof == 88);
654     }
655     else version (AArch64)
656     {
657         private
658         {
659             alias __dev_t = ulong;
660             alias __ino_t = c_ulong;
661             alias __ino64_t = ulong;
662             alias __mode_t = uint;
663             alias __nlink_t = uint;
664             alias __uid_t = uint;
665             alias __gid_t = uint;
666             alias __off_t = c_long;
667             alias __off64_t = long;
668             alias __blksize_t = int;
669             alias __blkcnt_t = c_long;
670             alias __blkcnt64_t = long;
671             alias __timespec = timespec;
672             alias __time_t = time_t;
673         }
674         struct stat_t
675         {
676             __dev_t st_dev;
677 
678             static if (!__USE_FILE_OFFSET64)
679             {
680                 __ino_t st_ino;
681             }
682             else
683             {
684                 __ino64_t st_ino;
685             }
686             __mode_t st_mode;
687             __nlink_t st_nlink;
688             __uid_t st_uid;
689             __gid_t st_gid;
690             __dev_t st_rdev;
691             __dev_t __pad1;
692 
693             static if (!__USE_FILE_OFFSET64)
694             {
695                 __off_t st_size;
696             }
697             else
698             {
699                 __off64_t st_size;
700             }
701             __blksize_t st_blksize;
702             int __pad2;
703 
704             static if (!__USE_FILE_OFFSET64)
705             {
706                 __blkcnt_t st_blocks;
707             }
708             else
709             {
710                 __blkcnt64_t st_blocks;
711             }
712 
713             static if (_DEFAULT_SOURCE)
714             {
715                 __timespec st_atim;
716                 __timespec st_mtim;
717                 __timespec st_ctim;
718                 extern(D) @safe @property inout pure nothrow
719                 {
720                     ref inout(time_t) st_atime() return { return st_atim.tv_sec; }
721                     ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; }
722                     ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; }
723                 }
724             }
725             else
726             {
727                 __time_t st_atime;
728                 c_ulong st_atimensec;
729                 __time_t st_mtime;
730                 c_ulong st_mtimensec;
731                 __time_t st_ctime;
732                 c_ulong st_ctimensec;
733             }
734             int[2] __unused;
735         }
736         version (D_LP64)
737             static assert(stat_t.sizeof == 128);
738         else
739             static assert(stat_t.sizeof == 104);
740     }
741     else version (SPARC_Any)
742     {
743         private
744         {
745             alias __dev_t = ulong;
746             alias __ino_t = c_ulong;
747             alias __ino64_t = ulong;
748             alias __mode_t = uint;
749             alias __nlink_t = uint;
750             alias __uid_t = uint;
751             alias __gid_t = uint;
752             alias __off_t = c_long;
753             alias __off64_t = long;
754             alias __blksize_t = c_long;
755             alias __blkcnt_t = c_long;
756             alias __blkcnt64_t = long;
757             alias __timespec = timespec;
758             alias __time_t = time_t;
759         }
760         struct stat_t
761         {
762             __dev_t st_dev;
763             static if (__WORDSIZE == 64 || !__USE_FILE_OFFSET64)
764             {
765                 ushort __pad1;
766                 __ino_t st_ino;
767             }
768             else
769             {
770                 __ino64_t st_ino;
771             }
772             __mode_t st_mode;
773             __nlink_t st_nlink;
774             __uid_t st_uid;
775             __gid_t st_gid;
776             __dev_t st_rdev;
777             ushort __pad2;
778 
779             static if (!__USE_FILE_OFFSET64)
780             {
781                 __off_t st_size;
782             }
783             else
784             {
785                 __off64_t st_size;
786             }
787             __blksize_t st_blksize;
788 
789             static if (!__USE_FILE_OFFSET64)
790             {
791                 __blkcnt_t st_blocks;
792             }
793             else
794             {
795                 __blkcnt64_t st_blocks;
796             }
797 
798             static if (_XOPEN_SOURCE >= 700)
799             {
800                 __timespec st_atim;
801                 __timespec st_mtim;
802                 __timespec st_ctim;
803                 extern(D) @safe @property inout pure nothrow
804                 {
805                     ref inout(time_t) st_atime() return { return st_atim.tv_sec; }
806                     ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; }
807                     ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; }
808                 }
809             }
810             else
811             {
812                 __time_t st_atime;
813                 c_ulong st_atimensec;
814                 __time_t st_mtime;
815                 c_ulong st_mtimensec;
816                 __time_t st_ctime;
817                 c_ulong st_ctimensec;
818             }
819 
820             c_ulong __unused4;
821             c_ulong __unused5;
822         }
823         static if (__USE_LARGEFILE64) alias stat_t stat64_t;
824 
825         static if (__WORDSIZE == 64)
826             static assert(stat_t.sizeof == 144);
827         else static if (__USE_FILE_OFFSET64)
828             static assert(stat_t.sizeof == 104);
829         else
830             static assert(stat_t.sizeof == 88);
831 
832     }
833     else version (S390)
834     {
835         private
836         {
837             alias __dev_t = ulong;
838             alias __ino_t = c_ulong;
839             alias __ino64_t = ulong;
840             alias __mode_t = uint;
841             alias __nlink_t = uint;
842             alias __uid_t = uint;
843             alias __gid_t = uint;
844             alias __off_t = c_long;
845             alias __off64_t = long;
846             alias __blksize_t = c_long;
847             alias __blkcnt_t = c_long;
848             alias __blkcnt64_t = long;
849             alias __timespec = timespec;
850             alias __time_t = time_t;
851         }
852         struct stat_t
853         {
854             __dev_t st_dev;
855             uint __pad1;
856             static if (!__USE_FILE_OFFSET64)
857                 __ino_t st_ino;
858             else
859                 __ino_t __st_ino;
860             __mode_t st_mode;
861             __nlink_t st_nlink;
862             __uid_t st_uid;
863             __gid_t st_gid;
864             __dev_t st_rdev;
865             uint __pad2;
866             static if (!__USE_FILE_OFFSET64)
867                 __off_t st_size;
868             else
869                 __off64_t st_size;
870             __blksize_t st_blksize;
871             static if (!__USE_FILE_OFFSET64)
872                 __blkcnt_t st_blocks;
873             else
874                 __blkcnt64_t st_blocks;
875             static if (_XOPEN_SOURCE >= 700)
876             {
877                 __timespec st_atim;
878                 __timespec st_mtim;
879                 __timespec st_ctim;
880                 extern(D) @safe @property inout pure nothrow
881                 {
882                     ref inout(time_t) st_atime() return { return st_atim.tv_sec; }
883                     ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; }
884                     ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; }
885                 }
886             }
887             else
888             {
889                 __time_t st_atime;
890                 c_ulong st_atimensec;
891                 __time_t st_mtime;
892                 c_ulong st_mtimensec;
893                 __time_t st_ctime;
894                 c_ulong st_ctimensec;
895             }
896             static if (!__USE_FILE_OFFSET64)
897             {
898                 c_ulong __glibc_reserved4;
899                 c_ulong __glibc_reserved5;
900             }
901             else
902                 __ino64_t st_ino;
903         }
904         static if (__USE_FILE_OFFSET64)
905             static assert(stat_t.sizeof == 104);
906         else
907             static assert(stat_t.sizeof == 88);
908     }
909     else version (SystemZ)
910     {
911         private
912         {
913             alias __dev_t = ulong;
914             alias __ino_t = c_ulong;
915             alias __ino64_t = ulong;
916             alias __mode_t = uint;
917             alias __nlink_t = ulong;
918             alias __uid_t = uint;
919             alias __gid_t = uint;
920             alias __off_t = c_long;
921             alias __off64_t = long;
922             alias __blksize_t = c_long;
923             alias __blkcnt_t = c_long;
924             alias __blkcnt64_t = long;
925             alias __timespec = timespec;
926             alias __time_t = time_t;
927         }
928         struct stat_t
929         {
930             __dev_t st_dev;
931             __ino_t st_ino;
932             __nlink_t st_nlink;
933             __mode_t st_mode;
934             __uid_t st_uid;
935             __gid_t st_gid;
936             int __glibc_reserved0;
937             __dev_t st_rdev;
938             __off_t st_size;
939             static if (_XOPEN_SOURCE >= 700)
940             {
941                 __timespec st_atim;
942                 __timespec st_mtim;
943                 __timespec st_ctim;
944                 extern(D) @safe @property inout pure nothrow
945                 {
946                     ref inout(time_t) st_atime() return { return st_atim.tv_sec; }
947                     ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; }
948                     ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; }
949                 }
950             }
951             else
952             {
953                 __time_t st_atime;
954                 c_ulong st_atimensec;
955                 __time_t st_mtime;
956                 c_ulong st_mtimensec;
957                 __time_t st_ctime;
958                 c_ulong st_ctimensec;
959             }
960             __blksize_t st_blksize;
961             __blkcnt_t st_blocks;
962             c_long[3] __glibc_reserved;
963         }
964         static if (_XOPEN_SOURCE >= 700)
965             static assert(stat_t.sizeof == 144);
966         else
967             static assert(stat_t.sizeof == 144);
968     }
969     else version (LoongArch64)
970     {
971         private
972         {
973             alias __dev_t = ulong;
974             alias __ino_t = c_ulong;
975             alias __ino64_t = ulong;
976             alias __mode_t = uint;
977             alias __nlink_t = uint;
978             alias __uid_t = uint;
979             alias __gid_t = uint;
980             alias __off_t = c_long;
981             alias __off64_t = long;
982             alias __blksize_t = int;
983             alias __blkcnt_t = c_long;
984             alias __blkcnt64_t = long;
985             alias __timespec = timespec;
986             alias __time_t = time_t;
987         }
988         struct stat_t
989         {
990             __dev_t st_dev;
991             __ino_t st_ino;
992             __mode_t st_mode;
993             __nlink_t st_nlink;
994             __uid_t st_uid;
995             __gid_t st_gid;
996             __dev_t st_rdev;
997             __dev_t __pad1;
998             // la64 always uses 64-bit file offsets
999             __off64_t st_size;
1000             __blksize_t st_blksize;
1001             int __pad2;
1002             // la64 always uses 64-bit block counts
1003             __blkcnt64_t st_blocks;
1004             static if (_XOPEN_SOURCE >= 700)
1005             {
1006                 __timespec st_atim;
1007                 __timespec st_mtim;
1008                 __timespec st_ctim;
1009                 extern(D) @safe @property inout pure nothrow
1010                 {
1011                     ref inout(time_t) st_atime() return { return st_atim.tv_sec; }
1012                     ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; }
1013                     ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; }
1014                 }
1015             }
1016             else
1017             {
1018                 __time_t st_atime;
1019                 c_ulong st_atimensec;
1020                 __time_t st_mtime;
1021                 c_ulong st_mtimensec;
1022                 __time_t st_ctime;
1023                 c_ulong st_ctimensec;
1024             }
1025             int[2] __glibc_reserved;
1026         }
1027         static assert(stat_t.sizeof == 128);
1028     }
1029     else
1030         static assert(0, "unimplemented");
1031 
1032     enum S_ISUID    = 0x800; // octal 04000
1033     enum S_ISGID    = 0x400; // octal 02000
1034     enum S_ISVTX    = 0x200; // octal 01000
1035 
1036     static if ( true /*__USE_POSIX199309*/ )
1037     {
1038         extern bool S_TYPEISMQ( stat_t* buf )  { return false; }
1039         extern bool S_TYPEISSEM( stat_t* buf ) { return false; }
1040         extern bool S_TYPEISSHM( stat_t* buf ) { return false; }
1041     }
1042 
1043     enum UTIME_NOW = 0x3fffffff;
1044     enum UTIME_OMIT = 0x3ffffffe;
1045 }
1046 else version (Darwin)
1047 {
1048     // _DARWIN_FEATURE_64_BIT_INODE stat is default for Mac OSX >10.5 and is
1049     // only meaningful type for other OS X/Darwin variants (e.g. iOS).
1050     // man stat(2) gives details.
1051     struct stat_t
1052     {
1053         dev_t       st_dev;
1054         mode_t      st_mode;
1055         nlink_t     st_nlink;
1056         ino_t       st_ino;
1057         uid_t       st_uid;
1058         gid_t       st_gid;
1059         dev_t       st_rdev;
1060         union
1061         {
1062             struct
1063             {
1064                 timespec  st_atimespec;
1065                 timespec  st_mtimespec;
1066                 timespec  st_ctimespec;
1067                 timespec  st_birthtimespec;
1068             }
1069             struct
1070             {
1071                 time_t      st_atime;
1072                 c_long      st_atimensec;
1073                 time_t      st_mtime;
1074                 c_long      st_mtimensec;
1075                 time_t      st_ctime;
1076                 c_long      st_ctimensec;
1077                 time_t      st_birthtime;
1078                 c_long      st_birthtimensec;
1079             }
1080         }
1081         off_t       st_size;
1082         blkcnt_t    st_blocks;
1083         blksize_t   st_blksize;
1084         uint        st_flags;
1085         uint        st_gen;
1086         int         st_lspare;
1087         long[2]     st_qspare;
1088     }
1089 
1090     enum S_ISUID    = 0x800; // octal 04000
1091     enum S_ISGID    = 0x400; // octal 02000
1092     enum S_ISVTX    = 0x200; // octal 01000
1093 }
1094 else version (FreeBSD)
1095 {
1096     import core.sys.freebsd.config;
1097 
1098     // https://github.com/freebsd/freebsd/blob/master/sys/sys/stat.h
1099     static if (__FreeBSD_version >= INO64_FIRST)
1100     {
1101         struct stat_t
1102         {
1103             dev_t     st_dev;
1104             ino_t     st_ino;
1105             nlink_t   st_nlink;
1106             mode_t    st_mode;
1107             short st_padding0;
1108             uid_t     st_uid;
1109             gid_t     st_gid;
1110             int st_padding1;
1111             dev_t     st_rdev;
1112 
1113             version (X86) int st_atim_ext;
1114             timespec  st_atim;
1115 
1116             version (X86) int st_mtim_ext;
1117             timespec  st_mtim;
1118 
1119             version (X86) int st_ctim_ext;
1120             timespec  st_ctim;
1121 
1122             version (X86) int st_btim_ext;
1123             timespec  st_birthtim;
1124 
1125             off_t     st_size;
1126             blkcnt_t st_blocks;
1127             blksize_t st_blksize;
1128             fflags_t  st_flags;
1129             ulong st_gen;
1130             ulong[10] st_spare;
1131 
1132             extern(D) @safe @property inout pure nothrow
1133             {
1134                 ref inout(time_t) st_atime() return { return st_atim.tv_sec; }
1135                 ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; }
1136                 ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; }
1137                 ref inout(time_t) st_birthtime() return { return st_birthtim.tv_sec; }
1138             }
1139         }
1140     }
1141     else
1142     {
1143         struct stat_t
1144         {
1145             uint        st_dev;
1146             uint        st_ino;
1147             mode_t      st_mode;
1148             ushort      st_nlink;
1149             uid_t       st_uid;
1150             gid_t       st_gid;
1151             uint        st_rdev;
1152             timespec    st_atim;
1153             timespec    st_mtim;
1154             timespec    st_ctim;
1155             off_t       st_size;
1156             blkcnt_t    st_blocks;
1157             blksize_t   st_blksize;
1158             fflags_t    st_flags;
1159             uint        st_gen;
1160             int         st_lspare;
1161             timespec    st_birthtim;
1162             ubyte[16 - timespec.sizeof] padding;
1163 
1164             extern(D) @safe @property inout pure nothrow
1165             {
1166                 ref inout(time_t) st_atime() return { return st_atim.tv_sec; }
1167                 ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; }
1168                 ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; }
1169                 ref inout(time_t) st_birthtime() return { return st_birthtim.tv_sec; }
1170             }
1171         }
1172     }
1173 
1174     enum S_ISUID    = 0x800; // octal 0004000
1175     enum S_ISGID    = 0x400; // octal 0002000
1176     enum S_ISVTX    = 0x200; // octal 0001000
1177 
1178     enum UTIME_NOW = -1;
1179     enum UTIME_OMIT = -2;
1180 }
1181 else version (NetBSD)
1182 {
1183     struct stat_t
1184     {
1185         dev_t     st_dev;               /* inode's device */
1186         mode_t    st_mode;              /* inode protection mode */
1187         ino_t     st_ino;               /* inode's number */
1188         nlink_t   st_nlink;             /* number of hard links */
1189         uid_t     st_uid;               /* user ID of the file's owner */
1190         gid_t     st_gid;               /* group ID of the file's group */
1191         dev_t     st_rdev;              /* device type */
1192         time_t    st_atime;             /* time of last access */
1193         long      st_atimensec;         /* nsec of last access */
1194         time_t    st_mtime;             /* time of last data modification */
1195         long      st_mtimensec;         /* nsec of last data modification */
1196         time_t    st_ctime;             /* time of last file status change */
1197         long      st_ctimensec;         /* nsec of last file status change */
1198         time_t    st_birthtime;         /* time of creation */
1199         long      st_birthtimensec;     /* nsec of time of creation */
1200         off_t     st_size;              /* file size, in bytes */
1201         blkcnt_t  st_blocks;            /* blocks allocated for file */
1202         blksize_t st_blksize;           /* optimal blocksize for I/O */
1203         uint32_t  st_flags;             /* user defined flags for file */
1204         uint32_t  st_gen;               /* file generation number */
1205         uint32_t[2]  st_spare;
1206     }
1207 
1208     enum S_ISUID    = 0x800; // octal 0004000
1209     enum S_ISGID    = 0x400; // octal 0002000
1210     enum S_ISVTX    = 0x200; // octal 0001000
1211 }
1212 else version (OpenBSD)
1213 {
1214     import core.sys.openbsd.sys.cdefs;
1215 
1216     struct stat_t
1217     {
1218         mode_t    st_mode;
1219         dev_t     st_dev;
1220         ino_t     st_ino;
1221         nlink_t   st_nlink;
1222         uid_t     st_uid;
1223         gid_t     st_gid;
1224         dev_t     st_rdev;
1225       static if (__POSIX_VISIBLE >= 200809 || __BSD_VISIBLE)
1226       {
1227         timespec  st_atim;
1228         timespec  st_mtim;
1229         timespec  st_ctim;
1230         extern(D) @safe @property inout pure nothrow
1231         {
1232             ref inout(time_t) st_atime() return { return st_atim.tv_sec; }
1233             ref inout(time_t) st_mtime() return { return st_mtim.tv_sec; }
1234             ref inout(time_t) st_ctime() return { return st_ctim.tv_sec; }
1235         }
1236       }
1237       else
1238       {
1239         time_t    st_atime;
1240         long      st_atimensec;
1241         time_t    st_mtime;
1242         long      st_mtimensec;
1243         time_t    st_ctime;
1244         long      st_ctimensec;
1245       }
1246         off_t     st_size;
1247         blkcnt_t  st_blocks;
1248         blksize_t st_blksize;
1249         uint32_t  st_flags;
1250         uint32_t  st_gen;
1251       static if (__POSIX_VISIBLE >= 200809 || __BSD_VISIBLE)
1252       {
1253         timespec __st_birthtim;
1254       }
1255       else
1256       {
1257         time_t  __st_birthtime;
1258         long    __st_birthtimensec;
1259       }
1260     }
1261 
1262     enum S_ISUID    = 0x800; // octal 0004000
1263     enum S_ISGID    = 0x400; // octal 0002000
1264     enum S_ISVTX    = 0x200; // octal 0001000
1265 }
1266 else version (DragonFlyBSD)
1267 {
1268     struct stat_t {
1269             ino_t     st_ino;               /* inode's number */
1270             nlink_t   st_nlink;             /* number of hard links */
1271             dev_t     st_dev;               /* inode's device */
1272             mode_t    st_mode;              /* inode protection mode */
1273             uint16_t  st_padding1;
1274             uid_t     st_uid;               /* user ID of the file's owner */
1275             gid_t     st_gid;               /* group ID of the file's group */
1276             dev_t     st_rdev;              /* device type */
1277             time_t      st_atime;
1278             c_long      __st_atimensec;
1279             time_t      st_mtime;
1280             c_long      __st_mtimensec;
1281             time_t      st_ctime;
1282             c_long      __st_ctimensec;
1283             off_t     st_size;              /* file size, in bytes */
1284             int64_t   st_blocks;            /* blocks allocated for file */
1285             uint32_t  st_blksize;           /* optimal blocksize for I/O */
1286             uint32_t  st_flags;             /* user defined flags for file */
1287             uint32_t  st_gen;               /* file generation number */
1288             int32_t   st_lspare;
1289             int64_t   st_qspare1;           /* was recursive change detect */
1290             int64_t   st_qspare2;
1291     }
1292 
1293     enum S_ISUID    = 0x800; // octal 0004000
1294     enum S_ISGID    = 0x400; // octal 0002000
1295     enum S_ISVTX    = 0x200; // octal 0001000
1296 }
1297 else version (Solaris)
1298 {
1299     private enum _ST_FSTYPSZ = 16;
1300 
1301     version (D_LP64)
1302     {
1303         struct stat_t
1304         {
1305             dev_t st_dev;
1306             ino_t st_ino;
1307             mode_t st_mode;
1308             nlink_t st_nlink;
1309             uid_t st_uid;
1310             gid_t st_gid;
1311             dev_t st_rdev;
1312             off_t st_size;
1313             union
1314             {
1315                 timestruc_t st_atim;
1316                 time_t      st_atime;
1317             }
1318             union
1319             {
1320                 timestruc_t st_mtim;
1321                 time_t      st_mtime;
1322             }
1323             union
1324             {
1325                 timestruc_t st_ctim;
1326                 time_t      st_ctime;
1327             }
1328             blksize_t st_blksize;
1329             blkcnt_t st_blocks;
1330             char[_ST_FSTYPSZ] st_fstype = 0;
1331         }
1332 
1333         static if (__USE_LARGEFILE64) alias stat_t stat64_t;
1334     }
1335     else
1336     {
1337         struct stat32_t
1338         {
1339             dev_t st_dev;
1340             c_long[3] st_pad1;
1341             ino_t st_ino;
1342             mode_t st_mode;
1343             nlink_t st_nlink;
1344             uid_t st_uid;
1345             gid_t st_gid;
1346             dev_t st_rdev;
1347             c_long[2] st_pad2;
1348             off_t st_size;
1349             c_long st_pad3;
1350             union
1351             {
1352                 timestruc_t st_atim;
1353                 time_t      st_atime;
1354             }
1355             union
1356             {
1357                 timestruc_t st_mtim;
1358                 time_t      st_mtime;
1359             }
1360             union
1361             {
1362                 timestruc_t st_ctim;
1363                 time_t      st_ctime;
1364             }
1365             blksize_t st_blksize;
1366             blkcnt_t st_blocks;
1367             char[_ST_FSTYPSZ] st_fstype = 0;
1368             c_long[8] st_pad4;
1369         }
1370 
1371         struct stat64_t
1372         {
1373             dev_t st_dev;
1374             c_long[3] st_pad1;
1375             ino64_t st_ino;
1376             mode_t st_mode;
1377             nlink_t st_nlink;
1378             uid_t st_uid;
1379             gid_t st_gid;
1380             dev_t st_rdev;
1381             c_long[2] st_pad2;
1382             off64_t st_size;
1383             union
1384             {
1385                 timestruc_t st_atim;
1386                 time_t      st_atime;
1387             }
1388             union
1389             {
1390                 timestruc_t st_mtim;
1391                 time_t      st_mtime;
1392             }
1393             union
1394             {
1395                 timestruc_t st_ctim;
1396                 time_t      st_ctime;
1397             }
1398             blksize_t st_blksize;
1399             blkcnt64_t st_blocks;
1400             char[_ST_FSTYPSZ] st_fstype = 0;
1401             c_long[8] st_pad4;
1402         }
1403 
1404         static if (__USE_FILE_OFFSET64)
1405             alias stat64_t stat_t;
1406         else
1407             alias stat32_t stat_t;
1408 
1409     }
1410 
1411     enum S_ISUID = 0x800;
1412     enum S_ISGID = 0x400;
1413     enum S_ISVTX = 0x200;
1414 }
1415 else
1416 {
1417     static assert(false, "Unsupported platform");
1418 }
1419 
1420 /*
1421 S_IRWXU
1422     S_IRUSR
1423     S_IWUSR
1424     S_IXUSR
1425 S_IRWXG
1426     S_IRGRP
1427     S_IWGRP
1428     S_IXGRP
1429 S_IRWXO
1430     S_IROTH
1431     S_IWOTH
1432     S_IXOTH
1433 
1434 S_ISBLK(m)
1435 S_ISCHR(m)
1436 S_ISDIR(m)
1437 S_ISFIFO(m)
1438 S_ISREG(m)
1439 S_ISLNK(m)
1440 S_ISSOCK(m)
1441  */
1442 
1443 version (CRuntime_Glibc)
1444 {
1445     enum S_IRUSR    = 0x100; // octal 0400
1446     enum S_IWUSR    = 0x080; // octal 0200
1447     enum S_IXUSR    = 0x040; // octal 0100
1448     enum S_IRWXU    = S_IRUSR | S_IWUSR | S_IXUSR;
1449 
1450     enum S_IRGRP    = S_IRUSR >> 3;
1451     enum S_IWGRP    = S_IWUSR >> 3;
1452     enum S_IXGRP    = S_IXUSR >> 3;
1453     enum S_IRWXG    = S_IRWXU >> 3;
1454 
1455     enum S_IROTH    = S_IRGRP >> 3;
1456     enum S_IWOTH    = S_IWGRP >> 3;
1457     enum S_IXOTH    = S_IXGRP >> 3;
1458     enum S_IRWXO    = S_IRWXG >> 3;
1459 
1460     private
1461     {
1462         extern (D) bool S_ISTYPE( mode_t mode, uint mask )
1463         {
1464             return ( mode & S_IFMT ) == mask;
1465         }
1466     }
1467 
1468     extern (D) bool S_ISBLK( mode_t mode )  { return S_ISTYPE( mode, S_IFBLK );  }
1469     extern (D) bool S_ISCHR( mode_t mode )  { return S_ISTYPE( mode, S_IFCHR );  }
1470     extern (D) bool S_ISDIR( mode_t mode )  { return S_ISTYPE( mode, S_IFDIR );  }
1471     extern (D) bool S_ISFIFO( mode_t mode ) { return S_ISTYPE( mode, S_IFIFO );  }
1472     extern (D) bool S_ISREG( mode_t mode )  { return S_ISTYPE( mode, S_IFREG );  }
1473     extern (D) bool S_ISLNK( mode_t mode )  { return S_ISTYPE( mode, S_IFLNK );  }
1474     extern (D) bool S_ISSOCK( mode_t mode ) { return S_ISTYPE( mode, S_IFSOCK ); }
1475 
1476     int utimensat(int dirfd, const char *pathname,
1477         ref const(timespec)[2] times, int flags);
1478     int futimens(int fd, ref const(timespec)[2] times);
1479 }
1480 else version (Darwin)
1481 {
1482     enum S_IRUSR    = 0x100;  // octal 0400
1483     enum S_IWUSR    = 0x080;  // octal 0200
1484     enum S_IXUSR    = 0x040;  // octal 0100
1485     enum S_IRWXU    = S_IRUSR | S_IWUSR | S_IXUSR;
1486 
1487     enum S_IRGRP    = S_IRUSR >> 3;
1488     enum S_IWGRP    = S_IWUSR >> 3;
1489     enum S_IXGRP    = S_IXUSR >> 3;
1490     enum S_IRWXG    = S_IRWXU >> 3;
1491 
1492     enum S_IROTH    = S_IRGRP >> 3;
1493     enum S_IWOTH    = S_IWGRP >> 3;
1494     enum S_IXOTH    = S_IXGRP >> 3;
1495     enum S_IRWXO    = S_IRWXG >> 3;
1496 
1497     private
1498     {
1499         extern (D) bool S_ISTYPE( mode_t mode, uint mask )
1500         {
1501             return ( mode & S_IFMT ) == mask;
1502         }
1503     }
1504 
1505     extern (D) bool S_ISBLK( mode_t mode )  { return S_ISTYPE( mode, S_IFBLK );  }
1506     extern (D) bool S_ISCHR( mode_t mode )  { return S_ISTYPE( mode, S_IFCHR );  }
1507     extern (D) bool S_ISDIR( mode_t mode )  { return S_ISTYPE( mode, S_IFDIR );  }
1508     extern (D) bool S_ISFIFO( mode_t mode ) { return S_ISTYPE( mode, S_IFIFO );  }
1509     extern (D) bool S_ISREG( mode_t mode )  { return S_ISTYPE( mode, S_IFREG );  }
1510     extern (D) bool S_ISLNK( mode_t mode )  { return S_ISTYPE( mode, S_IFLNK );  }
1511     extern (D) bool S_ISSOCK( mode_t mode ) { return S_ISTYPE( mode, S_IFSOCK ); }
1512 }
1513 else version (FreeBSD)
1514 {
1515     enum S_IRUSR    = 0x100; // octal 0000400
1516     enum S_IWUSR    = 0x080; // octal 0000200
1517     enum S_IXUSR    = 0x040; // octal 0000100
1518     enum S_IRWXU    = 0x1C0; // octal 0000700
1519 
1520     enum S_IRGRP    = 0x020;  // octal 0000040
1521     enum S_IWGRP    = 0x010;  // octal 0000020
1522     enum S_IXGRP    = 0x008;  // octal 0000010
1523     enum S_IRWXG    = 0x038;  // octal 0000070
1524 
1525     enum S_IROTH    = 0x4; // 0000004
1526     enum S_IWOTH    = 0x2; // 0000002
1527     enum S_IXOTH    = 0x1; // 0000001
1528     enum S_IRWXO    = 0x7; // 0000007
1529 
1530     private
1531     {
1532         extern (D) bool S_ISTYPE( mode_t mode, uint mask )
1533         {
1534             return ( mode & S_IFMT ) == mask;
1535         }
1536     }
1537 
1538     extern (D) bool S_ISBLK( mode_t mode )  { return S_ISTYPE( mode, S_IFBLK );  }
1539     extern (D) bool S_ISCHR( mode_t mode )  { return S_ISTYPE( mode, S_IFCHR );  }
1540     extern (D) bool S_ISDIR( mode_t mode )  { return S_ISTYPE( mode, S_IFDIR );  }
1541     extern (D) bool S_ISFIFO( mode_t mode ) { return S_ISTYPE( mode, S_IFIFO );  }
1542     extern (D) bool S_ISREG( mode_t mode )  { return S_ISTYPE( mode, S_IFREG );  }
1543     extern (D) bool S_ISLNK( mode_t mode )  { return S_ISTYPE( mode, S_IFLNK );  }
1544     extern (D) bool S_ISSOCK( mode_t mode ) { return S_ISTYPE( mode, S_IFSOCK ); }
1545 
1546     // Since FreeBSD 11:
1547     version (none)
1548     {
1549         int utimensat(int dirfd, const char *pathname,
1550             ref const(timespec)[2] times, int flags);
1551         int futimens(int fd, ref const(timespec)[2] times);
1552     }
1553 }
1554 else version (NetBSD)
1555 {
1556     enum S_IRUSR    = 0x100; // octal 0000400
1557     enum S_IWUSR    = 0x080; // octal 0000200
1558     enum S_IXUSR    = 0x040; // octal 0000100
1559     enum S_IRWXU    = 0x1C0; // octal 0000700
1560 
1561     enum S_IRGRP    = 0x020;  // octal 0000040
1562     enum S_IWGRP    = 0x010;  // octal 0000020
1563     enum S_IXGRP    = 0x008;  // octal 0000010
1564     enum S_IRWXG    = 0x038;  // octal 0000070
1565 
1566     enum S_IROTH    = 0x4; // 0000004
1567     enum S_IWOTH    = 0x2; // 0000002
1568     enum S_IXOTH    = 0x1; // 0000001
1569     enum S_IRWXO    = 0x7; // 0000007
1570 
1571     private
1572     {
1573         extern (D) bool S_ISTYPE( mode_t mode, uint mask )
1574         {
1575             return ( mode & S_IFMT ) == mask;
1576         }
1577     }
1578 
1579     extern (D) bool S_ISBLK( mode_t mode )  { return S_ISTYPE( mode, S_IFBLK );  }
1580     extern (D) bool S_ISCHR( mode_t mode )  { return S_ISTYPE( mode, S_IFCHR );  }
1581     extern (D) bool S_ISDIR( mode_t mode )  { return S_ISTYPE( mode, S_IFDIR );  }
1582     extern (D) bool S_ISFIFO( mode_t mode ) { return S_ISTYPE( mode, S_IFIFO );  }
1583     extern (D) bool S_ISREG( mode_t mode )  { return S_ISTYPE( mode, S_IFREG );  }
1584     extern (D) bool S_ISLNK( mode_t mode )  { return S_ISTYPE( mode, S_IFLNK );  }
1585     extern (D) bool S_ISSOCK( mode_t mode ) { return S_ISTYPE( mode, S_IFSOCK ); }
1586 }
1587 else version (OpenBSD)
1588 {
1589     enum S_IRUSR    = 0x100; // octal 0000400
1590     enum S_IWUSR    = 0x080; // octal 0000200
1591     enum S_IXUSR    = 0x040; // octal 0000100
1592     enum S_IRWXU    = 0x1C0; // octal 0000700
1593 
1594     enum S_IRGRP    = 0x020;  // octal 0000040
1595     enum S_IWGRP    = 0x010;  // octal 0000020
1596     enum S_IXGRP    = 0x008;  // octal 0000010
1597     enum S_IRWXG    = 0x038;  // octal 0000070
1598 
1599     enum S_IROTH    = 0x4; // 0000004
1600     enum S_IWOTH    = 0x2; // 0000002
1601     enum S_IXOTH    = 0x1; // 0000001
1602     enum S_IRWXO    = 0x7; // 0000007
1603 
1604     extern (D) bool S_ISBLK(mode_t mode)  { return (mode & S_IFMT) == S_IFBLK;  }
1605     extern (D) bool S_ISCHR(mode_t mode)  { return (mode & S_IFMT) == S_IFCHR;  }
1606     extern (D) bool S_ISDIR(mode_t mode)  { return (mode & S_IFMT) == S_IFDIR;  }
1607     extern (D) bool S_ISFIFO(mode_t mode) { return (mode & S_IFMT) == S_IFIFO;  }
1608     extern (D) bool S_ISREG(mode_t mode)  { return (mode & S_IFMT) == S_IFREG;  }
1609     extern (D) bool S_ISLNK(mode_t mode)  { return (mode & S_IFMT) == S_IFLNK;  }
1610     extern (D) bool S_ISSOCK(mode_t mode) { return (mode & S_IFMT) == S_IFSOCK; }
1611 }
1612 else version (DragonFlyBSD)
1613 {
1614     enum S_IRUSR    = 0x100; // octal 0000400
1615     enum S_IWUSR    = 0x080; // octal 0000200
1616     enum S_IXUSR    = 0x040; // octal 0000100
1617     enum S_IRWXU    = 0x1C0; // octal 0000700
1618 
1619     enum S_IRGRP    = 0x020;  // octal 0000040
1620     enum S_IWGRP    = 0x010;  // octal 0000020
1621     enum S_IXGRP    = 0x008;  // octal 0000010
1622     enum S_IRWXG    = 0x038;  // octal 0000070
1623 
1624     enum S_IROTH    = 0x4; // 0000004
1625     enum S_IWOTH    = 0x2; // 0000002
1626     enum S_IXOTH    = 0x1; // 0000001
1627     enum S_IRWXO    = 0x7; // 0000007
1628 
1629     private
1630     {
1631         extern (D) bool S_ISTYPE( mode_t mode, uint mask )
1632         {
1633             return ( mode & S_IFMT ) == mask;
1634         }
1635     }
1636 
1637     extern (D) bool S_ISBLK( mode_t mode )  { return S_ISTYPE( mode, S_IFBLK );  }
1638     extern (D) bool S_ISCHR( mode_t mode )  { return S_ISTYPE( mode, S_IFCHR );  }
1639     extern (D) bool S_ISDIR( mode_t mode )  { return S_ISTYPE( mode, S_IFDIR );  }
1640     extern (D) bool S_ISFIFO( mode_t mode ) { return S_ISTYPE( mode, S_IFIFO );  }
1641     extern (D) bool S_ISREG( mode_t mode )  { return S_ISTYPE( mode, S_IFREG );  }
1642     extern (D) bool S_ISLNK( mode_t mode )  { return S_ISTYPE( mode, S_IFLNK );  }
1643     extern (D) bool S_ISSOCK( mode_t mode ) { return S_ISTYPE( mode, S_IFSOCK ); }
1644 }
1645 else version (Solaris)
1646 {
1647     enum S_IRUSR = 0x100;
1648     enum S_IWUSR = 0x080;
1649     enum S_IXUSR = 0x040;
1650     enum S_IRWXU = 0x1C0;
1651 
1652     enum S_IRGRP = 0x020;
1653     enum S_IWGRP = 0x010;
1654     enum S_IXGRP = 0x008;
1655     enum S_IRWXG = 0x038;
1656 
1657     enum S_IROTH = 0x4; // 0000004
1658     enum S_IWOTH = 0x2; // 0000002
1659     enum S_IXOTH = 0x1; // 0000001
1660     enum S_IRWXO = 0x7; // 0000007
1661 
1662     private
1663     {
1664         extern (D) bool S_ISTYPE(mode_t mode, uint mask)
1665         {
1666             return (mode & S_IFMT) == mask;
1667         }
1668     }
1669 
1670     extern (D) bool S_ISBLK(mode_t mode) { return S_ISTYPE(mode, S_IFBLK); }
1671     extern (D) bool S_ISCHR(mode_t mode) { return S_ISTYPE(mode, S_IFCHR); }
1672     extern (D) bool S_ISDIR(mode_t mode) { return S_ISTYPE(mode, S_IFDIR); }
1673     extern (D) bool S_ISFIFO(mode_t mode) { return S_ISTYPE(mode, S_IFIFO); }
1674     extern (D) bool S_ISREG(mode_t mode) { return S_ISTYPE(mode, S_IFREG); }
1675     extern (D) bool S_ISLNK(mode_t mode) { return S_ISTYPE(mode, S_IFLNK); }
1676     extern (D) bool S_ISSOCK(mode_t mode) { return S_ISTYPE(mode, S_IFSOCK); }
1677     extern (D) bool S_ISDOOR(mode_t mode) { return S_ISTYPE(mode, S_IFDOOR); }
1678     extern (D) bool S_ISPORT(mode_t mode) { return S_ISTYPE(mode, S_IFPORT); }
1679 }
1680 else version (CRuntime_Bionic)
1681 {
1682     enum S_IRUSR    = 0x100; // octal 0000400
1683     enum S_IWUSR    = 0x080; // octal 0000200
1684     enum S_IXUSR    = 0x040; // octal 0000100
1685     enum S_IRWXU    = 0x1C0; // octal 0000700
1686 
1687     enum S_IRGRP    = 0x020;  // octal 0000040
1688     enum S_IWGRP    = 0x010;  // octal 0000020
1689     enum S_IXGRP    = 0x008;  // octal 0000010
1690     enum S_IRWXG    = 0x038;  // octal 0000070
1691 
1692     enum S_IROTH    = 0x4; // 0000004
1693     enum S_IWOTH    = 0x2; // 0000002
1694     enum S_IXOTH    = 0x1; // 0000001
1695     enum S_IRWXO    = 0x7; // 0000007
1696 
1697     private
1698     {
1699         extern (D) bool S_ISTYPE( uint mode, uint mask )
1700         {
1701             return ( mode & S_IFMT ) == mask;
1702         }
1703     }
1704 
1705     extern (D) bool S_ISBLK( uint mode )  { return S_ISTYPE( mode, S_IFBLK );  }
1706     extern (D) bool S_ISCHR( uint mode )  { return S_ISTYPE( mode, S_IFCHR );  }
1707     extern (D) bool S_ISDIR( uint mode )  { return S_ISTYPE( mode, S_IFDIR );  }
1708     extern (D) bool S_ISFIFO( uint mode ) { return S_ISTYPE( mode, S_IFIFO );  }
1709     extern (D) bool S_ISREG( uint mode )  { return S_ISTYPE( mode, S_IFREG );  }
1710     extern (D) bool S_ISLNK( uint mode )  { return S_ISTYPE( mode, S_IFLNK );  }
1711     extern (D) bool S_ISSOCK( uint mode ) { return S_ISTYPE( mode, S_IFSOCK ); }
1712 
1713     // Added since Lollipop
1714     int utimensat(int dirfd, const char *pathname,
1715         ref const(timespec)[2] times, int flags);
1716 }
1717 else version (CRuntime_Musl)
1718 {
1719     enum {
1720         S_IRUSR    = 0x100, // octal 0400
1721         S_IWUSR    = 0x080, // octal 0200
1722         S_IXUSR    = 0x040, // octal 0100
1723         S_IRWXU    = S_IRUSR | S_IWUSR | S_IXUSR,
1724 
1725         S_IRGRP    = S_IRUSR >> 3,
1726         S_IWGRP    = S_IWUSR >> 3,
1727         S_IXGRP    = S_IXUSR >> 3,
1728         S_IRWXG    = S_IRWXU >> 3,
1729 
1730         S_IROTH    = S_IRGRP >> 3,
1731         S_IWOTH    = S_IWGRP >> 3,
1732         S_IXOTH    = S_IXGRP >> 3,
1733         S_IRWXO    = S_IRWXG >> 3,
1734     }
1735 
1736     private
1737     {
1738         extern (D) bool S_ISTYPE( mode_t mode, uint mask )
1739         {
1740             return ( mode & S_IFMT ) == mask;
1741         }
1742     }
1743 
1744     extern (D) bool S_ISBLK( mode_t mode )  { return S_ISTYPE( mode, S_IFBLK );  }
1745     extern (D) bool S_ISCHR( mode_t mode )  { return S_ISTYPE( mode, S_IFCHR );  }
1746     extern (D) bool S_ISDIR( mode_t mode )  { return S_ISTYPE( mode, S_IFDIR );  }
1747     extern (D) bool S_ISFIFO( mode_t mode ) { return S_ISTYPE( mode, S_IFIFO );  }
1748     extern (D) bool S_ISREG( mode_t mode )  { return S_ISTYPE( mode, S_IFREG );  }
1749     extern (D) bool S_ISLNK( mode_t mode )  { return S_ISTYPE( mode, S_IFLNK );  }
1750     extern (D) bool S_ISSOCK( mode_t mode ) { return S_ISTYPE( mode, S_IFSOCK ); }
1751 
1752     int utimensat(int dirfd, const char *pathname,
1753         ref const(timespec)[2] times, int flags);
1754 }
1755 else version (CRuntime_UClibc)
1756 {
1757     enum S_IRUSR    = 0x100; // octal 0400
1758     enum S_IWUSR    = 0x080; // octal 0200
1759     enum S_IXUSR    = 0x040; // octal 0100
1760     enum S_IRWXU    = S_IRUSR | S_IWUSR | S_IXUSR;
1761 
1762     enum S_IRGRP    = S_IRUSR >> 3;
1763     enum S_IWGRP    = S_IWUSR >> 3;
1764     enum S_IXGRP    = S_IXUSR >> 3;
1765     enum S_IRWXG    = S_IRWXU >> 3;
1766 
1767     enum S_IROTH    = S_IRGRP >> 3;
1768     enum S_IWOTH    = S_IWGRP >> 3;
1769     enum S_IXOTH    = S_IXGRP >> 3;
1770     enum S_IRWXO    = S_IRWXG >> 3;
1771 
1772     private
1773     {
1774         extern (D) bool S_ISTYPE( mode_t mode, uint mask )
1775         {
1776             return ( mode & S_IFMT ) == mask;
1777         }
1778     }
1779 
1780     extern (D) bool S_ISBLK( mode_t mode )  { return S_ISTYPE( mode, S_IFBLK );  }
1781     extern (D) bool S_ISCHR( mode_t mode )  { return S_ISTYPE( mode, S_IFCHR );  }
1782     extern (D) bool S_ISDIR( mode_t mode )  { return S_ISTYPE( mode, S_IFDIR );  }
1783     extern (D) bool S_ISFIFO( mode_t mode ) { return S_ISTYPE( mode, S_IFIFO );  }
1784     extern (D) bool S_ISREG( mode_t mode )  { return S_ISTYPE( mode, S_IFREG );  }
1785     extern (D) bool S_ISLNK( mode_t mode )  { return S_ISTYPE( mode, S_IFLNK );  }
1786     extern (D) bool S_ISSOCK( mode_t mode ) { return S_ISTYPE( mode, S_IFSOCK ); }
1787 
1788     int utimensat(int dirfd, const char *pathname,
1789     ref const(timespec)[2] times, int flags);
1790     int futimens(int fd, ref const(timespec)[2] times);
1791 }
1792 else
1793 {
1794     static assert(false, "Unsupported platform");
1795 }
1796 
1797 /*
1798 int    chmod(const scope char*, mode_t);
1799 int    fchmod(int, mode_t);
1800 int    fstat(int, stat*);
1801 int    lstat(const scope char*, stat*);
1802 int    mkdir(const scope char*, mode_t);
1803 int    mkfifo(const scope char*, mode_t);
1804 int    stat(const scope char*, stat*);
1805 mode_t umask(mode_t);
1806 */
1807 
1808 int    chmod(const scope char*, mode_t);
1809 int    fchmod(int, mode_t);
1810 //int    fstat(int, stat_t*);
1811 //int    lstat(const scope char*, stat_t*);
1812 int    mkdir(const scope char*, mode_t);
1813 int    mkfifo(const scope char*, mode_t);
1814 //int    stat(const scope char*, stat_t*);
1815 mode_t umask(mode_t);
1816 
1817 version (CRuntime_Glibc)
1818 {
1819   static if ( __USE_LARGEFILE64 )
1820   {
1821     int   fstat64(int, stat_t*) @trusted;
1822     alias fstat64 fstat;
1823 
1824     int   lstat64(const scope char*, stat_t*);
1825     alias lstat64 lstat;
1826 
1827     int   stat64(const scope char*, stat_t*);
1828     alias stat64 stat;
1829   }
1830   else
1831   {
1832     int   fstat(int, stat_t*) @trusted;
1833     int   lstat(const scope char*, stat_t*);
1834     int   stat(const scope char*, stat_t*);
1835   }
1836 }
1837 else version (Solaris)
1838 {
1839     version (D_LP64)
1840     {
1841         int fstat(int, stat_t*) @trusted;
1842         int lstat(const scope char*, stat_t*);
1843         int stat(const scope char*, stat_t*);
1844 
1845         static if (__USE_LARGEFILE64)
1846         {
1847             alias fstat fstat64;
1848             alias lstat lstat64;
1849             alias stat stat64;
1850         }
1851     }
1852     else
1853     {
1854         static if (__USE_LARGEFILE64)
1855         {
1856             int   fstat64(int, stat_t*) @trusted;
1857             alias fstat64 fstat;
1858 
1859             int   lstat64(const scope char*, stat_t*);
1860             alias lstat64 lstat;
1861 
1862             int   stat64(const scope char*, stat_t*);
1863             alias stat64 stat;
1864         }
1865         else
1866         {
1867             int fstat(int, stat_t*) @trusted;
1868             int lstat(const scope char*, stat_t*);
1869             int stat(const scope char*, stat_t*);
1870         }
1871     }
1872 }
1873 else version (Darwin)
1874 {
1875     // OS X maintains backwards compatibility with older binaries using 32-bit
1876     // inode functions by appending $INODE64 to newer 64-bit inode functions.
1877     version (OSX)
1878     {
1879         version (AArch64)
1880         {
1881             int fstat(int, stat_t*);
1882             int lstat(const scope char*, stat_t*);
1883             int stat(const scope char*, stat_t*);
1884         }
1885         else
1886         {
1887             pragma(mangle, "fstat$INODE64") int fstat(int, stat_t*);
1888             pragma(mangle, "lstat$INODE64") int lstat(const scope char*, stat_t*);
1889             pragma(mangle, "stat$INODE64")  int stat(const scope char*, stat_t*);
1890         }
1891     }
1892     else
1893     {
1894         int fstat(int, stat_t*);
1895         int lstat(const scope char*, stat_t*);
1896         int stat(const scope char*, stat_t*);
1897     }
1898 }
1899 else version (FreeBSD)
1900 {
1901     version (GNU)
1902     {
1903         int   fstat(int, stat_t*);
1904         int   lstat(const scope char*, stat_t*);
1905         int   stat(const scope char*, stat_t*);
1906     }
1907     else
1908     {
1909         static if (__FreeBSD_version >= INO64_FIRST)
1910         {
1911             pragma(mangle, "fstat@FBSD_1.5") int   fstat(int, stat_t*);
1912             pragma(mangle, "lstat@FBSD_1.5") int   lstat(const scope char*, stat_t*);
1913             pragma(mangle, "stat@FBSD_1.5")  int   stat(const scope char*, stat_t*);
1914         }
1915         else
1916         {
1917             pragma(mangle, "fstat@FBSD_1.0") int   fstat(int, stat_t*);
1918             pragma(mangle, "lstat@FBSD_1.0") int   lstat(const scope char*, stat_t*);
1919             pragma(mangle, "stat@FBSD_1.0")  int   stat(const scope char*, stat_t*);
1920         }
1921     }
1922 }
1923 else version (NetBSD)
1924 {
1925     int   __fstat50(int, stat_t*);
1926     int   __lstat50(const scope char*, stat_t*);
1927     int   __stat50(const scope char*, stat_t*);
1928     alias __fstat50 fstat;
1929     alias __lstat50 lstat;
1930     alias __stat50 stat;
1931 }
1932 else version (OpenBSD)
1933 {
1934     int   fstat(int, stat_t*);
1935     int   lstat(const scope char*, stat_t*);
1936     int   stat(const scope char*, stat_t*);
1937 }
1938 else version (DragonFlyBSD)
1939 {
1940     int   fstat(int, stat_t*);
1941     int   lstat(const scope char*, stat_t*);
1942     int   stat(const scope char*, stat_t*);
1943 }
1944 else version (CRuntime_Bionic)
1945 {
1946     int   fstat(int, stat_t*) @trusted;
1947     int   lstat(const scope char*, stat_t*);
1948     int   stat(const scope char*, stat_t*);
1949 }
1950 else version (CRuntime_Musl)
1951 {
1952     pragma(mangle, muslRedirTime64Mangle!("stat", "__stat_time64"))
1953     int stat(const scope char*, stat_t*);
1954     pragma(mangle, muslRedirTime64Mangle!("fstat", "__fstat_time64"))
1955     int fstat(int, stat_t*);
1956     pragma(mangle, muslRedirTime64Mangle!("lstat", "__lstat_time64"))
1957     int lstat(const scope char*, stat_t*);
1958 
1959     alias fstat fstat64;
1960     alias lstat lstat64;
1961     alias stat stat64;
1962 }
1963 else version (CRuntime_UClibc)
1964 {
1965   static if ( __USE_LARGEFILE64 )
1966   {
1967     int   fstat64(int, stat_t*) @trusted;
1968     alias fstat64 fstat;
1969 
1970     int   lstat64(const scope char*, stat_t*);
1971     alias lstat64 lstat;
1972 
1973     int   stat64(const scope char*, stat_t*);
1974     alias stat64 stat;
1975   }
1976   else
1977   {
1978     int   fstat(int, stat_t*) @trusted;
1979     int   lstat(const scope char*, stat_t*);
1980     int   stat(const scope char*, stat_t*);
1981   }
1982 }
1983 
1984 //
1985 // Typed Memory Objects (TYM)
1986 //
1987 /*
1988 S_TYPEISTMO(buf)
1989 */
1990 
1991 //
1992 // XOpen (XSI)
1993 //
1994 /*
1995 S_IFMT
1996 S_IFBLK
1997 S_IFCHR
1998 S_IFIFO
1999 S_IFREG
2000 S_IFDIR
2001 S_IFLNK
2002 S_IFSOCK
2003 */
2004 
2005 version (linux)
2006 {
2007     enum S_IFMT     = 0xF000; // octal 0170000
2008     enum S_IFBLK    = 0x6000; // octal 0060000
2009     enum S_IFCHR    = 0x2000; // octal 0020000
2010     enum S_IFIFO    = 0x1000; // octal 0010000
2011     enum S_IFREG    = 0x8000; // octal 0100000
2012     enum S_IFDIR    = 0x4000; // octal 0040000
2013     enum S_IFLNK    = 0xA000; // octal 0120000
2014     enum S_IFSOCK   = 0xC000; // octal 0140000
2015 }
2016 else version (Darwin)
2017 {
2018     enum S_IFMT     = 0xF000; // octal 0170000
2019     enum S_IFBLK    = 0x6000; // octal 0060000
2020     enum S_IFCHR    = 0x2000; // octal 0020000
2021     enum S_IFIFO    = 0x1000; // octal 0010000
2022     enum S_IFREG    = 0x8000; // octal 0100000
2023     enum S_IFDIR    = 0x4000; // octal 0040000
2024     enum S_IFLNK    = 0xA000; // octal 0120000
2025     enum S_IFSOCK   = 0xC000; // octal 0140000
2026 }
2027 else version (FreeBSD)
2028 {
2029     enum S_IFMT     = 0xF000; // octal 0170000
2030     enum S_IFBLK    = 0x6000; // octal 0060000
2031     enum S_IFCHR    = 0x2000; // octal 0020000
2032     enum S_IFIFO    = 0x1000; // octal 0010000
2033     enum S_IFREG    = 0x8000; // octal 0100000
2034     enum S_IFDIR    = 0x4000; // octal 0040000
2035     enum S_IFLNK    = 0xA000; // octal 0120000
2036     enum S_IFSOCK   = 0xC000; // octal 0140000
2037 }
2038 else version (NetBSD)
2039 {
2040     enum S_IFMT     = 0xF000; // octal 0170000
2041     enum S_IFBLK    = 0x6000; // octal 0060000
2042     enum S_IFCHR    = 0x2000; // octal 0020000
2043     enum S_IFIFO    = 0x1000; // octal 0010000
2044     enum S_IFREG    = 0x8000; // octal 0100000
2045     enum S_IFDIR    = 0x4000; // octal 0040000
2046     enum S_IFLNK    = 0xA000; // octal 0120000
2047     enum S_IFSOCK   = 0xC000; // octal 0140000
2048 }
2049 else version (OpenBSD)
2050 {
2051     enum S_IFMT     = 0xF000; // octal 0170000
2052     enum S_IFBLK    = 0x6000; // octal 0060000
2053     enum S_IFCHR    = 0x2000; // octal 0020000
2054     enum S_IFIFO    = 0x1000; // octal 0010000
2055     enum S_IFREG    = 0x8000; // octal 0100000
2056     enum S_IFDIR    = 0x4000; // octal 0040000
2057     enum S_IFLNK    = 0xA000; // octal 0120000
2058     enum S_IFSOCK   = 0xC000; // octal 0140000
2059 }
2060 else version (DragonFlyBSD)
2061 {
2062     enum S_IFMT     = 0xF000; // octal 0170000
2063     enum S_IFBLK    = 0x6000; // octal 0060000
2064     enum S_IFCHR    = 0x2000; // octal 0020000
2065     enum S_IFIFO    = 0x1000; // octal 0010000
2066     enum S_IFREG    = 0x8000; // octal 0100000
2067     enum S_IFDIR    = 0x4000; // octal 0040000
2068     enum S_IFLNK    = 0xA000; // octal 0120000
2069     enum S_IFSOCK   = 0xC000; // octal 0140000
2070 }
2071 else version (Solaris)
2072 {
2073     enum S_IFMT = 0xF000;
2074     enum S_IFBLK = 0x6000;
2075     enum S_IFCHR = 0x2000;
2076     enum S_IFIFO = 0x1000;
2077     enum S_IFREG = 0x8000;
2078     enum S_IFDIR = 0x4000;
2079     enum S_IFLNK = 0xA000;
2080     enum S_IFSOCK = 0xC000;
2081     enum S_IFDOOR = 0xD000;
2082     enum S_IFPORT = 0xE000;
2083 }
2084 else
2085 {
2086     static assert(false, "Unsupported platform");
2087 }
2088 
2089 /*
2090 int mknod(const scope char*, mode_t, dev_t);
2091 */
2092 
2093 version (CRuntime_Glibc)
2094 {
2095     int mknod(const scope char*, mode_t, dev_t);
2096 }
2097 else version (Darwin)
2098 {
2099     int mknod(const scope char*, mode_t, dev_t);
2100 }
2101 else version (FreeBSD)
2102 {
2103     version (GNU)
2104     {
2105         int mknod(const scope char*, mode_t, dev_t);
2106     }
2107     else
2108     {
2109         static if (__FreeBSD_version >= INO64_FIRST)
2110             pragma(mangle, "mknod@FBSD_1.5") int mknod(const scope char*, mode_t, dev_t);
2111         else
2112             pragma(mangle, "mknod@FBSD_1.0") int mknod(const scope char*, mode_t, dev_t);
2113     }
2114 }
2115 else version (NetBSD)
2116 {
2117     int mknod(const scope char*, mode_t, dev_t);
2118 }
2119 else version (OpenBSD)
2120 {
2121     int mknod(const scope char*, mode_t, dev_t);
2122 }
2123 else version (DragonFlyBSD)
2124 {
2125     int mknod(const scope char*, mode_t, dev_t);
2126 }
2127 else version (Solaris)
2128 {
2129     int mknod(const scope char*, mode_t, dev_t);
2130 }
2131 else version (CRuntime_Bionic)
2132 {
2133     int mknod(const scope char*, mode_t, dev_t);
2134 }
2135 else version (CRuntime_Musl)
2136 {
2137     int mknod(const scope char*, mode_t, dev_t);
2138 }
2139 else version (CRuntime_UClibc)
2140 {
2141     int mknod(const scope char*, mode_t, dev_t);
2142 }
2143 else
2144 {
2145     static assert(false, "Unsupported platform");
2146 }