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