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
;
24 else version (WatchOS
)
29 import core
.stdc
.config
;
30 import core
.stdc
.stdarg
; // for va_list
31 import core
.stdc
.stdint
: intptr_t
;
35 import core
.sys
.posix
.sys
.types
;
37 else version (OpenBSD
)
39 import core
.sys
.posix
.sys
.types
;
43 import core
.sys
.posix
.sys
.types
;
45 version (DragonFlyBSD
)
47 import core
.sys
.posix
.sys
.types
;
55 version (CRuntime_Microsoft
)
67 /// Actually int.max since Visual Studio 2015.
70 _SYS_OPEN
= 20, // non-standard
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
)
100 else version (CRuntime_Musl
)
118 else version (Darwin
)
150 else version (FreeBSD
)
174 else version (NetBSD
)
198 else version (OpenBSD
)
211 TMP_MAX
= 0x7fffffff,
222 else version (DragonFlyBSD
)
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
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
)
275 enum int _NFILE
= 60;
278 enum int _NFILE
= 20;
280 else version (CRuntime_Bionic
)
304 else version (CRuntime_Newlib
)
328 else version (CRuntime_UClibc
)
366 static assert( false, "Unsupported platform" );
371 /// Offset is relative to the beginning
373 /// Offset is relative to the current position
375 /// Offset is relative to the end
379 version (CRuntime_Microsoft
)
391 alias shared(_iobuf
) FILE
;
393 else version (CRuntime_Glibc
)
395 import core
.stdc
.wchar_
: mbstate_t
;
399 long __pos
; // couldn't use off_t because of static if issue
422 ptrdiff_t _old_offset
;
425 char[1] _shortbuf
= 0;
430 /*_IO_codecvt*/ void* _codecvt
;
431 /*_IO_wide_data*/ void* _wide_data
;
432 _IO_FILE
*_freeres_list
;
437 char[15 * int.sizeof
- 4 * (void*).sizeof
- size_t
.sizeof
] _unused2
;
441 alias _IO_FILE _iobuf
;
443 alias shared(_IO_FILE
) FILE
;
449 char[16] __opaque
= 0;
455 alias _IO_FILE _iobuf
; // needed for phobos
457 alias shared(_IO_FILE
) FILE
;
459 else version (CRuntime_Musl
)
463 char[16] __opaque
= 0;
469 alias _IO_FILE _iobuf
; // needed for phobos
471 alias shared(_IO_FILE
) FILE
;
473 else version (Darwin
)
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
;
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
;
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
;
550 pthread_mutex_t _fl_mutex
;
558 alias __sFILE _iobuf
;
560 alias shared(__sFILE
) FILE
;
562 else version (NetBSD
)
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
;
591 int function(void *) _flush
;
592 /* Formerly used by fgetln/fgetwln; kept for binary compatibility */
593 char[__sbuf
.sizeof
- _flush
.sizeof
] _lb_unused
= void;
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
;
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
;
642 alias __sFILE _iobuf
;
644 alias shared(__sFILE
) FILE
;
646 else version (DragonFlyBSD
)
650 /// See /usr/include/stdio.h
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
;
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 */
697 ushort __flags
; // __orientation:2
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
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
;
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
;
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
;
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
;
808 long __pos
; // couldn't use off_t because of static if issue
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
827 char[2] __ungot_width
= 0;
835 __STDIO_FILE_STRUCT
* __nextopen
;
837 _IO_cookie_io_functions_t __gcs
;
838 wchar_t
[2] __ungot
= 0;
842 pthread_mutex_t __lock
;
846 alias __STDIO_FILE_STRUCT _iobuf
;
848 alias shared(__STDIO_FILE_STRUCT
) FILE
;
852 static assert( false, "Unsupported platform" );
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
)
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
)
935 extern shared FILE
* stdin
;
937 extern shared FILE
* stdout
;
939 extern shared FILE
* stderr
;
941 else version (Darwin
)
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
)
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
)
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
)
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
)
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
)
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
)
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
)
1107 extern shared FILE
* stdin
;
1109 extern shared FILE
* stdout
;
1111 extern shared FILE
* stderr
;
1122 else version (CRuntime_Newlib
)
1136 shared struct _reent
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
)
1169 extern shared FILE
* stdin
;
1171 extern shared FILE
* stdout
;
1173 extern shared FILE
* stderr
;
1178 extern shared FILE
* stdin
;
1180 extern shared FILE
* stdout
;
1182 extern shared FILE
* stderr
;
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.
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
);
1230 // Prefer the MinGW versions over the MSVC ones, as the latter don't handle
1234 int __mingw_fprintf(FILE
* stream
, scope const char* format
, scope const ...);
1236 alias __mingw_fprintf fprintf
;
1240 int __mingw_fscanf(FILE
* stream
, scope const char* format
, scope ...);
1242 alias __mingw_fscanf fscanf
;
1246 int __mingw_sprintf(scope char* s
, scope const char* format
, scope const ...);
1248 alias __mingw_sprintf sprintf
;
1252 int __mingw_sscanf(scope const char* s
, scope const char* format
, scope ...);
1254 alias __mingw_sscanf sscanf
;
1258 int __mingw_vfprintf(FILE
* stream
, scope const char* format
, va_list arg
);
1260 alias __mingw_vfprintf vfprintf
;
1264 int __mingw_vfscanf(FILE
* stream
, scope const char* format
, va_list arg
);
1266 alias __mingw_vfscanf vfscanf
;
1270 int __mingw_vsprintf(scope char* s
, scope const char* format
, va_list arg
);
1272 alias __mingw_vsprintf vsprintf
;
1276 int __mingw_vsscanf(scope const char* s
, scope const char* format
, va_list arg
);
1278 alias __mingw_vsscanf vsscanf
;
1282 int __mingw_vprintf(scope const char* format
, va_list arg
);
1284 alias __mingw_vprintf vprintf
;
1288 int __mingw_vscanf(scope const char* format
, va_list arg
);
1290 alias __mingw_vscanf vscanf
;
1294 int __mingw_printf(scope const char* format
, scope const ...);
1296 alias __mingw_printf printf
;
1300 int __mingw_scanf(scope const char* format
, scope ...);
1302 alias __mingw_scanf scanf
;
1304 else version (CRuntime_Glibc
)
1308 int fprintf(FILE
* stream
, scope const char* format
, scope const ...);
1311 int __isoc99_fscanf(FILE
* stream
, scope const char* format
, scope ...);
1313 alias fscanf
= __isoc99_fscanf
;
1316 int sprintf(scope char* s
, scope const char* format
, scope const ...);
1319 int __isoc99_sscanf(scope const char* s
, scope const char* format
, scope ...);
1321 alias sscanf
= __isoc99_sscanf
;
1324 int vfprintf(FILE
* stream
, scope const char* format
, va_list arg
);
1327 int __isoc99_vfscanf(FILE
* stream
, scope const char* format
, va_list arg
);
1329 alias vfscanf
= __isoc99_vfscanf
;
1332 int vsprintf(scope char* s
, scope const char* format
, va_list arg
);
1335 int __isoc99_vsscanf(scope const char* s
, scope const char* format
, va_list arg
);
1337 alias vsscanf
= __isoc99_vsscanf
;
1340 int vprintf(scope const char* format
, va_list arg
);
1343 int __isoc99_vscanf(scope const char* format
, va_list arg
);
1345 alias vscanf
= __isoc99_vscanf
;
1348 int printf(scope const char* format
, scope const ...);
1351 int __isoc99_scanf(scope const char* format
, scope ...);
1353 alias scanf
= __isoc99_scanf
;
1359 int fprintf(FILE
* stream
, scope const char* format
, scope const ...);
1362 int fscanf(FILE
* stream
, scope const char* format
, scope ...);
1365 int sprintf(scope char* s
, scope const char* format
, scope const ...);
1368 int sscanf(scope const char* s
, scope const char* format
, scope ...);
1371 int vfprintf(FILE
* stream
, scope const char* format
, va_list arg
);
1374 int vfscanf(FILE
* stream
, scope const char* format
, va_list arg
);
1377 int vsprintf(scope char* s
, scope const char* format
, va_list arg
);
1380 int vsscanf(scope const char* s
, scope const char* format
, va_list arg
);
1383 int vprintf(scope const char* format
, va_list arg
);
1386 int vscanf(scope const char* format
, va_list arg
);
1389 int printf(scope const char* format
, scope const ...);
1392 int scanf(scope const char* format
, scope ...);
1395 // No unsafe pointer manipulation.
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.
1417 int getchar()() { return getc(stdin
); }
1419 int putchar()(int c
) { return putc(c
,stdout
); }
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.
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.
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
);
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
;
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
;
1487 int _snprintf(scope char* s
, size_t n
, scope const char* format
, scope const ...);
1490 int snprintf(scope char* s
, size_t n
, scope const char* format
, scope const ...);
1494 int _vsnprintf(scope char* s
, size_t n
, scope const char* format
, va_list arg
);
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.
1536 void rewind(FILE
* stream
);
1538 pure void clearerr(FILE
* stream
);
1540 pure int feof(FILE
* stream
);
1542 pure int ferror(FILE
* stream
);
1549 int snprintf(scope char* s
, size_t n
, scope const char* format
, scope const ...);
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.
1579 pure void clearerr(FILE
*);
1581 pure int feof(FILE
*);
1583 pure int ferror(FILE
*);
1590 int snprintf(scope char* s
, size_t n
, scope const char* format
, scope const ...);
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.
1603 pure void clearerr(FILE
*);
1605 pure int feof(FILE
*);
1607 pure int ferror(FILE
*);
1614 int snprintf(scope char* s
, size_t n
, scope const char* format
, scope const ...);
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.
1627 pure void clearerr(FILE
*);
1629 pure int feof(FILE
*);
1631 pure int ferror(FILE
*);
1638 int snprintf(char* s
, size_t n
, const scope char* format
, scope const ...);
1641 int vsnprintf(char* s
, size_t n
, const scope char* format
, va_list arg
);
1643 else version (OpenBSD
)
1645 // No unsafe pointer manipulation.
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
;
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
)
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
);
1731 int snprintf(scope char* s
, size_t n
, scope const char* format
, scope const ...);
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.
1742 pure void clearerr(FILE
*);
1743 pure int feof(FILE
*);
1744 pure int ferror(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;
1765 int snprintf(scope char* s
, size_t n
, scope const char* format
, scope const ...);
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.
1777 pure void clearerr(FILE
*);
1779 pure int feof(FILE
*);
1781 pure int ferror(FILE
*);
1788 int snprintf(scope char* s
, size_t n
, scope const char* format
, scope const ...);
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.
1801 pure void clearerr(FILE
*);
1803 pure int feof(FILE
*);
1805 pure int ferror(FILE
*);
1812 int snprintf(scope char* s
, size_t n
, scope const char* format
, scope const ...);
1815 int vsnprintf(scope char* s
, size_t n
, scope const char* format
, va_list arg
);
1817 else version (CRuntime_Musl
)
1822 void rewind(FILE
* stream
);
1824 pure void clearerr(FILE
* stream
);
1826 pure int feof(FILE
* stream
);
1828 pure int ferror(FILE
* stream
);
1835 int snprintf(scope char* s
, size_t n
, scope const char* format
, scope const ...);
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.
1846 void rewind(FILE
* stream
);
1848 pure void clearerr(FILE
* stream
);
1850 pure int feof(FILE
* stream
);
1852 pure int ferror(FILE
* stream
);
1859 int snprintf(scope char* s
, size_t n
, scope const char* format
, scope const ...);
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.
1887 void rewind(FILE
* stream
);
1889 pure void clearerr(FILE
* stream
);
1891 pure int feof(FILE
* stream
);
1893 pure int ferror(FILE
* stream
);
1900 int snprintf(scope char* s
, size_t n
, scope const char* format
, scope const ...);
1903 int vsnprintf(scope char* s
, size_t n
, scope const char* format
, va_list arg
);
1907 // No unsafe pointer manipulation.
1911 void rewind(FILE
* stream
);
1913 pure void clearerr(FILE
* stream
);
1915 pure int feof(FILE
* stream
);
1917 pure int ferror(FILE
* stream
);
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
);
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
); ///
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
, ///
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
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