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.fcntl;
16 
17 import core.sys.posix.config;
18 import core.stdc.stdint;
19 public import core.sys.posix.sys.types; // for off_t, mode_t
20 public import core.sys.posix.sys.stat;  // for S_IFMT, etc.
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 (ARM)     version = ARM_Any;
32 version (AArch64) version = ARM_Any;
33 version (HPPA)    version = HPPA_Any;
34 version (MIPS32)  version = MIPS_Any;
35 version (MIPS64)  version = MIPS_Any;
36 version (PPC)     version = PPC_Any;
37 version (PPC64)   version = PPC_Any;
38 version (RISCV32) version = RISCV_Any;
39 version (RISCV64) version = RISCV_Any;
40 version (S390)    version = IBMZ_Any;
41 version (SPARC)   version = SPARC_Any;
42 version (SPARC64) version = SPARC_Any;
43 version (SystemZ) version = IBMZ_Any;
44 version (X86)     version = X86_Any;
45 version (X86_64)  version = X86_Any;
46 
47 version (Posix):
48 extern (C):
49 
50 nothrow:
51 @nogc:
52 
53 //
54 // Required
55 //
56 /*
57 F_DUPFD
58 F_GETFD
59 F_SETFD
60 F_GETFL
61 F_SETFL
62 F_GETLK
63 F_SETLK
64 F_SETLKW
65 F_GETOWN
66 F_SETOWN
67 
68 FD_CLOEXEC
69 
70 F_RDLCK
71 F_UNLCK
72 F_WRLCK
73 
74 O_CREAT
75 O_EXCL
76 O_NOCTTY
77 O_TRUNC
78 
79 O_APPEND
80 O_DSYNC
81 O_NONBLOCK
82 O_RSYNC
83 O_SYNC
84 
85 O_ACCMODE
86 O_RDONLY
87 O_RDWR
88 O_WRONLY
89 
90 struct flock
91 {
92     short   l_type;
93     short   l_whence;
94     off_t   l_start;
95     off_t   l_len;
96     pid_t   l_pid;
97 }
98 */
99 version (linux)
100 {
101     enum F_DUPFD        = 0;
102     enum F_GETFD        = 1;
103     enum F_SETFD        = 2;
104     enum F_GETFL        = 3;
105     enum F_SETFL        = 4;
106   version (X86_64)
107   {
108     static assert(off_t.sizeof == 8);
109     enum F_GETLK        = 5;
110     enum F_SETLK        = 6;
111     enum F_SETLKW       = 7;
112   }
113   else version (AArch64)
114   {
115     enum F_GETLK        = 5;
116     enum F_SETLK        = 6;
117     enum F_SETLKW       = 7;
118   }
119   else version (PPC64)
120   {
121     enum F_GETLK        = 5;
122     enum F_SETLK        = 6;
123     enum F_SETLKW       = 7;
124   }
125   else version (RISCV64)
126   {
127     enum F_GETLK        = 5;
128     enum F_SETLK        = 6;
129     enum F_SETLKW       = 7;
130   }
131   else version (SystemZ)
132   {
133     static assert(off_t.sizeof == 8);
134     enum F_GETLK        = 5;
135     enum F_SETLK        = 6;
136     enum F_SETLKW       = 7;
137   }
138   else version (MIPS_N64)
139   {
140     enum F_GETLK        = 14;
141     enum F_SETLK        = 6;
142     enum F_SETLKW       = 7;
143   }
144   else version (MIPS_Any)
145   {
146     version (CRuntime_Musl)
147     {
148         enum F_GETLK      = 14;
149         enum F_SETLK      = 6;
150         enum F_SETLKW     = 7;
151     }
152     else
153     {
154         static if ( __USE_FILE_OFFSET64 )
155         {
156             enum F_GETLK      = 33;
157             enum F_SETLK      = 34;
158             enum F_SETLKW     = 35;
159         }
160         else
161         {
162             enum F_GETLK      = 14;
163             enum F_SETLK      = 6;
164             enum F_SETLKW     = 7;
165         }
166     }
167   }
168   else version (LoongArch64)
169   {
170     static assert(off_t.sizeof == 8);
171     enum F_GETLK        = 5;
172     enum F_SETLK        = 6;
173     enum F_SETLKW       = 7;
174   } else
175   static if ( __USE_FILE_OFFSET64 )
176   {
177     enum F_GETLK        = 12;
178     enum F_SETLK        = 13;
179     enum F_SETLKW       = 14;
180   }
181   else
182   {
183     enum F_GETLK        = 5;
184     enum F_SETLK        = 6;
185     enum F_SETLKW       = 7;
186   }
187     enum F_GETOWN       = 9;
188     enum F_SETOWN       = 8;
189 
190     enum FD_CLOEXEC     = 1;
191 
192     enum F_RDLCK        = 0;
193     enum F_UNLCK        = 2;
194     enum F_WRLCK        = 1;
195 
196     version (X86_Any)
197     {
198         enum O_CREAT        = 0x40;     // octal     0100
199         enum O_EXCL         = 0x80;     // octal     0200
200         enum O_NOCTTY       = 0x100;    // octal     0400
201         enum O_TRUNC        = 0x200;    // octal    01000
202 
203         enum O_APPEND       = 0x400;    // octal    02000
204         enum O_NONBLOCK     = 0x800;    // octal    04000
205         enum O_CLOEXEC      = 0x80000;  // octal 02000000
206         enum O_SYNC         = 0x101000; // octal 04010000
207         enum O_DSYNC        = 0x1000;   // octal   010000
208         enum O_RSYNC        = O_SYNC;
209 
210         enum O_DIRECTORY    = 0x010000; // octal   0200000
211         enum O_NOFOLLOW     = 0x020000; // octal   0400000
212         enum O_DIRECT       = 0x004000; // octal    040000
213         version (X86_64)
214             enum O_LARGEFILE = 0;
215         else
216             enum O_LARGEFILE = 0x08000; // octal   0100000
217         enum O_TMPFILE      = 0x410000; // octal 020200000
218         enum O_ASYNC        = 0x2000;   // octal    020000
219         enum O_NOATIME      = 0x40000;  // octal  01000000
220         enum O_PATH         = 0x200000; // octal 010000000
221         enum O_NDELAY       = O_NONBLOCK;
222     }
223     else version (HPPA_Any)
224     {
225         enum O_CREAT        = 0x00100;  // octal    04000
226         enum O_EXCL         = 0x00400;  // octal     0200
227         enum O_NOCTTY       = 0x20000;  // octal     0400
228         enum O_TRUNC        = 0x00200;  // octal    01000
229 
230         enum O_APPEND       = 0x00008;  // octal      010
231         enum O_NONBLOCK     = 0x10004;  // octal  0200004
232         enum O_CLOEXEC      = 0x200000; // octal 02000000
233         enum O_SYNC         = 0x48000;  // octal 01100000
234         enum O_DSYNC        = 0x40000;  // octal 01000000
235         enum O_RSYNC        = 0x80000;  // octal 02000000
236 
237         enum O_DIRECTORY    = 0x001000; // octal 000010000
238         enum O_NOFOLLOW     = 0x000080; // octal 000000200
239         enum O_DIRECT       = 0x004000; // octal    040000
240         enum O_LARGEFILE    = 0x000800; // octal  00004000
241         enum O_TMPFILE      = 0x801000; // octal 040010000
242         enum O_ASYNC        = 0x2000;   // octal    020000
243         enum O_NOATIME      = 0x100000; // octal 004000000
244         enum O_PATH         = 0x400000; // octal 020000000
245         enum O_NDELAY       = O_NONBLOCK;
246     }
247     else version (MIPS_Any)
248     {
249         enum O_CREAT        = 0x0100;
250         enum O_EXCL         = 0x0400;
251         enum O_NOCTTY       = 0x0800;
252         enum O_TRUNC        = 0x0200;
253 
254         enum O_APPEND       = 0x0008;
255         enum O_DSYNC        = 0x0010;
256         enum O_NONBLOCK     = 0x0080;
257         enum O_CLOEXEC      = 0x80000;
258         enum O_RSYNC        = O_SYNC;
259         enum O_SYNC         = 0x4010;
260 
261         enum O_DIRECTORY    = 0x010000;
262         enum O_NOFOLLOW     = 0x020000;
263         enum O_DIRECT       = 0x8000;
264         version (MIPS_N64)
265             enum O_LARGEFILE = 0;
266         else
267             enum O_LARGEFILE = 0x2000;
268         enum O_TMPFILE      = 0x410000;
269         enum O_ASYNC        = 0x1000;
270         enum O_NOATIME      = 0x40000;
271         enum O_PATH         = 0x200000;
272         enum O_NDELAY       = O_NONBLOCK;
273     }
274     else version (PPC_Any)
275     {
276         enum O_CREAT        = 0x40;     // octal     0100
277         enum O_EXCL         = 0x80;     // octal     0200
278         enum O_NOCTTY       = 0x100;    // octal     0400
279         enum O_TRUNC        = 0x200;    // octal    01000
280 
281         enum O_APPEND       = 0x400;    // octal    02000
282         enum O_NONBLOCK     = 0x800;    // octal    04000
283         enum O_CLOEXEC      = 0x80000;  // octal 02000000
284         enum O_SYNC         = 0x101000; // octal 04010000
285         enum O_DSYNC        = 0x1000;   // octal   010000
286         enum O_RSYNC        = O_SYNC;
287 
288         enum O_DIRECTORY    = 0x004000; // octal    040000
289         enum O_NOFOLLOW     = 0x008000; // octal   0100000
290         enum O_DIRECT       = 0x020000; // octal   0400000
291         version (D_LP64)
292             enum O_LARGEFILE = 0;
293         else
294             enum O_LARGEFILE = 0x10000; // octal   0200000
295         enum O_TMPFILE      = 0x404000; // octal 020040000
296         enum O_ASYNC        = 0x2000;   // octal    020000
297         enum O_NOATIME      = 0x40000;  // octal  01000000
298         enum O_PATH         = 0x200000;
299         enum O_NDELAY       = O_NONBLOCK;
300     }
301     else version (ARM_Any)
302     {
303         enum O_CREAT        = 0x40;     // octal     0100
304         enum O_EXCL         = 0x80;     // octal     0200
305         enum O_NOCTTY       = 0x100;    // octal     0400
306         enum O_TRUNC        = 0x200;    // octal    01000
307 
308         enum O_APPEND       = 0x400;    // octal    02000
309         enum O_NONBLOCK     = 0x800;    // octal    04000
310         enum O_CLOEXEC      = 0x80000;  // octal 02000000
311         enum O_SYNC         = 0x101000; // octal 04010000
312         enum O_DSYNC        = 0x1000;   // octal   010000
313         enum O_RSYNC        = O_SYNC;
314 
315         enum O_DIRECTORY    = 0x004000; // octal    040000
316         enum O_NOFOLLOW     = 0x008000; // octal   0100000
317         enum O_DIRECT       = 0x010000; // octal   0200000
318         version (D_LP64)
319             enum O_LARGEFILE = 0;
320         else
321             enum O_LARGEFILE = 0x20000; // octal   0400000
322         enum O_TMPFILE      = 0x404000; // octal 020040000
323         enum O_ASYNC        = 0x2000;   // octal    020000
324         enum O_NOATIME      = 0x40000;  // octal  01000000
325         enum O_PATH         = 0x200000; // octal 010000000
326         enum O_NDELAY       = O_NONBLOCK;
327     }
328     else version (RISCV_Any)
329     {
330         enum O_CREAT        = 0x40;     // octal     0100
331         enum O_EXCL         = 0x80;     // octal     0200
332         enum O_NOCTTY       = 0x100;    // octal     0400
333         enum O_TRUNC        = 0x200;    // octal    01000
334 
335         enum O_APPEND       = 0x400;    // octal    02000
336         enum O_NONBLOCK     = 0x800;    // octal    04000
337         enum O_CLOEXEC      = 0x80000;  // octal 02000000
338         enum O_SYNC         = 0x101000; // octal 04010000
339         enum O_DSYNC        = 0x1000;   // octal   010000
340         enum O_RSYNC        = O_SYNC;
341 
342         enum O_DIRECTORY    = 0x010000;
343         enum O_NOFOLLOW     = 0x020000;
344         enum O_DIRECT       = 0x004000;
345         version (D_LP64)
346             enum O_LARGEFILE = 0;
347         else
348             enum O_LARGEFILE = 0x8000;
349         enum O_TMPFILE      = 0x410000;
350         enum O_ASYNC        = 0x2000;
351         enum O_NOATIME      = 0x40000;
352         enum O_PATH         = 0x200000;
353         enum O_NDELAY       = O_NONBLOCK;
354     }
355     else version (SPARC_Any)
356     {
357         enum O_CREAT        = 0x200;
358         enum O_EXCL         = 0x800;
359         enum O_NOCTTY       = 0x8000;
360         enum O_TRUNC        = 0x400;
361 
362         enum O_APPEND       = 0x8;
363         enum O_NONBLOCK     = 0x4000;
364         enum O_CLOEXEC      = 0x400000;
365         enum O_SYNC         = 0x802000;
366         enum O_DSYNC        = 0x2000;
367         enum O_RSYNC        = O_SYNC;
368 
369         enum O_DIRECTORY    = 0x10000;
370         enum O_NOFOLLOW     = 0x20000;
371         enum O_DIRECT       = 0x100000;
372         version (D_LP64)
373             enum O_LARGEFILE = 0;
374         else
375             enum O_LARGEFILE = 0x40000;
376         enum O_TMPFILE      = 0x2010000;
377         enum O_ASYNC        = 0x0040;
378         enum O_NOATIME      = 0x200000;
379         enum O_PATH         = 0x1000000;
380         enum O_NDELAY       = (0x0004|O_NONBLOCK);
381     }
382     else version (IBMZ_Any)
383     {
384         enum O_CREAT        = 0x40;     // octal     0100
385         enum O_EXCL         = 0x80;     // octal     0200
386         enum O_NOCTTY       = 0x100;    // octal     0400
387         enum O_TRUNC        = 0x200;    // octal    01000
388 
389         enum O_APPEND       = 0x400;    // octal    02000
390         enum O_NONBLOCK     = 0x800;    // octal    04000
391         enum O_CLOEXEC      = 0x80000;  // octal 02000000
392         enum O_SYNC         = 0x101000; // octal 04010000
393         enum O_DSYNC        = 0x1000;   // octal   010000
394         enum O_RSYNC        = O_SYNC;
395 
396         enum O_DIRECTORY    = 0x010000; // octal   0200000
397         enum O_NOFOLLOW     = 0x020000; // octal   0400000
398         enum O_DIRECT       = 0x004000; // octal    040000
399         version (D_LP64)
400             enum O_LARGEFILE = 0;
401         else
402             enum O_LARGEFILE = 0x08000; // octal   0100000
403         enum O_TMPFILE      = 0x410000; // octal 020200000
404         enum O_ASYNC        = 0x2000;   // octal    020000
405         enum O_NOATIME      = 0x40000;  // octal  01000000
406         enum O_PATH         = 0x200000; // octal 010000000
407         enum O_NDELAY       = O_NONBLOCK;
408     }
409     else version (LoongArch64)
410     {
411         enum O_CREAT        = 0x40;     // octal     0100
412         enum O_EXCL         = 0x80;     // octal     0200
413         enum O_NOCTTY       = 0x100;    // octal     0400
414         enum O_TRUNC        = 0x200;    // octal    01000
415 
416         enum O_APPEND       = 0x400;    // octal    02000
417         enum O_NONBLOCK     = 0x800;    // octal    04000
418         enum O_CLOEXEC      = 0x80000;  // octal 02000000
419         enum O_SYNC         = 0x101000; // octal 04010000
420         enum O_DSYNC        = 0x1000;   // octal   010000
421         enum O_RSYNC        = O_SYNC;
422 
423         enum O_DIRECTORY    = 0x010000; // octal    200000
424         enum O_NOFOLLOW     = 0x020000; // octal    400000
425         enum O_DIRECT       = 0x004000; // octal    040000
426         version (D_LP64)
427             enum O_LARGEFILE = 0;
428         else
429             enum O_LARGEFILE = 0x8000;  // octal   0100000
430         enum O_TMPFILE      = 0x404000; // octal 020040000
431         enum O_ASYNC        = 0x2000;   // octal    020000
432         enum O_NOATIME      = 0x40000;  // octal  01000000
433         enum O_PATH         = 0x200000; // octal 010000000
434         enum O_NDELAY       = O_NONBLOCK;
435     }
436     else
437         static assert(0, "unimplemented");
438 
439     version (CRuntime_Musl)
440     {
441         enum O_SEARCH   = O_PATH;
442         enum O_EXEC     = O_PATH;
443         enum O_ACCMODE  = (3|O_SEARCH);
444     }
445     else
446     {
447         enum O_ACCMODE  = 0x3;
448     }
449     enum O_RDONLY       = 0x0;
450     enum O_WRONLY       = 0x1;
451     enum O_RDWR         = 0x2;
452 
453     struct flock
454     {
455         short   l_type;
456         short   l_whence;
457         off_t   l_start;
458         off_t   l_len;
459         pid_t   l_pid;
460     }
461 
462     enum AT_SYMLINK_NOFOLLOW = 0x100;
463     enum AT_FDCWD = -100;
464     enum AT_REMOVEDIR = 0x200;
465     enum AT_SYMLINK_FOLLOW = 0x400;
466     enum AT_EACCESS = 0x200;
467 }
468 else version (Darwin)
469 {
470     enum F_DUPFD        = 0;
471     enum F_GETFD        = 1;
472     enum F_SETFD        = 2;
473     enum F_GETFL        = 3;
474     enum F_SETFL        = 4;
475     enum F_GETOWN       = 5;
476     enum F_SETOWN       = 6;
477     enum F_GETLK        = 7;
478     enum F_SETLK        = 8;
479     enum F_SETLKW       = 9;
480 
481     enum FD_CLOEXEC     = 1;
482 
483     enum F_RDLCK        = 1;
484     enum F_UNLCK        = 2;
485     enum F_WRLCK        = 3;
486 
487     enum O_CREAT        = 0x0200;
488     enum O_EXCL         = 0x0800;
489     enum O_NOCTTY       = 0;
490     enum O_TRUNC        = 0x0400;
491 
492     enum O_RDONLY       = 0x0000;
493     enum O_WRONLY       = 0x0001;
494     enum O_RDWR         = 0x0002;
495     enum O_ACCMODE      = 0x0003;
496 
497     enum O_NONBLOCK     = 0x0004;
498     enum O_APPEND       = 0x0008;
499     enum O_SYNC         = 0x0080;
500     //enum O_DSYNC
501     //enum O_RSYNC
502 
503     struct flock
504     {
505         off_t   l_start;
506         off_t   l_len;
507         pid_t   l_pid;
508         short   l_type;
509         short   l_whence;
510     }
511 }
512 else version (FreeBSD)
513 {
514     enum F_DUPFD        = 0;
515     enum F_GETFD        = 1;
516     enum F_SETFD        = 2;
517     enum F_GETFL        = 3;
518     enum F_SETFL        = 4;
519     enum F_GETOWN       = 5;
520     enum F_SETOWN       = 6;
521     enum F_GETLK        = 11;
522     enum F_SETLK        = 12;
523     enum F_SETLKW       = 13;
524     enum F_OGETLK       = 7;
525     enum F_OSETLK       = 8;
526     enum F_OSETLKW      = 9;
527     enum F_DUP2FD       = 10;
528 
529     enum FD_CLOEXEC     = 1;
530 
531     enum F_RDLCK        = 1;
532     enum F_UNLCK        = 2;
533     enum F_WRLCK        = 3;
534 
535     enum O_CREAT        = 0x0200;
536     enum O_EXCL         = 0x0800;
537     enum O_NOCTTY       = 0x8000;
538     enum O_TRUNC        = 0x0400;
539 
540     enum O_RDONLY       = 0x0000;
541     enum O_WRONLY       = 0x0001;
542     enum O_RDWR         = 0x0002;
543     enum O_ACCMODE      = 0x0003;
544 
545     enum O_NONBLOCK     = 0x0004;
546     enum O_APPEND       = 0x0008;
547     enum O_SYNC         = 0x0080;
548     //enum O_DSYNC
549     //enum O_RSYNC
550 
551     struct flock
552     {
553         off_t   l_start;
554         off_t   l_len;
555         pid_t   l_pid;
556         short   l_type;
557         short   l_whence;
558         int     l_sysid;
559     }
560 
561     struct oflock
562     {
563         off_t   l_start;
564         off_t   l_len;
565         pid_t   l_pid;
566         short   l_type;
567         short   l_whence;
568     }
569 
570     enum AT_SYMLINK_NOFOLLOW = 0x200;
571     enum AT_FDCWD = -100;
572 }
573 else version (OpenBSD)
574 {
575     enum F_DUPFD        = 0;
576     enum F_GETFD        = 1;
577     enum F_SETFD        = 2;
578     enum F_GETFL        = 3;
579     enum F_SETFL        = 4;
580     enum F_GETOWN       = 5;
581     enum F_SETOWN       = 6;
582     enum F_GETLK        = 7;
583     enum F_SETLK        = 8;
584     enum F_SETLKW       = 9;
585     enum F_DUPFD_CLOEXEC= 10;
586     enum F_ISATTY       = 11;
587 
588     enum FD_CLOEXEC     = 1;
589 
590     enum F_RDLCK        = 1;
591     enum F_UNLCK        = 2;
592     enum F_WRLCK        = 3;
593 
594     enum O_CREAT        = 0x0200;
595     enum O_EXCL         = 0x0800;
596     enum O_NOCTTY       = 0x8000;
597     enum O_TRUNC        = 0x0400;
598 
599     enum O_RDONLY       = 0x0000;
600     enum O_WRONLY       = 0x0001;
601     enum O_RDWR         = 0x0002;
602     enum O_ACCMODE      = 0x0003;
603     enum O_SHLOCK       = 0x0010;
604     enum O_EXLOCK       = 0x0020;
605     enum O_ASYNC        = 0x0040;
606     enum O_FSYNC        = 0x0080;
607     enum O_NOFOLLOW     = 0x0100;
608 
609     enum O_NONBLOCK     = 0x0004;
610     enum O_APPEND       = 0x0008;
611     enum O_SYNC         = 0x0080;
612     enum O_DSYNC        = O_SYNC;
613     enum O_RSYNC        = O_SYNC;
614 
615     enum O_CLOEXEC      = 0x10000;
616     enum O_DIRECTORY    = 0x20000;
617 
618     enum LOCK_SH        = 0x01;
619     enum LOCK_EX        = 0x02;
620     enum LOCK_NB        = 0x04;
621     enum LOCK_UN        = 0x08;
622 
623     struct flock
624     {
625         off_t   l_start;
626         off_t   l_len;
627         pid_t   l_pid;
628         short   l_type;
629         short   l_whence;
630     }
631 
632     enum AT_FDCWD            = -100;
633 
634     enum AT_EACCESS          = 0x01;
635     enum AT_SYMLINK_NOFOLLOW = 0x02;
636     enum AT_SYMLINK_FOLLOW   = 0x04;
637     enum AT_REMOVEDIR        = 0x08;
638 }
639 else version (NetBSD)
640 {
641     enum F_DUPFD        = 0;
642     enum F_GETFD        = 1;
643     enum F_SETFD        = 2;
644     enum F_GETFL        = 3;
645     enum F_SETFL        = 4;
646     enum F_GETOWN       = 5;
647     enum F_SETOWN       = 6;
648     enum F_GETLK        = 7;
649     enum F_SETLK        = 8;
650     enum F_SETLKW       = 9;
651     enum F_CLOSEM       = 10;
652     enum F_MAXFD        = 11;
653     enum F_DUPFD_CLOEXEC= 12;
654     enum F_GETNOSIGPIPE = 13;
655     enum F_SETNOSIGPIPE = 14;
656 
657     enum FD_CLOEXEC     = 1;
658 
659     enum F_RDLCK        = 1;
660     enum F_UNLCK        = 2;
661     enum F_WRLCK        = 3;
662 
663     enum O_CREAT        = 0x0200;
664     enum O_EXCL         = 0x0800;
665     enum O_NOCTTY       = 0x8000;
666     enum O_TRUNC        = 0x0400;
667 
668     enum O_RDONLY       = 0x0000;
669     enum O_WRONLY       = 0x0001;
670     enum O_RDWR         = 0x0002;
671     enum O_ACCMODE      = 0x0003;
672 
673     enum O_NONBLOCK     = 0x0004;
674     enum O_APPEND       = 0x0008;
675     enum O_SYNC         = 0x0080;
676     //enum O_DSYNC
677     //enum O_RSYNC
678 
679     struct flock
680     {
681         off_t   l_start;
682         off_t   l_len;
683         pid_t   l_pid;
684         short   l_type;
685         short   l_whence;
686     }
687 }
688 else version (DragonFlyBSD)
689 {
690     enum O_RDONLY       = 0x0000;
691     enum O_WRONLY       = 0x0001;
692     enum O_RDWR         = 0x0002;
693     enum O_ACCMODE      = 0x0003;
694 
695     enum FREAD          = 0x0001;
696     enum FWRITE         = 0x0002;
697     enum O_NONBLOCK     = 0x0000004;
698     enum O_APPEND       = 0x0000008;
699     enum O_SHLOCK       = 0x0000010;
700     enum O_EXLOCK       = 0x0000020;
701     enum O_ASYNC        = 0x0000040;
702     enum O_FSYNC        = 0x0000080;
703     enum O_SYNC         = 0x0000080;
704     enum O_NOFOLLOW     = 0x0000100;
705     enum O_CREAT        = 0x0000200;
706     enum O_TRUNC        = 0x0000400;
707     enum O_EXCL         = 0x0000800;
708     enum O_NOCTTY       = 0x0008000;
709     enum O_DIRECT       = 0x0010000;
710     enum O_CLOEXEC      = 0x0020000;
711     enum O_FBLOCKING    = 0x0040000;
712     enum O_FNONBLOCKING = 0x0080000;
713     enum O_FAPPEND      = 0x0100000;
714     enum O_FOFFSET      = 0x0200000;
715     enum O_FSYNCWRITE   = 0x0400000;
716     enum O_FASYNCWRITE  = 0x0800000;
717     enum O_DIRECTORY    = 0x8000000;
718 
719     enum FAPPEND        = O_APPEND;
720     enum FASYNC         = O_ASYNC;
721     enum FFSYNC         = O_FSYNC;
722     enum FNONBLOCK      = O_NONBLOCK;
723     enum FNDELAY        = O_NONBLOCK;
724     enum O_NDELAY       = O_NONBLOCK;
725     enum FPOSIXSHM      = O_NOFOLLOW;
726 
727     enum FCNTLFLAGS = (FAPPEND|FASYNC|FFSYNC|FNONBLOCK|FPOSIXSHM|O_DIRECT);
728 
729     enum F_DUPFD        = 0;
730     enum F_GETFD        = 1;
731     enum F_SETFD        = 2;
732     enum F_GETFL        = 3;
733     enum F_SETFL        = 4;
734     enum F_GETOWN       = 5;
735     enum F_SETOWN       = 6;
736     enum F_GETLK        = 7;
737 //    enum F_SETLK        = 8;
738     enum F_SETLK        = 8;
739     enum F_SETLKW       = 9;
740     enum F_OGETLK       = F_GETLK;
741     enum F_OSETLK       = F_SETLK;
742     enum F_OSETLKW      = F_SETLKW;
743     enum F_DUP2FD       = 10;
744     //enum F_GETLK        = 11;
745     //enum F_SETLK        = 12;
746     //enum F_SETLKW       = 13;
747     enum F_DUPFD_CLOEXEC = 17;
748     enum F_DUP2FD_CLOEXEC = 18;
749 
750     enum FD_CLOEXEC     = 1;
751 
752     enum F_RDLCK        = 1;
753     enum F_UNLCK        = 2;
754     enum F_WRLCK        = 3;
755 
756     enum LOCK_SH        = 0x01;
757     enum LOCK_EX        = 0x02;
758     enum LOCK_NB        = 0x04;
759     enum LOCK_UN        = 0x08;
760 
761     struct flock
762     {
763         off_t   l_start;
764         off_t   l_len;
765         pid_t   l_pid;
766         short   l_type;
767         short   l_whence;
768     }
769 
770     alias oflock = flock;
771 }
772 else version (Solaris)
773 {
774     enum F_DUPFD = 0;
775     enum F_GETFD = 1;
776     enum F_SETFD = 2;
777     enum F_GETFL = 3;
778     enum F_SETFL = 4;
779 
780     version (D_LP64)
781     {
782         enum F_GETLK = 14;
783         enum F_SETLK = 6;
784         enum F_SETLKW = 7;
785     }
786     else
787     {
788         static if (__USE_FILE_OFFSET64)
789         {
790             enum F_GETLK = 14;
791             enum F_SETLK = 6;
792             enum F_SETLKW = 7;
793         }
794         else
795         {
796             enum F_GETLK = 33;
797             enum F_SETLK = 34;
798             enum F_SETLKW = 35;
799         }
800     }
801 
802     enum F_GETOWN = 23;
803     enum F_SETOWN = 24;
804 
805     enum FD_CLOEXEC = 1;
806 
807     enum F_RDLCK = 1;
808     enum F_UNLCK = 3;
809     enum F_WRLCK = 2;
810     enum F_UNCKSYS = 4;
811 
812     enum O_CREAT = 0x0100;
813     enum O_EXCL = 0x0400;
814     enum O_NOCTTY = 0x0800;
815     enum O_TRUNC = 0x0200;
816 
817     enum O_APPEND = 0x0008;
818     enum O_NONBLOCK = 0x0080;
819     enum O_SYNC = 0x0010;
820     enum O_DSYNC = 0x0040;
821     enum O_RSYNC = 0x8000;
822 
823     enum O_ACCMODE = (O_SEARCH | O_EXEC | 0x3);
824     enum O_RDONLY = 0;
825     enum O_WRONLY = 1;
826     enum O_RDWR = 2;
827     enum O_SEARCH = 0x200000;
828     enum O_EXEC = 0x400000;
829 
830     struct flock
831     {
832         short l_type;
833         short l_whence;
834         off_t l_start;
835         off_t l_len;
836         int l_sysid;
837         pid_t l_pid;
838         c_long[4] l_pad;
839     }
840 
841     static if (__USE_LARGEFILE64)
842     {
843         struct flock64
844         {
845             short       l_type;
846             short       l_whence;
847             off64_t     l_start;
848             off64_t     l_len;
849             int         l_sysid;
850             pid_t       l_pid;
851             c_long[4]   l_pad;
852         }
853     }
854 }
855 else
856 {
857     static assert(false, "Unsupported platform");
858 }
859 
860 /*
861 int creat(const scope char*, mode_t);
862 int fcntl(int, int, ...);
863 int open(const scope char*, int, ...);
864 */
865 version (CRuntime_Glibc)
866 {
867     static if ( __USE_FILE_OFFSET64 )
868     {
869         int   creat64(const scope char*, mode_t);
870         alias creat64 creat;
871 
872         int   open64(const scope char*, int, ...);
873         alias open64 open;
874     }
875     else
876     {
877         int   creat(const scope char*, mode_t);
878         int   open(const scope char*, int, ...);
879     }
880 }
881 else version (Darwin)
882 {
883     int creat(const scope char*, mode_t);
884     int open(const scope char*, int, ...);
885 }
886 else version (FreeBSD)
887 {
888     int creat(const scope char*, mode_t);
889     int open(const scope char*, int, ...);
890 }
891 else version (OpenBSD)
892 {
893     int creat(const scope char*, mode_t);
894     int open(const scope char*, int, ...);
895 }
896 else version (NetBSD)
897 {
898     int creat(const scope char*, mode_t);
899     int open(const scope char*, int, ...);
900 }
901 else version (DragonFlyBSD)
902 {
903     int creat(const scope char*, mode_t);
904     int open(const scope char*, int, ...);
905 }
906 else version (Solaris)
907 {
908     version (D_LP64)
909     {
910         int creat(const scope char*, mode_t);
911         int open(const scope char*, int, ...);
912 
913         static if (__USE_LARGEFILE64)
914         {
915             alias creat creat64;
916             alias open open64;
917         }
918     }
919     else
920     {
921         static if (__USE_LARGEFILE64)
922         {
923             int creat64(const scope char*, mode_t);
924             alias creat64 creat;
925 
926             int open64(const scope char*, int, ...);
927             alias open64 open;
928         }
929         else
930         {
931             int creat(const scope char*, mode_t);
932             int open(const scope char*, int, ...);
933         }
934     }
935 }
936 else version (CRuntime_Bionic)
937 {
938     int   creat(const scope char*, mode_t);
939     int   open(const scope char*, int, ...);
940 }
941 else version (CRuntime_Musl)
942 {
943     int open(const scope char*, int, ...);
944 }
945 else version (CRuntime_UClibc)
946 {
947     static if ( __USE_FILE_OFFSET64 )
948     {
949         int   creat64(const scope char*, mode_t);
950         alias creat64 creat;
951 
952         int   open64(const scope char*, int, ...);
953         alias open64 open;
954     }
955     else
956     {
957         int   creat(const scope char*, mode_t);
958         int   open(const scope char*, int, ...);
959     }
960 }
961 else
962 {
963     static assert(false, "Unsupported platform");
964 }
965 
966 //int creat(const scope char*, mode_t);
967 int fcntl(int, int, ...);
968 //int open(const scope char*, int, ...);
969 
970 // Generic Posix fallocate
971 int posix_fallocate(int, off_t, off_t);
972 
973 //
974 // Advisory Information (ADV)
975 //
976 /*
977 POSIX_FADV_NORMAL
978 POSIX_FADV_SEQUENTIAL
979 POSIX_FADV_RANDOM
980 POSIX_FADV_WILLNEED
981 POSIX_FADV_DONTNEED
982 POSIX_FADV_NOREUSE
983 
984 int posix_fadvise(int, off_t, off_t, int);
985 */