stdio.h(0P)
β¨ PROLOG β¨
okay bestie, before anything else β this page is part of the POSIX Programmer's Manual, and here's the lil disclaimer: the Linux implementation of this interface may differ (so like, go check the corresponding Linux manual page for the deets on Linux behavior), or the interface might not be implemented on Linux at all. π not every platform is gonna have your back on this one.
π NAME π
stdio.h β standard buffered input/output
that's it, that's the vibe. it's the header that runs your whole file-reading, file-writing, printing-to-terminal lifestyle. main character energy fr fr.
πΈ SYNOPSIS πΈ
#include <stdio.h>
just that one line. iconic. π
π¦ DESCRIPTION π¦
so here's the tea: some of the functionality described on this reference page actually extends the ISO C standard. if you want those extra symbols to be visible in this header, your application has to define the appropriate feature test macro β go read the System Interfaces volume of POSIX.1β2017, Section 2.2, The Compilation Environment for the whole story. π₯
π§ the data types (defined through typedef)
FILEβ a structure containing information about a file. it's literally the whole personality of your stream.fpos_tβ a non-array type containing all information needed to specify uniquely every position within a file. yes, every position, uniquely. she's thorough.off_tβ as described in<sys/types.h>.size_tβ as described in<stddef.h>.ssize_tβ as described in<sys/types.h>.va_listβ as described in<stdarg.h>.
π the macros that expand to integer constant expressions
BUFSIZβ size of<stdio.h>buffers. this shall expand to a positive value. (positive! she's not gonna be weird about it.)L_ctermidβ maximum size of character array to holdctermid()output.L_tmpnamβ maximum size of character array to holdtmpnam()output.
π the macros that expand to integer constant expressions with distinct values
_IOFBFβ input/output fully buffered._IOLBFβ input/output line buffered._IONBFβ input/output unbuffered.
β and ALSO these macros that expand to integer constant expressions with distinct values
SEEK_CURβ seek relative to current position.SEEK_ENDβ seek relative to end-of-file.SEEK_SETβ seek relative to start-of-file.
(yes bestie, there are two separate groups of distinct-valued constant-expression macros, and they are NOT the same group. keep up π )
π the macros that expand to integer constant expressions denoting implementation limits
{FILENAME_MAX}β maximum size in bytes of the longest pathname that the implementation guarantees can be opened.{FOPEN_MAX}β number of streams which the implementation guarantees can be open simultaneously. the value is at least eight.{TMP_MAX}β minimum number of unique filenames generated bytmpnam(). also: maximum number of times an application can calltmpnam()reliably. the value of{TMP_MAX}is at least 25.
on XSI-conformant systems, the value of {TMP_MAX} is at least 10000. π the XSI girlies are eating good.
π the negative-value macro
EOFβ end-of-file return value. this one shall expand to an integer constant expression with typeintand a negative value. so when you see a negative number, it's not a bug, it's justEOFsaying hi.
π«Ά and also
the <stdio.h> header shall define NULL as described in <stddef.h>. β¨
π§΅ the string-constant macro
P_tmpdirβ default directory prefix fortempnam().
π the standard stream macros
these shall expand to expressions of type "pointer to FILE" that point to the FILE objects associated, respectively, with the standard error, input, and output streams:
stderrβ standard error output stream.stdinβ standard input stream.stdoutβ standard output stream.
the trio. the holy trinity. the ones you've been typing since day one. π
π the functions
the following shall be declared as functions and may also be defined as macros. function prototypes shall be provided.
void clearerr(FILE *);
char *ctermid(char *);
int dprintf(int, const char *restrict, ...)
int fclose(FILE *);
FILE *fdopen(int, const char *);
int feof(FILE *);
int ferror(FILE *);
int fflush(FILE *);
int fgetc(FILE *);
int fgetpos(FILE *restrict, fpos_t *restrict);
char *fgets(char *restrict, int, FILE *restrict);
int fileno(FILE *);
void flockfile(FILE *);
FILE *fmemopen(void *restrict, size_t, const char *restrict);
FILE *fopen(const char *restrict, const char *restrict);
int fprintf(FILE *restrict, const char *restrict, ...);
int fputc(int, FILE *);
int fputs(const char *restrict, FILE *restrict);
size_t fread(void *restrict, size_t, size_t, FILE *restrict);
FILE *freopen(const char *restrict, const char *restrict,
FILE *restrict);
int fscanf(FILE *restrict, const char *restrict, ...);
int fseek(FILE *, long, int);
int fseeko(FILE *, off_t, int);
int fsetpos(FILE *, const fpos_t *);
long ftell(FILE *);
off_t ftello(FILE *);
int ftrylockfile(FILE *);
void funlockfile(FILE *);
size_t fwrite(const void *restrict, size_t, size_t, FILE *restrict);
int getc(FILE *);
int getchar(void);
int getc_unlocked(FILE *);
int getchar_unlocked(void);
ssize_t getdelim(char **restrict, size_t *restrict, int,
FILE *restrict);
ssize_t getline(char **restrict, size_t *restrict, FILE *restrict);
char *gets(char *);
FILE *open_memstream(char **, size_t *);
int pclose(FILE *);
void perror(const char *);
FILE *popen(const char *, const char *);
int printf(const char *restrict, ...);
int putc(int, FILE *);
int putchar(int);
int putc_unlocked(int, FILE *);
int putchar_unlocked(int);
int puts(const char *);
int remove(const char *);
int rename(const char *, const char *);
int renameat(int, const char *, int, const char *);
void rewind(FILE *);
int scanf(const char *restrict, ...);
void setbuf(FILE *restrict, char *restrict);
int setvbuf(FILE *restrict, char *restrict, int, size_t);
int snprintf(char *restrict, size_t, const char *restrict, ...);
int sprintf(char *restrict, const char *restrict, ...);
int sscanf(const char *restrict, const char *restrict, ...);
char *tempnam(const char *, const char *);
FILE *tmpfile(void);
char *tmpnam(char *);
int ungetc(int, FILE *);
int vdprintf(int, const char *restrict, va_list);
int vfprintf(FILE *restrict, const char *restrict, va_list);
int vfscanf(FILE *restrict, const char *restrict, va_list);
int vprintf(const char *restrict, va_list);
int vscanf(const char *restrict, va_list);
int vsnprintf(char *restrict, size_t, const char *restrict,
va_list);
int vsprintf(char *restrict, const char *restrict, va_list);
int vsscanf(const char *restrict, const char *restrict, va_list);
also? inclusion of the <stdio.h> header may also make visible all symbols from <stddef.h>. surprise bonus content. π
the following sections are informative.
π APPLICATION USAGE π
real talk, this one's important: since standard I/O streams may use an underlying file descriptor to access the file associated with a stream, application developers need to be aware that {FOPEN_MAX} streams may not be available if file descriptors are being used to access files that are not associated with streams. so likeβ¦ the guarantee has an asterisk, bestie. plan accordingly. π«Ά
π₯ RATIONALE π₯
there's a whole conflict between the ISO C standard and the POSIX definition of the {TMP_MAX} macro, and it's addressed by ISO/IEC 9899:1999 standard, Defect Report 336. the POSIX standard is in alignment with the public record of the response to the Defect Report. this change has not yet been published as part of the ISO C standard. so yeah β drama in the standards committee. periodt. π
π FUTURE DIRECTIONS π
None. she said what she said, and what she said was nothing. π
π SEE ALSO π
<stdarg.h><stddef.h><sys_types.h>
and also, from the System Interfaces volume of POSIX.1β2017, Section 2.2, The Compilation Environment: clearerr(), ctermid(), fclose(), fdopen(), feof(), ferror(), fflush(), fgetc(), fgetpos(), fgets(), fileno(), flockfile(), fmemopen(), fopen(), fprintf(), fputc(), fputs(), fread(), freopen(), fscanf(), fseek(), fsetpos(), ftell(), fwrite(), getc(), getchar(), getc_unlocked(), getdelim(), getopt(), gets(), open_memstream(), pclose(), perror(), popen(), putc(), putchar(), puts(), remove(), rename(), rewind(), setbuf(), setvbuf(), stdin, system(), tempnam(), tmpfile(), tmpnam(), ungetc(), vfprintf(), vfscanf()
go read all of them. or like, at least the ones you actually need. i'm not your mom. π§
π COPYRIGHT π
portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. π
in the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. the original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. to report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page, bestie β brought to you by IEEE/The Open Group, 2017, stdio.h(0P) β¨ go forth and fopen() responsibly π«Άπ
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms