stdio(3)

๐ŸŒธ stdio โ€” standard input/output library functions ๐ŸŒธ

okay bestie, strap in, because this is THE page for <stdio.h> โ€” the header that runs basically every C program you've ever loved. ๐Ÿ’– This is stdio from the Library Functions Manual, and it's your whole tour of buffered stream I/O. No cap.

๐Ÿ“š LIBRARY

Standard C library (libc, -lc) ๐Ÿซถ

โœจ SYNOPSIS โœจ

#include <stdio.h>

extern FILE  *stdin;
extern FILE  *stdout;
extern FILE  *stderr;

๐Ÿ’… DESCRIPTION ๐Ÿ’…

So the standard I/O library? It gives you a simple and efficient buffered stream I/O interface. Input and output get mapped into logical data streams, and all the messy physical I/O characteristics are, like, concealed. The functions and macros are listed below, and if you want more tea on any one of them, go read its own individual man page. ๐Ÿ“

A stream gets associated with an external file (which, yes, can absolutely be a physical device) by opening a file โ€” and that might involve creating a new file. Heads up: creating a file that already exists causes its former contents to be discarded. Gone. Poof. ๐Ÿ˜ญ

If a file can support positioning requests (think a disk file, as opposed to a terminal), then a file position indicator tied to the stream gets positioned at the start of the file (byte zero) โ€” unless the file is opened in append mode. And if append mode is used, it is unspecified whether the position indicator lands at the start or the end of the file. ๐Ÿ™ˆ The position indicator is then maintained by subsequent reads, writes, and positioning requests. All input happens as if the characters were read by successive calls to fgetc(3); all output happens as if all characters were written by successive calls to fputc(3). Iconic consistency, honestly.

A file gets disassociated from a stream by closing the file. Output streams are flushed (meaning any unwritten buffer contents get transferred to the host environment) before the stream is disassociated from the file. Also, the value of a pointer to a FILE object is indeterminate after a file is closed โ€” that's just garbage, bestie. Not me trusting a dangling FILE *. ๐Ÿ’€

A file may be subsequently reopened, by the same or another program execution, and its contents reclaimed or modified (if it can be repositioned at the start). If the main function returns to its original caller, or the exit(3) function is called, all open files get closed (hence all output streams get flushed) before program termination. But other methods of program termination, like abort(3), do not bother about closing files properly. Rude of them, honestly.

At program startup, three text streams are predefined and need not be opened explicitly:

  • standard input โ€” for reading conventional input
  • standard output โ€” for writing conventional output
  • standard error โ€” for writing diagnostic output

These streams get abbreviated as stdin, stdout, and stderr. When opened, the standard error stream is not fully buffered; the standard input and output streams are fully buffered if and only if the streams do not refer to an interactive device. Vibe check passed.

Output streams that refer to terminal devices are always line buffered by default, and pending output to such streams gets written automatically whenever an input stream that refers to a terminal device is read. So if you're doing a large amount of computation after printing part of a line on an output terminal, you need to fflush(3) the standard output before going off and computing โ€” otherwise your output just sits there and doesn't show up. Ask me how I know. ๐Ÿ˜ญ

The stdio library is a part of the library libc and routines are automatically loaded as needed by cc(1). The SYNOPSIS sections of the following manual pages indicate which include files to use, what the compiler declaration for the function looks like, and which external variables are of interest. iykyk. ๐Ÿ‘‘

Okay and this part matters: the following are defined as macros, and these names may not be reused without first removing their current definitions with #undef:

BUFSIZ, EOF, FILENAME_MAX, FOPEN_MAX, L_cuserid, L_ctermid, L_tmpnam, NULL, SEEK_END, SEEK_SET, SEEK_CUR, TMP_MAX, clearerr, feof, ferror, fileno, getc, getchar, putc, putchar, stderr, stdin, stdout.

Function versions of the macro functions feof, ferror, clearerr, fileno, getc, getchar, putc, and putchar exist, and they will be used if the macros definitions are explicitly removed. Slay. โœจ

๐Ÿฆ‹ List of functions ๐Ÿฆ‹

Every single one, no skips, because I would never do that to you:


โญ STANDARDS โญ

C11, POSIX.1-2008.

๐ŸŒˆ HISTORY ๐ŸŒˆ

C89, POSIX.1-2001.

๐Ÿ‘‘ SEE ALSO ๐Ÿ‘‘

close(2), open(2), read(2), write(2), stdout(3), unlocked_stdio(3)


okay that's the whole page bestie, you ate that ๐Ÿ’… this is Linux man-pages 6.20, dated 2025-09-21, and it's the stdio(3) page โ€” now go write some buffered I/O and flush your streams, ily ๐Ÿซถ๐Ÿ’–โœจ

๐Ÿ“ฆ where this page comes from
  • 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 6.20
  • ๐Ÿ“œ the page's license: BSD-4-Clause-UC
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms