#include <stdio.h>

stdio.h

includes: _stdio.h, _bounds.h, sys/cdefs.h, Availability.h, _types.h, sys/_types/_va_list.h, sys/_types/_size_t.h, sys/_types/_null.h, sys/stdio.h, _printf.h, sys/_types/_seek_set.h, _ctermid.h, sys/_types/_off_t.h, sys/_types/_ssize_t.h, secure/_stdio.h, _stdio.h, _stdio.h, _stdio.h
80 functions · 26 macros · 5 variables · 2 typedefs · 2 structs

typedeffpos_t

typedef __darwin_off_t fpos_t

macro_FSTDIO

#define _FSTDIO 
Define for new stdio with functions.

struct__sbuf

stdio buffers
size 16, align 8
unsigned char *_base
int_size

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!
size 152, align 8
unsigned char *_pcurrent position in (some) buffer
int_rread space left for getc()
int_wwrite space left for putc()
short_flagsflags, below; this FILE is free if 0
short_filefileno, if Unix descriptor, else -1
struct __sbuf_bfthe buffer (at least 1 byte, if !NULL)
int_lbfsize0 or -_bf._size, for inline putc
void *_cookieoperations 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_ubseparate buffer for long sequences of ungetc() ungetc buffer
struct __sFILEX *_extraadditions to FILE to not break ABI
int_ursaved _r when _r is counting ungetc data
unsigned char[3]_ubuftricks to meet minimum requirements even when malloc() fails guarantee an ungetc() buffer
unsigned char[1]_nbufguarantee a getc() buffer
struct __sbuf_lbseparate buffer for fgetln() when line crosses buffer boundary buffer for fgetln()
int_blksizeUnix stdio files get aligned to block boundaries on fseek() stat.st_blksize (may be != _bf._size)
fpos_t_offsetcurrent lseek offset (see WARNING)

typedefFILE

typedef struct __sFILE FILE;

variable__stdinp

extern FILE *__stdinp

variable__stdoutp

extern FILE *__stdoutp

variable__stderrp

extern FILE *__stderrp

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

macro_IOLBF

#define _IOLBF 1
setvbuf should set line buffered

macro_IONBF

#define _IONBF 2
setvbuf should set unbuffered

macroBUFSIZ

#define BUFSIZ 1024
size of buffer used by setbuf

macroEOF

#define EOF (-1)

macroFOPEN_MAX

must be == _POSIX_STREAM_MAX <limits.h>
#define FOPEN_MAX 20
must be <= OPEN_MAX <sys/syslimits.h>

macroFILENAME_MAX

#define FILENAME_MAX 1024
must be <= PATH_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/"

macroL_tmpnam

#define L_tmpnam 1024
XXX must be == PATH_MAX

macroTMP_MAX

#define TMP_MAX 308915776

macrostdin

#define stdin __stdinp

macrostdout

#define stdout __stdoutp

macrostderr

#define stderr __stderrp

functionclearerr

void clearerr(FILE *)
man page · January 28, 2009
clearerr(3) — check and reset stream status

functionfclose

int fclose(FILE *)
man page · April 22, 2006
fclose(3) — close a stream

functionfeof

int feof(FILE *)
man page · January 28, 2009
feof(3) — check and reset stream status

functionferror

int ferror(FILE *)
man page · January 28, 2009
ferror(3) — check and reset stream status

functionfflush

int fflush(FILE *)
man page · August 1, 2019
fflush(3) — flush a stream

functionfgetc

int fgetc(FILE *)
man page · January 10, 2003
fgetc(3) — get next character or word from input stream

functionfgetpos

int fgetpos(FILE * __restrict, fpos_t *)
man page · March 19, 2004
fgetpos(3) — reposition a stream

functionfgets

char *_LIBC_CSTR fgets(char * __restrict _LIBC_COUNT(__size), int __size, FILE *)
man page · June 4, 1993
fgets(3) — get a line from a stream

functionfopen

FILE *fopen(const char * __restrict __filename, const char * __restrict __mode)
man page · September 1, 2023
fopen(3) — stream open functions

functionfprintf

__printflike(2, 3)
int fprintf(FILE * __restrict, const char * __restrict, ...)

functionfputc

int fputc(int, FILE *)
man page · January 10, 2003
fputc(3) — output a character or word to a stream

functionfputs

__DARWIN_ALIAS(fputs)
int fputs(const char * __restrict, FILE * __restrict)
man page · June 4, 1993
fputs(3) — output a line to a stream

functionfread

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/output

functionfreopen

__DARWIN_ALIAS(freopen)
FILE *freopen(const char * __restrict, const char * __restrict, FILE * __restrict)
man page · September 1, 2023
freopen(3) — stream open functions

functionfscanf

__scanflike(2, 3)
int fscanf(FILE * __restrict, const char * __restrict, ...)
man page · January 4, 2003
fscanf(3) — input format conversion

functionfseek

int fseek(FILE *, long, int)
man page · March 19, 2004
fseek(3) — reposition a stream

functionfsetpos

int fsetpos(FILE *, const fpos_t *)
man page · March 19, 2004
fsetpos(3) — reposition a stream

functionftell

long ftell(FILE *)
man page · March 19, 2004
ftell(3) — reposition a stream

functionfwrite

__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/output

functiongetc

int getc(FILE *)
man page · January 10, 2003
getc(3) — get next character or word from input stream

functiongetchar

int getchar(void)
man page · January 10, 2003
getchar(3) — get next character or word from input stream

functiongets

__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 stream

functionperror

__cold
void perror(const char *)
man page · October 12, 2004
perror(3) — system error messages

functionputc

int putc(int, FILE *)
man page · January 10, 2003
putc(3) — output a character or word to a stream

functionputchar

int putchar(int)
man page · January 10, 2003
putchar(3) — output a character or word to a stream

functionputs

int puts(const char *)
man page · June 4, 1993
puts(3) — output a line to a stream

functionremove

int remove(const char *)
man page · June 4, 1993
remove(3) — remove directory entry

functionrename

int rename(const char *__old, const char *__new)
man page · June 3, 2021
rename(2) — change the name of a file

functionrewind

void rewind(FILE *)
man page · March 19, 2004
rewind(3) — reposition a stream

functionscanf

__scanflike(1, 2)
int scanf(const char * __restrict, ...)
man page · January 4, 2003
scanf(3) — input format conversion

functionsetbuf

void setbuf(FILE * __restrict, char * __restrict _LIBC_COUNT_OR_NULL(BUFSIZ))
man page · June 4, 1993
setbuf(3) — stream buffering operations

functionsetvbuf

int setvbuf(
	FILE * __restrict,
	char * __restrict _LIBC_COUNT_OR_NULL(__size),
	int,
	size_t __size
)
man page · June 4, 1993
setvbuf(3) — stream buffering operations

functionsprintf

__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 conversion

functiontmpfile

FILE *tmpfile(void)
man page · November 12, 2008
tmpfile(3) — temporary file routines

functiontmpnam

__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 routines

functionungetc

int ungetc(int, FILE *)
man page · June 4, 1993
ungetc(3) — un-get character from input stream

functionvfprintf

__printflike(2, 0)
int vfprintf(FILE * __restrict, const char * __restrict, va_list)

functionvprintf

__printflike(1, 0)
int vprintf(const char * __restrict, va_list)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/printf.c
va_list form of the kernel printf. Formats the message and delivers it to the kernel log (os_log) and the console. Always returns 0.

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

macroL_ctermid

#define L_ctermid 1024
size for ctermid(); PATH_MAX

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 functions

functionfileno

int fileno(FILE *)
man page · January 28, 2009
fileno(3) — check and reset stream status

functionpclose

__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) — process

functionpopen

__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) — process

function__srget

int __srget(FILE *)

function__svfscanf

__scanflike(2, 0)
int __svfscanf(FILE *, const char *, va_list)

function__swbuf

int __swbuf(int, FILE *)

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 stream

functiongetchar_unlocked

int getchar_unlocked(void)
man page · January 10, 2003
getchar_unlocked(3) — get next character or word from input stream

functionputc_unlocked

int putc_unlocked(int, FILE *)
man page · January 10, 2003
putc_unlocked(3) — output a character or word to a stream

functionputchar_unlocked

int putchar_unlocked(int)
man page · January 10, 2003
putchar_unlocked(3) — output a character or word to a stream

functiongetw

int getw(FILE *)
Removed in Issue 6
man page · January 10, 2003
getw(3) — get next character or word from input stream

functionputw

int putw(int, FILE *)
man page · January 10, 2003
putw(3) — output a character or word to a stream

functiontempnam

__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 routines

macrogetc_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 stream

functionftello

off_t ftello(FILE * __stream)
man page · March 19, 2004
ftello(3) — reposition a stream

functionsnprintf

__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 conversion

functionvscanf

__scanflike(1, 0)
int vscanf(const char * __restrict __format, va_list)
man page · January 4, 2003
vscanf(3) — input format conversion

functionvsnprintf

__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 conversion

functiondprintf

__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 stream

functiongetline

__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 stream

functionfmemopen

__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 functions

functionopen_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 functions

variablesys_nerr

extern __const int sys_nerr
perror(3) external variables

variablesys_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 pathname

functionfgetln

char *_LIBC_COUNT(*__len) fgetln(FILE *, size_t *__len)
man page · April 19, 1994
fgetln(3) — get a line from a stream

functionfmtcheck

__attribute__((format_arg(2)))
__const char *fmtcheck(const char *, const char *)
man page · October 16, 2002
fmtcheck(3) — sanitizes user-supplied

functionfpurge

int fpurge(FILE *)
man page · August 1, 2019
fpurge(3) — flush a stream

functionsetbuffer

void setbuffer(FILE *, char *_LIBC_COUNT_OR_NULL(__size), int __size)
man page · June 4, 1993
setbuffer(3) — stream buffering operations

functionsetlinebuf

int setlinebuf(FILE *)
man page · June 4, 1993
setlinebuf(3) — stream buffering operations

functionvasprintf

__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 stream

macrofropen

#define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)

macrofwopen

#define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)

macrofeof_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)