Fix file cache tunables documentation
[gcc.git] / libphobos / libdruntime / core / stdc / stdio.d
blobd3ee2cae8e53fedc5aa0a5acd4443994d049ec5f
1 /**
2 * D header file for C99 <stdio.h>
4 * $(C_HEADER_DESCRIPTION pubs.opengroup.org/onlinepubs/009695399/basedefs/_stdio.h.html, _stdio.h)
6 * Copyright: Copyright Sean Kelly 2005 - 2009.
7 * License: Distributed under the
8 * $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0).
9 * (See accompanying file LICENSE)
10 * Authors: Sean Kelly,
11 * Alex Rønne Petersen
12 * Source: $(DRUNTIMESRC core/stdc/_stdio.d)
13 * Standards: ISO/IEC 9899:1999 (E)
16 module core.stdc.stdio;
18 version (OSX)
19 version = Darwin;
20 else version (iOS)
21 version = Darwin;
22 else version (TVOS)
23 version = Darwin;
24 else version (WatchOS)
25 version = Darwin;
27 private
29 import core.stdc.config;
30 import core.stdc.stdarg; // for va_list
31 import core.stdc.stdint : intptr_t;
33 version (FreeBSD)
35 import core.sys.posix.sys.types;
37 else version (OpenBSD)
39 import core.sys.posix.sys.types;
41 version (NetBSD)
43 import core.sys.posix.sys.types;
45 version (DragonFlyBSD)
47 import core.sys.posix.sys.types;
51 extern (C):
52 nothrow:
53 @nogc:
55 version (CRuntime_Microsoft)
57 enum
59 ///
60 BUFSIZ = 512,
61 ///
62 EOF = -1,
63 ///
64 FOPEN_MAX = 20,
65 ///
66 FILENAME_MAX = 260,
67 /// Actually int.max since Visual Studio 2015.
68 TMP_MAX = 32767,
69 ///
70 _SYS_OPEN = 20, // non-standard
73 ///
74 enum int _NFILE = 512; // non-standard
75 /// Removed since Visual Studio 2015.
76 enum string _P_tmpdir = "\\"; // non-standard
77 /// Removed since Visual Studio 2015.
78 enum wstring _wP_tmpdir = "\\"; // non-standard
79 /// Actually 260 since Visual Studio 2015.
80 enum int L_tmpnam = _P_tmpdir.length + 12;
82 else version (CRuntime_Glibc)
84 enum
86 ///
87 BUFSIZ = 8192,
88 ///
89 EOF = -1,
90 ///
91 FOPEN_MAX = 16,
92 ///
93 FILENAME_MAX = 4095,
94 ///
95 TMP_MAX = 238328,
96 ///
97 L_tmpnam = 20
100 else version (CRuntime_Musl)
102 enum
105 BUFSIZ = 1024,
107 EOF = -1,
109 FOPEN_MAX = 1000,
111 FILENAME_MAX = 4096,
113 TMP_MAX = 10000,
115 L_tmpnam = 20
118 else version (Darwin)
120 enum
123 BUFSIZ = 1024,
125 EOF = -1,
127 FOPEN_MAX = 20,
129 FILENAME_MAX = 1024,
131 TMP_MAX = 308915776,
133 L_tmpnam = 1024,
136 private
138 struct __sbuf
140 ubyte* _base;
141 int _size;
144 struct __sFILEX
150 else version (FreeBSD)
152 enum
155 BUFSIZ = 1024,
157 EOF = -1,
159 FOPEN_MAX = 20,
161 FILENAME_MAX = 1024,
163 TMP_MAX = 308915776,
165 L_tmpnam = 1024
168 struct __sbuf
170 ubyte *_base;
171 int _size;
174 else version (NetBSD)
176 enum
179 BUFSIZ = 1024,
181 EOF = -1,
183 FOPEN_MAX = 20,
185 FILENAME_MAX = 1024,
187 TMP_MAX = 308915776,
189 L_tmpnam = 1024
192 struct __sbuf
194 ubyte *_base;
195 int _size;
198 else version (OpenBSD)
200 enum
203 BUFSIZ = 1024,
205 EOF = -1,
207 FOPEN_MAX = 20,
209 FILENAME_MAX = 1024,
211 TMP_MAX = 0x7fffffff,
213 L_tmpnam = 1024
216 struct __sbuf
218 ubyte *_base;
219 int _size;
222 else version (DragonFlyBSD)
224 enum
226 BUFSIZ = 1024,
227 EOF = -1,
228 FOPEN_MAX = 20,
229 FILENAME_MAX = 1024,
230 TMP_MAX = 308915776,
231 L_tmpnam = 1024
234 struct __sbuf { // <sys/sbuf.h>
235 byte* s_buf; // storage buffer
236 int function(void *, const char *, int) sbuf_drain_func;
237 void* s_drain_arg; // user-supplied drain argument
238 int s_error; // current error code
239 ssize_t s_size; // size of storage buffer
240 ssize_t s_len; // current length of string
241 int s_flags; // flags
242 ssize_t s_sect_len; // current length of section
245 enum {
246 SBUF_FIXEDLEN = 0x00000000, // fixed length buffer (default)
247 SBUF_AUTOEXTEND = 0x00000001, // automatically extend buffer
248 SBUF_USRFLAGMSK = 0x0000ffff, // mask of flags the user may specify
249 SBUF_DYNAMIC = 0x00010000, // s_buf must be freed
250 SBUF_FINISHED = 0x00020000, // set by sbuf_finish()
251 SBUF_DYNSTRUCT = 0x00080000, // sbuf must be freed
252 SBUF_INSECTION = 0x00100000, // set by sbuf_start_section()
255 else version (Solaris)
257 enum
260 BUFSIZ = 1024,
262 EOF = -1,
264 FOPEN_MAX = _NFILE,
266 FILENAME_MAX = 1024,
268 TMP_MAX = 17576,
270 L_tmpnam = 25,
273 version (X86)
275 enum int _NFILE = 60;
276 else
278 enum int _NFILE = 20;
280 else version (CRuntime_Bionic)
282 enum
285 BUFSIZ = 1024,
287 EOF = -1,
289 FOPEN_MAX = 20,
291 FILENAME_MAX = 1024,
293 TMP_MAX = 308915776,
295 L_tmpnam = 1024
298 struct __sbuf
300 ubyte* _base;
301 int _size;
304 else version (CRuntime_Newlib)
306 enum
309 BUFSIZ = 1024,
311 EOF = -1,
313 FOPEN_MAX = 20,
315 FILENAME_MAX = 1024,
317 TMP_MAX = 26,
319 L_tmpnam = 1024
322 struct __sbuf
324 ubyte* _base;
325 int _size;
328 else version (CRuntime_UClibc)
330 enum
333 BUFSIZ = 4096,
335 EOF = -1,
337 FOPEN_MAX = 16,
339 FILENAME_MAX = 4095,
341 TMP_MAX = 238328,
343 L_tmpnam = 20
346 else version (WASI)
348 enum
351 BUFSIZ = 1024,
353 EOF = -1,
355 FOPEN_MAX = 1000,
357 FILENAME_MAX = 4096,
359 TMP_MAX = 10000,
361 L_tmpnam = 20
364 else
366 static assert( false, "Unsupported platform" );
369 enum
371 /// Offset is relative to the beginning
372 SEEK_SET,
373 /// Offset is relative to the current position
374 SEEK_CUR,
375 /// Offset is relative to the end
376 SEEK_END
379 version (CRuntime_Microsoft)
382 alias long fpos_t;
385 struct _iobuf
387 void* undefined;
391 alias shared(_iobuf) FILE;
393 else version (CRuntime_Glibc)
395 import core.stdc.wchar_ : mbstate_t;
397 struct fpos_t
399 long __pos; // couldn't use off_t because of static if issue
400 mbstate_t __state;
404 struct _IO_FILE
406 int _flags;
407 char* _read_ptr;
408 char* _read_end;
409 char* _read_base;
410 char* _write_base;
411 char* _write_ptr;
412 char* _write_end;
413 char* _buf_base;
414 char* _buf_end;
415 char* _save_base;
416 char* _backup_base;
417 char* _save_end;
418 void* _markers;
419 _IO_FILE* _chain;
420 int _fileno;
421 int _flags2;
422 ptrdiff_t _old_offset;
423 ushort _cur_column;
424 byte _vtable_offset;
425 char[1] _shortbuf = 0;
426 void* _lock;
428 ptrdiff_t _offset;
430 /*_IO_codecvt*/ void* _codecvt;
431 /*_IO_wide_data*/ void* _wide_data;
432 _IO_FILE *_freeres_list;
433 void *_freeres_buf;
434 size_t __pad5;
435 int _mode;
437 char[15 * int.sizeof - 4 * (void*).sizeof - size_t.sizeof] _unused2;
441 alias _IO_FILE _iobuf;
443 alias shared(_IO_FILE) FILE;
445 else version (WASI)
447 union fpos_t
449 char[16] __opaque = 0;
450 double __align;
452 struct _IO_FILE;
455 alias _IO_FILE _iobuf; // needed for phobos
457 alias shared(_IO_FILE) FILE;
459 else version (CRuntime_Musl)
461 union fpos_t
463 char[16] __opaque = 0;
464 double __align;
466 struct _IO_FILE;
469 alias _IO_FILE _iobuf; // needed for phobos
471 alias shared(_IO_FILE) FILE;
473 else version (Darwin)
476 alias long fpos_t;
479 struct __sFILE
481 ubyte* _p;
482 int _r;
483 int _w;
484 short _flags;
485 short _file;
486 __sbuf _bf;
487 int _lbfsize;
489 void* _cookie;
490 int function(void*) _close;
491 int function(void*, char*, int) _read;
492 fpos_t function(void*, fpos_t, int) _seek;
493 int function(void*, char *, int) _write;
495 __sbuf _ub;
496 __sFILEX* _extra;
497 int _ur;
499 ubyte[3] _ubuf;
500 ubyte[1] _nbuf;
502 __sbuf _lb;
504 int _blksize;
505 fpos_t _offset;
509 alias __sFILE _iobuf;
511 alias shared(__sFILE) FILE;
513 else version (FreeBSD)
515 // Need to import wchar_ now since __mbstate_t now resides there
516 import core.stdc.wchar_ : mbstate_t;
519 alias off_t fpos_t;
522 struct __sFILE
524 ubyte* _p;
525 int _r;
526 int _w;
527 short _flags;
528 short _file;
529 __sbuf _bf;
530 int _lbfsize;
532 void* _cookie;
533 int function(void*) _close;
534 int function(void*, char*, int) _read;
535 fpos_t function(void*, fpos_t, int) _seek;
536 int function(void*, const scope char*, int) _write;
538 __sbuf _ub;
539 ubyte* _up;
540 int _ur;
542 ubyte[3] _ubuf;
543 ubyte[1] _nbuf;
545 __sbuf _lb;
547 int _blksize;
548 fpos_t _offset;
550 pthread_mutex_t _fl_mutex;
551 pthread_t _fl_owner;
552 int _fl_count;
553 int _orientation;
554 mbstate_t _mbstate;
558 alias __sFILE _iobuf;
560 alias shared(__sFILE) FILE;
562 else version (NetBSD)
565 alias off_t fpos_t;
568 struct __sFILE
570 ubyte* _p;
571 int _r;
572 int _w;
573 ushort _flags;
574 short _file;
575 __sbuf _bf;
576 int _lbfsize;
578 void* _cookie;
579 int function(void*) _close;
580 ssize_t function(void*, char*, size_t) _read;
581 fpos_t function(void*, fpos_t, int) _seek;
582 ssize_t function(void*, const scope char*, size_t) _write;
584 __sbuf _ub;
585 ubyte* _up;
586 int _ur;
588 ubyte[3] _ubuf;
589 ubyte[1] _nbuf;
591 int function(void *) _flush;
592 /* Formerly used by fgetln/fgetwln; kept for binary compatibility */
593 char[__sbuf.sizeof - _flush.sizeof] _lb_unused = void;
596 int _blksize;
597 off_t _offset;
598 static assert(off_t.sizeof==8);
602 alias __sFILE _iobuf;
604 alias shared(__sFILE) FILE;
606 else version (OpenBSD)
609 alias fpos_t = off_t;
612 struct __sFILE
614 ubyte* _p;
615 int _r;
616 int _w;
617 short _flags;
618 short _file;
619 __sbuf _bf;
620 int _lbfsize;
622 void* _cookie;
623 int function(void*) _close;
624 int function(void*, scope char*, int) _read;
625 fpos_t function(void*, fpos_t, int) _seek;
626 int function(void*, scope const char*, int) _write;
628 __sbuf _ext;
629 ubyte* _up;
630 int _ur;
632 ubyte[3] _ubuf;
633 ubyte[1] _nbuf;
635 __sbuf _lb;
637 int _blksize;
638 fpos_t _offset;
642 alias __sFILE _iobuf;
644 alias shared(__sFILE) FILE;
646 else version (DragonFlyBSD)
648 alias off_t fpos_t;
650 /// See /usr/include/stdio.h
651 struct __FILE_public
653 ubyte* *_p; /* current position in (some) buffer */
654 int _flags; /* flags, below; this FILE is free if 0 */
655 int _fileno; /* fileno, if Unix descriptor, else -1 */
656 ssize_t _r; /* read space left for getc() */
657 ssize_t _w; /* write space left for putc() */
658 ssize_t _lbfsize; /* 0 or -_bf._size, for inline putc */
661 alias __FILE_public _iobuf;
662 alias shared(__FILE_public) FILE;
664 else version (Solaris)
666 import core.stdc.wchar_ : mbstate_t;
669 alias c_long fpos_t;
671 version (D_LP64)
674 struct _iobuf
676 char* _ptr; /* next character from/to here in buffer */
677 char* _base; /* the buffer */
678 char* _end; /* the end of the buffer */
679 size_t _cnt; /* number of available characters in buffer */
680 int _file; /* UNIX System file descriptor */
681 int _flag; /* the state of the stream */
682 ubyte[24] _lock; //rmutex_t _lock; /* lock for this structure */
683 mbstate_t _state; /* mbstate_t */
684 ubyte[32] __fill; /* filler to bring size to 128 bytes */
687 else
690 struct _iobuf
692 char* _ptr;
693 int _cnt;
694 char* _base;
695 char _flag = 0;
696 char _magic = 0;
697 ushort __flags; // __orientation:2
698 // __ionolock:1
699 // __seekable:1
700 // __extendedfd:1
701 // __xf_nocheck:1
702 // __filler:10
706 alias shared(_iobuf) FILE;
708 else version (CRuntime_Bionic)
711 alias c_long fpos_t; // couldn't use off_t because of static if issue
714 struct __sFILE
716 ubyte* _p;
717 int _r;
718 int _w;
719 short _flags;
720 short _file;
721 __sbuf _bf;
722 int _lbfsize;
724 void* _cookie;
725 int function(void*) _close;
726 int function(void*, scope char*, int) _read;
727 fpos_t function(void*, fpos_t, int) _seek;
728 int function(void*, scope const char*, int) _write;
730 __sbuf _ext;
731 ubyte* _up;
732 int _ur;
734 ubyte[3] _ubuf;
735 ubyte[1] _nbuf;
737 __sbuf _lb;
739 int _blksize;
740 fpos_t _offset;
744 alias __sFILE _iobuf;
746 alias shared(__sFILE) FILE;
748 else version (CRuntime_Newlib)
750 import core.sys.posix.sys.types : ssize_t;
751 import core.stdc.wchar_ : mbstate_t;
754 alias fpos_t = c_long;
757 struct __sFILE
759 ubyte* _p;
760 int _r;
761 int _w;
762 short _flags;
763 short _file;
764 __sbuf _bf;
765 int _lbfsize;
767 void* _data;
768 void* _cookie;
770 ssize_t function(void*, void*, scope char*, size_t) _read;
771 ssize_t function(void*, void*, scope const char*, size_t) _write;
772 fpos_t function(void*, void*, fpos_t, int) _seek;
773 int function(void*, void*) _close;
775 __sbuf _ub;
776 ubyte* _up;
777 int _ur;
779 ubyte[3] _ubuf;
780 ubyte[1] _nbuf;
782 __sbuf _lb;
784 int _blksize;
785 int _flags2;
787 long _offset;
788 void* _unused;
790 void* _lock;
791 mbstate_t _mbstate;
795 alias __sFILE _iobuf; // needed for phobos
797 alias shared(__sFILE) FILE;
799 else version (CRuntime_UClibc)
801 import core.stdc.wchar_ : mbstate_t;
802 import core.stdc.stddef : wchar_t;
803 import core.sys.posix.sys.types : ssize_t, pthread_mutex_t;
806 struct fpos_t
808 long __pos; // couldn't use off_t because of static if issue
809 mbstate_t __state;
810 int __mblen_pending;
813 struct _IO_cookie_io_functions_t
815 ssize_t function(void* __cookie, char* __buf, size_t __bufsize) read;
816 ssize_t function(void* __cookie, const char* __buf, size_t __bufsize) write;
817 int function(void* __cookie, long* __pos, int __whence) seek;
818 int function(void* __cookie) close;
821 alias _IO_cookie_io_functions_t cookie_io_functions_t;
824 struct __STDIO_FILE_STRUCT
826 ushort __modeflags;
827 char[2] __ungot_width = 0;
828 int __filedes;
829 char* __bufstart;
830 char* __bufend;
831 char* __bufpos;
832 char* __bufread;
833 char* __bufgetc_u;
834 char*__bufputc_u;
835 __STDIO_FILE_STRUCT* __nextopen;
836 void *__cookie;
837 _IO_cookie_io_functions_t __gcs;
838 wchar_t[2] __ungot = 0;
839 mbstate_t __state;
840 void *__unused;
841 int __user_locking;
842 pthread_mutex_t __lock;
846 alias __STDIO_FILE_STRUCT _iobuf;
848 alias shared(__STDIO_FILE_STRUCT) FILE;
850 else
852 static assert( false, "Unsupported platform" );
855 enum
858 _F_RDWR = 0x0003, // non-standard
860 _F_READ = 0x0001, // non-standard
862 _F_WRIT = 0x0002, // non-standard
864 _F_BUF = 0x0004, // non-standard
866 _F_LBUF = 0x0008, // non-standard
868 _F_ERR = 0x0010, // non-standard
870 _F_EOF = 0x0020, // non-standard
872 _F_BIN = 0x0040, // non-standard
874 _F_IN = 0x0080, // non-standard
876 _F_OUT = 0x0100, // non-standard
878 _F_TERM = 0x0200, // non-standard
881 version (CRuntime_Microsoft)
883 enum
886 _IOFBF = 0,
888 _IOLBF = 0x40,
890 _IONBF = 4,
891 /// Removed since Visual Studio 2015.
892 _IOREAD = 1, // non-standard
893 /// Removed since Visual Studio 2015.
894 _IOWRT = 2, // non-standard
895 /// Removed since Visual Studio 2015.
896 _IOMYBUF = 8, // non-standard
897 /// Removed since Visual Studio 2015.
898 _IOEOF = 0x10, // non-standard
899 /// Removed since Visual Studio 2015.
900 _IOERR = 0x20, // non-standard
901 /// Removed since Visual Studio 2015.
902 _IOSTRG = 0x40, // non-standard
903 /// Removed since Visual Studio 2015.
904 _IORW = 0x80, // non-standard
905 /// Removed since Visual Studio 2015.
906 _IOAPP = 0x200, // non-standard
907 /// Removed since Visual Studio 2015.
908 _IOAPPEND = 0x200, // non-standard
911 extern shared void function() _fcloseallp;
913 FILE* __acrt_iob_func(int hnd); // VS2015+, reimplemented in msvc.d for VS2013-
916 FILE* stdin()() { return __acrt_iob_func(0); }
918 FILE* stdout()() { return __acrt_iob_func(1); }
920 FILE* stderr()() { return __acrt_iob_func(2); }
922 else version (CRuntime_Glibc)
924 enum
927 _IOFBF = 0,
929 _IOLBF = 1,
931 _IONBF = 2,
935 extern shared FILE* stdin;
937 extern shared FILE* stdout;
939 extern shared FILE* stderr;
941 else version (Darwin)
943 enum
946 _IOFBF = 0,
948 _IOLBF = 1,
950 _IONBF = 2,
953 private extern shared FILE* __stdinp;
954 private extern shared FILE* __stdoutp;
955 private extern shared FILE* __stderrp;
958 alias __stdinp stdin;
960 alias __stdoutp stdout;
962 alias __stderrp stderr;
964 else version (FreeBSD)
966 enum
969 _IOFBF = 0,
971 _IOLBF = 1,
973 _IONBF = 2,
976 private extern shared FILE* __stdinp;
977 private extern shared FILE* __stdoutp;
978 private extern shared FILE* __stderrp;
981 alias __stdinp stdin;
983 alias __stdoutp stdout;
985 alias __stderrp stderr;
987 else version (NetBSD)
989 enum
992 _IOFBF = 0,
994 _IOLBF = 1,
996 _IONBF = 2,
999 private extern shared FILE[3] __sF;
1000 @property auto __stdin()() { return &__sF[0]; }
1001 @property auto __stdout()() { return &__sF[1]; }
1002 @property auto __stderr()() { return &__sF[2]; }
1004 alias __stdin stdin;
1006 alias __stdout stdout;
1008 alias __stderr stderr;
1010 else version (OpenBSD)
1012 enum
1015 _IOFBF = 0,
1017 _IOLBF = 1,
1019 _IONBF = 2,
1022 private extern shared FILE[3] __sF;
1023 @property auto __stdin()() { return &__sF[0]; }
1024 @property auto __stdout()() { return &__sF[1]; }
1025 @property auto __stderr()() { return &__sF[2]; }
1027 alias __stdin stdin;
1029 alias __stdout stdout;
1031 alias __stderr stderr;
1033 else version (DragonFlyBSD)
1035 enum
1037 _IOFBF = 0,
1038 _IOLBF = 1,
1039 _IONBF = 2,
1042 private extern shared FILE* __stdinp;
1043 private extern shared FILE* __stdoutp;
1044 private extern shared FILE* __stderrp;
1046 alias __stdinp stdin;
1047 alias __stdoutp stdout;
1048 alias __stderrp stderr;
1050 else version (Solaris)
1052 enum
1055 _IOFBF = 0x00,
1057 _IOLBF = 0x40,
1059 _IONBF = 0x04,
1061 _IOEOF = 0x20,
1063 _IOERR = 0x40,
1065 _IOREAD = 0x01,
1067 _IOWRT = 0x02,
1069 _IORW = 0x80,
1071 _IOMYBUF = 0x08,
1074 private extern shared FILE[_NFILE] __iob;
1077 @property auto stdin()() { return &__iob[0]; }
1079 @property auto stdout()() { return &__iob[1]; }
1081 @property auto stderr()() { return &__iob[2]; }
1083 else version (CRuntime_Bionic)
1085 enum
1088 _IOFBF = 0,
1090 _IOLBF = 1,
1092 _IONBF = 2,
1095 private extern shared FILE[3] __sF;
1098 @property auto stdin()() { return &__sF[0]; }
1100 @property auto stdout()() { return &__sF[1]; }
1102 @property auto stderr()() { return &__sF[2]; }
1104 else version (CRuntime_Musl)
1106 // needs tail const
1107 extern shared FILE* stdin;
1109 extern shared FILE* stdout;
1111 extern shared FILE* stderr;
1112 enum
1115 _IOFBF = 0,
1117 _IOLBF = 1,
1119 _IONBF = 2,
1122 else version (CRuntime_Newlib)
1124 enum
1127 _IOFBF = 0,
1129 _IOLBF = 1,
1131 _IONBF = 2,
1134 private
1136 shared struct _reent
1138 int _errno;
1139 __sFILE* _stdin;
1140 __sFILE* _stdout;
1141 __sFILE* _stderr;
1143 _reent* __getreent();
1146 pragma(inline, true)
1149 @property auto stdin()() { return __getreent()._stdin; }
1151 @property auto stdout()() { return __getreent()._stdout; }
1153 @property auto stderr()() { return __getreent()._stderr; }
1156 else version (CRuntime_UClibc)
1158 enum
1161 _IOFBF = 0,
1163 _IOLBF = 1,
1165 _IONBF = 2,
1169 extern shared FILE* stdin;
1171 extern shared FILE* stdout;
1173 extern shared FILE* stderr;
1175 else version (WASI)
1177 // needs tail const
1178 extern shared FILE* stdin;
1180 extern shared FILE* stdout;
1182 extern shared FILE* stderr;
1183 enum
1186 _IOFBF = 0,
1188 _IOLBF = 1,
1190 _IONBF = 2,
1193 else
1195 static assert( false, "Unsupported platform" );
1199 int remove(scope const char* filename);
1201 int rename(scope const char* from, scope const char* to);
1204 @trusted FILE* tmpfile(); // No unsafe pointer manipulation.
1206 char* tmpnam(char* s);
1209 int fclose(FILE* stream);
1211 // No unsafe pointer manipulation.
1212 @trusted
1215 int fflush(FILE* stream);
1219 FILE* fopen(scope const char* filename, scope const char* mode);
1221 FILE* freopen(scope const char* filename, scope const char* mode, FILE* stream);
1224 void setbuf(FILE* stream, char* buf);
1226 int setvbuf(FILE* stream, char* buf, int mode, size_t size);
1228 version (MinGW)
1230 // Prefer the MinGW versions over the MSVC ones, as the latter don't handle
1231 // reals at all.
1233 pragma(printf)
1234 int __mingw_fprintf(FILE* stream, scope const char* format, scope const ...);
1236 alias __mingw_fprintf fprintf;
1239 pragma(scanf)
1240 int __mingw_fscanf(FILE* stream, scope const char* format, scope ...);
1242 alias __mingw_fscanf fscanf;
1245 pragma(printf)
1246 int __mingw_sprintf(scope char* s, scope const char* format, scope const ...);
1248 alias __mingw_sprintf sprintf;
1251 pragma(scanf)
1252 int __mingw_sscanf(scope const char* s, scope const char* format, scope ...);
1254 alias __mingw_sscanf sscanf;
1257 pragma(printf)
1258 int __mingw_vfprintf(FILE* stream, scope const char* format, va_list arg);
1260 alias __mingw_vfprintf vfprintf;
1263 pragma(scanf)
1264 int __mingw_vfscanf(FILE* stream, scope const char* format, va_list arg);
1266 alias __mingw_vfscanf vfscanf;
1269 pragma(printf)
1270 int __mingw_vsprintf(scope char* s, scope const char* format, va_list arg);
1272 alias __mingw_vsprintf vsprintf;
1275 pragma(scanf)
1276 int __mingw_vsscanf(scope const char* s, scope const char* format, va_list arg);
1278 alias __mingw_vsscanf vsscanf;
1281 pragma(printf)
1282 int __mingw_vprintf(scope const char* format, va_list arg);
1284 alias __mingw_vprintf vprintf;
1287 pragma(scanf)
1288 int __mingw_vscanf(scope const char* format, va_list arg);
1290 alias __mingw_vscanf vscanf;
1293 pragma(printf)
1294 int __mingw_printf(scope const char* format, scope const ...);
1296 alias __mingw_printf printf;
1299 pragma(scanf)
1300 int __mingw_scanf(scope const char* format, scope ...);
1302 alias __mingw_scanf scanf;
1304 else version (CRuntime_Glibc)
1307 pragma(printf)
1308 int fprintf(FILE* stream, scope const char* format, scope const ...);
1310 pragma(scanf)
1311 int __isoc99_fscanf(FILE* stream, scope const char* format, scope ...);
1313 alias fscanf = __isoc99_fscanf;
1315 pragma(printf)
1316 int sprintf(scope char* s, scope const char* format, scope const ...);
1318 pragma(scanf)
1319 int __isoc99_sscanf(scope const char* s, scope const char* format, scope ...);
1321 alias sscanf = __isoc99_sscanf;
1323 pragma(printf)
1324 int vfprintf(FILE* stream, scope const char* format, va_list arg);
1326 pragma(scanf)
1327 int __isoc99_vfscanf(FILE* stream, scope const char* format, va_list arg);
1329 alias vfscanf = __isoc99_vfscanf;
1331 pragma(printf)
1332 int vsprintf(scope char* s, scope const char* format, va_list arg);
1334 pragma(scanf)
1335 int __isoc99_vsscanf(scope const char* s, scope const char* format, va_list arg);
1337 alias vsscanf = __isoc99_vsscanf;
1339 pragma(printf)
1340 int vprintf(scope const char* format, va_list arg);
1342 pragma(scanf)
1343 int __isoc99_vscanf(scope const char* format, va_list arg);
1345 alias vscanf = __isoc99_vscanf;
1347 pragma(printf)
1348 int printf(scope const char* format, scope const ...);
1350 pragma(scanf)
1351 int __isoc99_scanf(scope const char* format, scope ...);
1353 alias scanf = __isoc99_scanf;
1355 else
1358 pragma(printf)
1359 int fprintf(FILE* stream, scope const char* format, scope const ...);
1361 pragma(scanf)
1362 int fscanf(FILE* stream, scope const char* format, scope ...);
1364 pragma(printf)
1365 int sprintf(scope char* s, scope const char* format, scope const ...);
1367 pragma(scanf)
1368 int sscanf(scope const char* s, scope const char* format, scope ...);
1370 pragma(printf)
1371 int vfprintf(FILE* stream, scope const char* format, va_list arg);
1373 pragma(scanf)
1374 int vfscanf(FILE* stream, scope const char* format, va_list arg);
1376 pragma(printf)
1377 int vsprintf(scope char* s, scope const char* format, va_list arg);
1379 pragma(scanf)
1380 int vsscanf(scope const char* s, scope const char* format, va_list arg);
1382 pragma(printf)
1383 int vprintf(scope const char* format, va_list arg);
1385 pragma(scanf)
1386 int vscanf(scope const char* format, va_list arg);
1388 pragma(printf)
1389 int printf(scope const char* format, scope const ...);
1391 pragma(scanf)
1392 int scanf(scope const char* format, scope ...);
1395 // No unsafe pointer manipulation.
1396 @trusted
1399 int fgetc(FILE* stream);
1401 int fputc(int c, FILE* stream);
1405 char* fgets(char* s, int n, FILE* stream);
1407 int fputs(scope const char* s, FILE* stream);
1409 char* gets(char* s);
1411 int puts(scope const char* s);
1413 // No unsafe pointer manipulation.
1414 extern (D) @trusted
1417 int getchar()() { return getc(stdin); }
1419 int putchar()(int c) { return putc(c,stdout); }
1423 alias getc = fgetc;
1425 alias putc = fputc;
1428 @trusted int ungetc(int c, FILE* stream); // No unsafe pointer manipulation.
1431 size_t fread(scope void* ptr, size_t size, size_t nmemb, FILE* stream);
1433 size_t fwrite(scope const void* ptr, size_t size, size_t nmemb, FILE* stream);
1435 // No unsafe pointer manipulation.
1436 @trusted
1439 int fgetpos(FILE* stream, scope fpos_t * pos);
1441 int fsetpos(FILE* stream, scope const fpos_t* pos);
1444 int fseek(FILE* stream, c_long offset, int whence);
1446 c_long ftell(FILE* stream);
1449 version (CRuntime_Microsoft)
1451 // No unsafe pointer manipulation.
1452 @trusted
1455 void rewind(FILE* stream);
1457 pure void clearerr(FILE* stream);
1459 pure int feof(FILE* stream);
1461 pure int ferror(FILE* stream);
1463 pure int fileno(FILE* stream);
1466 version (MinGW)
1468 pragma(printf)
1469 int __mingw_snprintf(scope char* s, size_t n, scope const char* fmt, scope const ...);
1471 alias __mingw_snprintf _snprintf;
1473 alias __mingw_snprintf snprintf;
1476 pragma(printf)
1477 int __mingw_vsnprintf(scope char* s, size_t n, scope const char* format, va_list arg);
1479 alias __mingw_vsnprintf _vsnprintf;
1481 alias __mingw_vsnprintf vsnprintf;
1483 else
1486 pragma(printf)
1487 int _snprintf(scope char* s, size_t n, scope const char* format, scope const ...);
1489 pragma(printf)
1490 int snprintf(scope char* s, size_t n, scope const char* format, scope const ...);
1493 pragma(printf)
1494 int _vsnprintf(scope char* s, size_t n, scope const char* format, va_list arg);
1496 pragma(printf)
1497 int vsnprintf(scope char* s, size_t n, scope const char* format, va_list arg);
1501 // Microsoft under-the-hood C I/O functions. Uses _iobuf* for the unshared
1502 // version of FILE*, usable when the FILE is locked.
1504 import core.stdc.stddef : wchar_t;
1505 import core.stdc.wchar_ : wint_t;
1508 int _fputc_nolock(int c, _iobuf* fp);
1510 int _fgetc_nolock(_iobuf* fp);
1512 wint_t _fputwc_nolock(wchar_t c, _iobuf* fp);
1514 wint_t _fgetwc_nolock(_iobuf* fp);
1516 void _lock_file(FILE* fp);
1518 void _unlock_file(FILE* fp);
1520 int _setmode(int fd, int mode);
1522 int _fseeki64(FILE* stream, long offset, int origin);
1524 long _ftelli64(FILE* stream);
1526 intptr_t _get_osfhandle(int fd);
1528 int _open_osfhandle(intptr_t osfhandle, int flags);
1530 else version (CRuntime_Glibc)
1532 // No unsafe pointer manipulation.
1533 @trusted
1536 void rewind(FILE* stream);
1538 pure void clearerr(FILE* stream);
1540 pure int feof(FILE* stream);
1542 pure int ferror(FILE* stream);
1544 int fileno(FILE *);
1548 pragma(printf)
1549 int snprintf(scope char* s, size_t n, scope const char* format, scope const ...);
1551 pragma(printf)
1552 int vsnprintf(scope char* s, size_t n, scope const char* format, va_list arg);
1555 // Gnu under-the-hood C I/O functions. Uses _iobuf* for the unshared
1556 // version of FILE*, usable when the FILE is locked.
1557 // See http://gnu.org/software/libc/manual/html_node/I_002fO-on-Streams.html
1559 import core.stdc.wchar_ : wint_t;
1560 import core.stdc.stddef : wchar_t;
1563 int fputc_unlocked(int c, _iobuf* stream);
1565 int fgetc_unlocked(_iobuf* stream);
1567 wint_t fputwc_unlocked(wchar_t wc, _iobuf* stream);
1569 wint_t fgetwc_unlocked(_iobuf* stream);
1571 else version (Darwin)
1573 // No unsafe pointer manipulation.
1574 @trusted
1577 void rewind(FILE*);
1579 pure void clearerr(FILE*);
1581 pure int feof(FILE*);
1583 pure int ferror(FILE*);
1585 int fileno(FILE*);
1589 pragma(printf)
1590 int snprintf(scope char* s, size_t n, scope const char* format, scope const ...);
1592 pragma(printf)
1593 int vsnprintf(scope char* s, size_t n, scope const char* format, va_list arg);
1595 else version (FreeBSD)
1597 // No unsafe pointer manipulation.
1598 @trusted
1601 void rewind(FILE*);
1603 pure void clearerr(FILE*);
1605 pure int feof(FILE*);
1607 pure int ferror(FILE*);
1609 int fileno(FILE*);
1613 pragma(printf)
1614 int snprintf(scope char* s, size_t n, scope const char* format, scope const ...);
1616 pragma(printf)
1617 int vsnprintf(scope char* s, size_t n, scope const char* format, va_list arg);
1619 else version (NetBSD)
1621 // No unsafe pointer manipulation.
1622 @trusted
1625 void rewind(FILE*);
1627 pure void clearerr(FILE*);
1629 pure int feof(FILE*);
1631 pure int ferror(FILE*);
1633 int fileno(FILE*);
1637 pragma(printf)
1638 int snprintf(char* s, size_t n, const scope char* format, scope const ...);
1640 pragma(printf)
1641 int vsnprintf(char* s, size_t n, const scope char* format, va_list arg);
1643 else version (OpenBSD)
1645 // No unsafe pointer manipulation.
1646 @trusted
1649 void rewind(FILE*);
1651 @trusted private
1654 pragma(mangle, "clearerr")
1655 pure void __clearerr(FILE*);
1657 pragma(mangle, "feof")
1658 pure int __feof(FILE*);
1660 pragma(mangle, "ferror")
1661 pure int __ferror(FILE*);
1663 pragma(mangle, "fileno")
1664 int __fileno(FILE*);
1667 enum __SLBF = 0x0001;
1668 enum __SNBF = 0x0002;
1669 enum __SRD = 0x0004;
1670 enum __SWR = 0x0008;
1671 enum __SRW = 0x0010;
1672 enum __SEOF = 0x0020;
1673 enum __SERR = 0x0040;
1674 enum __SMBF = 0x0080;
1675 enum __SAPP = 0x0100;
1676 enum __SSTR = 0x0200;
1677 enum __SOPT = 0x0400;
1678 enum __SNPT = 0x0800;
1679 enum __SOFF = 0x1000;
1680 enum __SMOD = 0x2000;
1681 enum __SALC = 0x4000;
1682 enum __SIGN = 0x8000;
1684 extern immutable __gshared int __isthreaded;
1686 extern (D) @trusted
1688 void __sclearerr()(FILE* p)
1690 p._flags = p._flags & ~(__SERR|__SEOF);
1693 int __sfeof()(FILE* p)
1695 return (p._flags & __SEOF) != 0;
1698 int __sferror()(FILE* p)
1700 return (p._flags & __SERR) != 0;
1703 int __sfileno()(FILE* p)
1705 return p._file;
1708 pure void clearerr()(FILE* file)
1710 !__isthreaded ? __sclearerr(file) : __clearerr(file);
1713 pure int feof()(FILE* file)
1715 return !__isthreaded ? __sfeof(file) : __feof(file);
1718 pure int ferror()(FILE* file)
1720 return !__isthreaded ? __sferror(file) : __ferror(file);
1723 int fileno()(FILE* file)
1725 return !__isthreaded ? __sfileno(file) : __fileno(file);
1730 pragma(printf)
1731 int snprintf(scope char* s, size_t n, scope const char* format, scope const ...);
1733 pragma(printf)
1734 int vsnprintf(scope char* s, size_t n, scope const char* format, va_list arg);
1736 else version (DragonFlyBSD)
1738 // No unsafe pointer manipulation.
1739 @trusted
1741 void rewind(FILE*);
1742 pure void clearerr(FILE*);
1743 pure int feof(FILE*);
1744 pure int ferror(FILE*);
1745 int fileno(FILE*);
1747 enum __SLBF = 0x0001;
1748 enum __SNBF = 0x0002;
1749 enum __SRD = 0x0004;
1750 enum __SWR = 0x0008;
1751 enum __SRW = 0x0010;
1752 enum __SEOF = 0x0020;
1753 enum __SERR = 0x0040;
1754 enum __SMBF = 0x0080;
1755 enum __SAPP = 0x0100;
1756 enum __SSTR = 0x0200;
1757 enum __SOPT = 0x0400;
1758 enum __SNPT = 0x0800;
1759 enum __SOFF = 0x1000;
1760 enum __SMOD = 0x2000;
1761 enum __SALC = 0x4000;
1762 enum __SIGN = 0x8000;
1764 pragma(printf)
1765 int snprintf(scope char* s, size_t n, scope const char* format, scope const ...);
1766 pragma(printf)
1767 int vsnprintf(scope char* s, size_t n, scope const char* format, va_list arg);
1769 else version (Solaris)
1771 // No unsafe pointer manipulation.
1772 @trusted
1775 void rewind(FILE*);
1777 pure void clearerr(FILE*);
1779 pure int feof(FILE*);
1781 pure int ferror(FILE*);
1783 int fileno(FILE*);
1787 pragma(printf)
1788 int snprintf(scope char* s, size_t n, scope const char* format, scope const ...);
1790 pragma(printf)
1791 int vsnprintf(scope char* s, size_t n, scope const char* format, va_list arg);
1793 else version (CRuntime_Bionic)
1795 // No unsafe pointer manipulation.
1796 @trusted
1799 void rewind(FILE*);
1801 pure void clearerr(FILE*);
1803 pure int feof(FILE*);
1805 pure int ferror(FILE*);
1807 int fileno(FILE*);
1811 pragma(printf)
1812 int snprintf(scope char* s, size_t n, scope const char* format, scope const ...);
1814 pragma(printf)
1815 int vsnprintf(scope char* s, size_t n, scope const char* format, va_list arg);
1817 else version (CRuntime_Musl)
1819 @trusted
1822 void rewind(FILE* stream);
1824 pure void clearerr(FILE* stream);
1826 pure int feof(FILE* stream);
1828 pure int ferror(FILE* stream);
1830 int fileno(FILE *);
1834 pragma(printf)
1835 int snprintf(scope char* s, size_t n, scope const char* format, scope const ...);
1837 pragma(printf)
1838 int vsnprintf(scope char* s, size_t n, scope const char* format, va_list arg);
1840 else version (CRuntime_Newlib)
1842 // No unsafe pointer manipulation.
1843 @trusted
1846 void rewind(FILE* stream);
1848 pure void clearerr(FILE* stream);
1850 pure int feof(FILE* stream);
1852 pure int ferror(FILE* stream);
1854 int fileno(FILE *);
1858 pragma(printf)
1859 int snprintf(scope char* s, size_t n, scope const char* format, scope const ...);
1861 pragma(printf)
1862 int vsnprintf(scope char* s, size_t n, scope const char* format, va_list arg);
1865 // Gnu under-the-hood C I/O functions. Uses _iobuf* for the unshared
1866 // version of FILE*, usable when the FILE is locked.
1867 // See http://gnu.org/software/libc/manual/html_node/I_002fO-on-Streams.html
1869 import core.stdc.wchar_ : wint_t;
1870 import core.stdc.stddef : wchar_t;
1873 int fputc_unlocked(int c, _iobuf* stream);
1875 int fgetc_unlocked(_iobuf* stream);
1877 wint_t fputwc_unlocked(wchar_t wc, _iobuf* stream);
1879 wint_t fgetwc_unlocked(_iobuf* stream);
1881 else version (CRuntime_UClibc)
1883 // No unsafe pointer manipulation.
1884 @trusted
1887 void rewind(FILE* stream);
1889 pure void clearerr(FILE* stream);
1891 pure int feof(FILE* stream);
1893 pure int ferror(FILE* stream);
1895 int fileno(FILE *);
1899 pragma(printf)
1900 int snprintf(scope char* s, size_t n, scope const char* format, scope const ...);
1902 pragma(printf)
1903 int vsnprintf(scope char* s, size_t n, scope const char* format, va_list arg);
1905 else version (WASI)
1907 // No unsafe pointer manipulation.
1908 @trusted
1911 void rewind(FILE* stream);
1913 pure void clearerr(FILE* stream);
1915 pure int feof(FILE* stream);
1917 pure int ferror(FILE* stream);
1919 int fileno(FILE *);
1923 int snprintf(scope char* s, size_t n, scope const char* format, ...);
1925 int vsnprintf(scope char* s, size_t n, scope const char* format, va_list arg);
1927 else
1929 static assert( false, "Unsupported platform" );
1933 void perror(scope const char* s);
1935 version (CRuntime_Microsoft)
1937 int _open(scope const char* filename, int oflag, ...); ///
1938 int _wopen(scope const wchar* filename, int oflag, ...); ///
1939 int _sopen(scope const char* filename, int oflag, int shflag, ...); ///
1940 int _wsopen(scope const wchar* filename, int oflag, int shflag, ...); ///
1941 int _close(int fd); ///
1942 FILE *_fdopen(int fd, scope const(char)* flags); ///
1943 FILE *_wfdopen(int fd, scope const(wchar)* flags); ///
1946 version (Windows)
1948 // file open flags
1949 enum
1951 _O_RDONLY = 0x0000, ///
1952 O_RDONLY = _O_RDONLY, ///
1953 _O_WRONLY = 0x0001, ///
1954 O_WRONLY = _O_WRONLY, ///
1955 _O_RDWR = 0x0002, ///
1956 O_RDWR = _O_RDWR, ///
1957 _O_APPEND = 0x0008, ///
1958 O_APPEND = _O_APPEND, ///
1959 _O_CREAT = 0x0100, ///
1960 O_CREAT = _O_CREAT, ///
1961 _O_TRUNC = 0x0200, ///
1962 O_TRUNC = _O_TRUNC, ///
1963 _O_EXCL = 0x0400, ///
1964 O_EXCL = _O_EXCL, ///
1965 _O_TEXT = 0x4000, ///
1966 O_TEXT = _O_TEXT, ///
1967 _O_BINARY = 0x8000, ///
1968 O_BINARY = _O_BINARY, ///
1969 _O_WTEXT = 0x10000, ///
1970 _O_U16TEXT = 0x20000, ///
1971 _O_U8TEXT = 0x40000, ///
1972 _O_ACCMODE = (_O_RDONLY|_O_WRONLY|_O_RDWR), ///
1973 O_ACCMODE = _O_ACCMODE, ///
1974 _O_RAW = _O_BINARY, ///
1975 O_RAW = _O_BINARY, ///
1976 _O_NOINHERIT = 0x0080, ///
1977 O_NOINHERIT = _O_NOINHERIT, ///
1978 _O_TEMPORARY = 0x0040, ///
1979 O_TEMPORARY = _O_TEMPORARY, ///
1980 _O_SHORT_LIVED = 0x1000, ///
1981 _O_SEQUENTIAL = 0x0020, ///
1982 O_SEQUENTIAL = _O_SEQUENTIAL, ///
1983 _O_RANDOM = 0x0010, ///
1984 O_RANDOM = _O_RANDOM, ///
1987 enum
1989 _S_IREAD = 0x0100, /// read permission, owner
1990 S_IREAD = _S_IREAD, /// read permission, owner
1991 _S_IWRITE = 0x0080, /// write permission, owner
1992 S_IWRITE = _S_IWRITE, /// write permission, owner
1995 enum
1997 _SH_DENYRW = 0x10, /// deny read/write mode
1998 SH_DENYRW = _SH_DENYRW, /// deny read/write mode
1999 _SH_DENYWR = 0x20, /// deny write mode
2000 SH_DENYWR = _SH_DENYWR, /// deny write mode
2001 _SH_DENYRD = 0x30, /// deny read mode
2002 SH_DENYRD = _SH_DENYRD, /// deny read mode
2003 _SH_DENYNO = 0x40, /// deny none mode
2004 SH_DENYNO = _SH_DENYNO, /// deny none mode