#include <stdio.h>
stdio.h
typedeffpos_t
typedef __darwin_off_t fpos_t
struct__sFILE
stdio state variables.
The following always hold:
if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),
_lbfsize is -_bf._size, else _lbfsize is 0
if _flags&__SRD, _w is 0
if _flags&__SWR, _r is 0
This ensures that the getc and putc macros (or inline functions) never
try to write or read from a file that is in `read' or `write' mode.
(Moreover, they can, and do, automatically switch from read mode to
write mode, and back, on "r+" and "w+" files.)
_lbfsize is used only to make the inline line-buffered output stream
code as compact as possible.
_ub, _up, and _ur are used when ungetc() pushes back more characters
than fit in the current _bf, or when ungetc() pushes back a character
that does not match the previous one in _bf. When this happens,
_ub._base becomes non-nil (i.e., a stream has ungetc() data iff
_ub._base!=NULL) and _up and _ur save the current values of _p and _r.
NB: see WARNING above before changing the layout of this structure!
| unsigned char * | _p | current position in (some) buffer |
| int | _r | read space left for getc() |
| int | _w | write space left for putc() |
| short | _flags | flags, below; this FILE is free if 0 |
| short | _file | fileno, if Unix descriptor, else -1 |
| struct __sbuf | _bf | the buffer (at least 1 byte, if !NULL) |
| int | _lbfsize | 0 or -_bf._size, for inline putc |
| void * | _cookie | operations cookie passed to io functions |
| int (*)(void *) | _close | |
| int (*)(void *, char *, int) | _read | |
| fpos_t (*)(void *, fpos_t, int) | _seek | |
| int (*)(void *, const char *, int) | _write | |
| struct __sbuf | _ub | separate buffer for long sequences of ungetc() ungetc buffer |
| struct __sFILEX * | _extra | additions to FILE to not break ABI |
| int | _ur | saved _r when _r is counting ungetc data |
| unsigned char[3] | _ubuf | tricks to meet minimum requirements even when malloc() fails guarantee an ungetc() buffer |
| unsigned char[1] | _nbuf | guarantee a getc() buffer |
| struct __sbuf | _lb | separate buffer for fgetln() when line crosses buffer boundary buffer for fgetln() |
| int | _blksize | Unix stdio files get aligned to block boundaries on fseek() stat.st_blksize (may be != _bf._size) |
| fpos_t | _offset | current lseek offset (see WARNING) |
macro_IOFBF
The following three definitions are for ANSI C, which took them
from System V, which brilliantly took internal interface macros and
made them official arguments to setvbuf(), without renaming them.
Hence, these ugly _IOxxx names are *supposed* to appear in user code.
Although numbered as their counterparts above, the implementation
does not rely on this.
#define _IOFBF 0
setvbuf should set fully buffered
macroEOF
#define EOF (-1)
macroFOPEN_MAX
must be == _POSIX_STREAM_MAX <limits.h>
#define FOPEN_MAX 20
must be <= OPEN_MAX <sys/syslimits.h>
macroP_tmpdir
System V/ANSI C; this is the wrong way to do this, do *not* use these.
#define P_tmpdir "/var/tmp/"
macroTMP_MAX
#define TMP_MAX 308915776
functionclearerr
void clearerr(FILE *)
man page · January 28, 2009
clearerr(3) — check and reset stream statusfunctionferror
int ferror(FILE *)
man page · January 28, 2009
ferror(3) — check and reset stream statusfunctionfgetc
int fgetc(FILE *)
man page · January 10, 2003
fgetc(3) — get next character or word from input streamfunctionfgetpos
int fgetpos(FILE * __restrict, fpos_t *)
man page · March 19, 2004
fgetpos(3) — reposition a streamfunctionfgets
char *_LIBC_CSTR fgets(char * __restrict _LIBC_COUNT(__size), int __size, FILE *)
man page · June 4, 1993
fgets(3) — get a line from a streamfunctionfopen
FILE *fopen(const char * __restrict __filename, const char * __restrict __mode)
man page · September 1, 2023
fopen(3) — stream open functionsfunctionfputc
int fputc(int, FILE *)
man page · January 10, 2003
fputc(3) — output a character or word to a streamfunctionfputs
__DARWIN_ALIAS(fputs) int fputs(const char * __restrict, FILE * __restrict)
man page · June 4, 1993
fputs(3) — output a line to a streamfunctionfread
size_t fread( void * __restrict _LIBC_SIZE(__size * __nitems) __ptr, size_t __size, size_t __nitems, FILE * __restrict __stream )
man page · March 8, 1994
fread(3) — binary stream input/outputfunctionfreopen
__DARWIN_ALIAS(freopen) FILE *freopen(const char * __restrict, const char * __restrict, FILE * __restrict)
man page · September 1, 2023
freopen(3) — stream open functionsfunctionfscanf
__scanflike(2, 3) int fscanf(FILE * __restrict, const char * __restrict, ...)
man page · January 4, 2003
fscanf(3) — input format conversionfunctionfsetpos
int fsetpos(FILE *, const fpos_t *)
man page · March 19, 2004
fsetpos(3) — reposition a streamfunctionfwrite
__DARWIN_ALIAS(fwrite) size_t fwrite( const void * __restrict _LIBC_SIZE(__size * __nitems) __ptr, size_t __size, size_t __nitems, FILE * __restrict __stream )
man page · March 8, 1994
fwrite(3) — binary stream input/outputfunctiongetc
int getc(FILE *)
man page · January 10, 2003
getc(3) — get next character or word from input streamfunctiongetchar
int getchar(void)
man page · January 10, 2003
getchar(3) — get next character or word from input streamfunctiongets
__deprecated_msg("This function is provided for compatibility reasons only. Due to security concerns inherent in the design of gets , it is highly recommended that you use fgets(3) instead.") char *_LIBC_CSTR gets(char *_LIBC_UNSAFE_INDEXABLE)
(3)deprecated
man page · June 4, 1993
gets(3) — get a line from a streamfunctionperror
__cold
void perror(const char *)man page · October 12, 2004
perror(3) — system error messagesfunctionputc
int putc(int, FILE *)
man page · January 10, 2003
putc(3) — output a character or word to a streamfunctionputchar
int putchar(int)
man page · January 10, 2003
putchar(3) — output a character or word to a streamfunctionrename
int rename(const char *__old, const char *__new)
man page · June 3, 2021
rename(2) — change the name of a filefunctionscanf
__scanflike(1, 2)
int scanf(const char * __restrict, ...)man page · January 4, 2003
scanf(3) — input format conversionfunctionsetbuf
void setbuf(FILE * __restrict, char * __restrict _LIBC_COUNT_OR_NULL(BUFSIZ))
man page · June 4, 1993
setbuf(3) — stream buffering operationsfunctionsetvbuf
int setvbuf( FILE * __restrict, char * __restrict _LIBC_COUNT_OR_NULL(__size), int, size_t __size )
man page · June 4, 1993
setvbuf(3) — stream buffering operationsfunctionsprintf
__swift_unavailable("Use snprintf instead.") , it is highly recommended that you use snprintf(3) instead.") int sprintf(char * __restrict _LIBC_UNSAFE_INDEXABLE, const char * __restrict, ...) __printflike(2, 3) _LIBC_PTRCHECK_REPLACED("snprintf") __deprecated_msg("This function is provided for compatibility reasons only. Due to security concerns inherent in the design of sprintf( 3 )
deprecated
functionsscanf
__scanflike(2, 3)
int sscanf(const char * __restrict, const char * __restrict, ...)man page · January 4, 2003
sscanf(3) — input format conversionfunctiontmpnam
__swift_unavailable("Use mkstemp(3) instead.") __deprecated_msg("This function is provided for compatibility reasons only. Due to security concerns inherent in the design of tmpnam , it is highly recommended that you use mkstemp(3) instead.") char *_LIBC_CSTR tmpnam(char *_LIBC_COUNT(L_tmpnam))
(3)deprecated
man page · November 12, 2008
tmpnam(3) — temporary file routinesfunctionungetc
int ungetc(int, FILE *)
man page · June 4, 1993
ungetc(3) — un-get character from input streamfunctionvfprintf
__printflike(2, 0) int vfprintf(FILE * __restrict, const char * __restrict, va_list)
functionvsprintf
__swift_unavailable("Use vsnprintf instead.") __printflike(2, 0) _LIBC_PTRCHECK_REPLACED("vsnprintf") __deprecated_msg("This function is provided for compatibility reasons only. Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use vsnprintf(3) instead.") int vsprintf( char * __restrict _LIBC_UNSAFE_INDEXABLE, const char * __restrict, va_list )
deprecated
macro_LIBC_COUNT__L_CTERMID
#define _LIBC_COUNT__L_CTERMID _LIBC_COUNT_OR_NULL(L_ctermid)
functionfdopen
FILE *fdopen(int, const char *)
man page · September 1, 2023
fdopen(3) — stream open functionsfunctionfileno
int fileno(FILE *)
man page · January 28, 2009
fileno(3) — check and reset stream statusfunctionpclose
__swift_unavailable("Use posix_spawn APIs or NSTask instead. (On iOS, process spawning is unavailable.)") int pclose(FILE *)
man page · May 3, 1995
pclose(3) — processfunctionpopen
__DARWIN_ALIAS_STARTING(__MAC_10_6, __IPHONE_2_0, __DARWIN_ALIAS(popen)) __swift_unavailable("Use posix_spawn APIs or NSTask instead. (On iOS, process spawning is unavailable.)") FILE *popen(const char *, const char *)
man page · May 3, 1995
popen(3) — processfunction__svfscanf
__scanflike(2, 0) int __svfscanf(FILE *, const char *, va_list)
function__sputc
__header_always_inline int __sputc(int _c, FILE *_p)
The __sfoo macros are here so that we can
define function versions in the C library.
functionflockfile
void flockfile(FILE *)
man page · January 10, 2003
flockfile(3) — "stdio locking functions"functionftrylockfile
int ftrylockfile(FILE *)
man page · January 10, 2003
ftrylockfile(3) — "stdio locking functions"functionfunlockfile
void funlockfile(FILE *)
man page · January 10, 2003
funlockfile(3) — "stdio locking functions"functiongetc_unlocked
int getc_unlocked(FILE *)
man page · January 10, 2003
getc_unlocked(3) — get next character or word from input streamfunctiongetchar_unlocked
int getchar_unlocked(void)
man page · January 10, 2003
getchar_unlocked(3) — get next character or word from input streamfunctionputc_unlocked
int putc_unlocked(int, FILE *)
man page · January 10, 2003
putc_unlocked(3) — output a character or word to a streamfunctionputchar_unlocked
int putchar_unlocked(int)
man page · January 10, 2003
putchar_unlocked(3) — output a character or word to a streamfunctiongetw
int getw(FILE *)
Removed in Issue 6
man page · January 10, 2003
getw(3) — get next character or word from input streamfunctionputw
int putw(int, FILE *)
man page · January 10, 2003
putw(3) — output a character or word to a streamfunctiontempnam
__swift_unavailable("Use mkstemp(3) instead.") __deprecated_msg("This function is provided for compatibility reasons only. Due to security concerns inherent in the design of tempnam , it is highly recommended that you use mkstemp(3) instead.") char *_LIBC_CSTR tempnam(const char *__dir, const char *__prefix) __DARWIN_ALIAS(tempnam)
(3)deprecated
man page · November 12, 2008
tempnam(3) — temporary file routinesmacrogetc_unlocked
#define getc_unlocked(fp) __sgetc(fp)
macroputc_unlocked
#define putc_unlocked(x, fp) __sputc(x, fp)
macrogetchar_unlocked
#define getchar_unlocked() getc_unlocked(stdin)
macroputchar_unlocked
#define putchar_unlocked(x) putc_unlocked(x, stdout)
functionfseeko
int fseeko(FILE * __stream, off_t __offset, int __whence)
man page · March 19, 2004
fseeko(3) — reposition a streamfunctionsnprintf
__printflike(3, 4) int snprintf( char * __restrict _LIBC_COUNT(__size) __str, size_t __size, const char * __restrict __format, ... )
functionvfscanf
__scanflike(2, 0) int vfscanf(FILE * __restrict __stream, const char * __restrict __format, va_list)
man page · January 4, 2003
vfscanf(3) — input format conversionfunctionvscanf
__scanflike(1, 0) int vscanf(const char * __restrict __format, va_list)
man page · January 4, 2003
vscanf(3) — input format conversionfunctionvsnprintf
__printflike(3, 0) int vsnprintf( char * __restrict _LIBC_COUNT(__size) __str, size_t __size, const char * __restrict __format, va_list )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu bsd/kern/subr_prf.c
Scaled-down kernel version of vsnprintf(3). Formats at most size - 1 characters into str and NUL-terminates when size is at least 1. Returns the length the fully formatted string would have had, even if it did not fit; use vscnprintf to obtain the number of bytes actually written.
functionvsscanf
__scanflike(2, 0) int vsscanf(const char * __restrict __str, const char * __restrict __format, va_list)
man page · January 4, 2003
vsscanf(3) — input format conversionfunctiondprintf
__printflike(2, 3) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3)
int dprintf(int, const char * __restrict, ...)functionvdprintf
__printflike(2, 0) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3) int vdprintf(int, const char * __restrict, va_list)
functiongetdelim
__OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3) ssize_t getdelim( char *_LIBC_COUNT(*__linecapp) *__restrict __linep, size_t * __restrict __linecapp, int __delimiter, FILE * __restrict __stream )
man page · November 30, 2010
getdelim(3) — get a line from a streamfunctiongetline
__OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3) ssize_t getline( char *_LIBC_COUNT(*__linecapp) *__restrict __linep, size_t * __restrict __linecapp, FILE * __restrict __stream )
man page · November 30, 2010
getline(3) — get a line from a streamfunctionfmemopen
__API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0)) FILE *fmemopen( void * __restrict __buf _LIBC_SIZE(__size), size_t __size, const char * __restrict __mode )
man page · September 1, 2023
fmemopen(3) — stream open functionsfunctionopen_memstream
__API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0)) FILE *open_memstream(char *_LIBC_COUNT(*__sizep) *__bufp, size_t *__sizep)
man page · August 1, 2015
open_memstream(3) — dynamic memory buffer stream open functionsvariablesys_errlist
extern __const char *__const sys_errlist[]
functionasprintf
__printflike(2, 3)
int asprintf(char *_LIBC_CSTR *__restrict, const char * __restrict, ...)functionctermid_r
char *_LIBC_CSTR ctermid_r(char *_LIBC_COUNT(L_ctermid))
man page · October 1, 2011
ctermid_r(3) — generate terminal pathnamefunctionfgetln
char *_LIBC_COUNT(*__len) fgetln(FILE *, size_t *__len)
man page · April 19, 1994
fgetln(3) — get a line from a streamfunctionfmtcheck
__attribute__((format_arg(2)))
__const char *fmtcheck(const char *, const char *)man page · October 16, 2002
fmtcheck(3) — sanitizes user-suppliedfunctionsetbuffer
void setbuffer(FILE *, char *_LIBC_COUNT_OR_NULL(__size), int __size)
man page · June 4, 1993
setbuffer(3) — stream buffering operationsfunctionsetlinebuf
int setlinebuf(FILE *)
man page · June 4, 1993
setlinebuf(3) — stream buffering operationsfunctionvasprintf
__printflike(2, 0) int vasprintf(char *_LIBC_CSTR *__restrict, const char * __restrict, va_list)
functionfunopen
FILE *funopen( const void *, int (* _Nullable)(void *, char *_LIBC_COUNT(__n), int __n), int (* _Nullable)(void *, const char *_LIBC_COUNT(__n), int __n), fpos_t (* _Nullable)(void *, fpos_t, int), int (* _Nullable)(void *) )
Stdio function-access interface.
man page · March 19, 2004
funopen(3) — open a streammacrofeof_unlocked
#define feof_unlocked(p) __sfeof(p)
macroferror_unlocked
#define ferror_unlocked(p) __sferror(p)
macroclearerr_unlocked
#define clearerr_unlocked(p) __sclearerr(p)
macrofileno_unlocked
#define fileno_unlocked(p) __sfileno(p)