The OpenD Programming Language

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