1stdio(3) Library Functions Manual stdio(3)
2
3
4
6 stdio - standard input/output library functions
7
9 Standard C library (libc, -lc)
10
12 #include <stdio.h>
13
14 FILE *stdin;
15 FILE *stdout;
16 FILE *stderr;
17
19 The standard I/O library provides a simple and efficient buffered
20 stream I/O interface. Input and output is mapped into logical data
21 streams and the physical I/O characteristics are concealed. The func‐
22 tions and macros are listed below; more information is available from
23 the individual man pages.
24
25 A stream is associated with an external file (which may be a physical
26 device) by opening a file, which may involve creating a new file. Cre‐
27 ating an existing file causes its former contents to be discarded. If
28 a file can support positioning requests (such as a disk file, as op‐
29 posed to a terminal), then a file position indicator associated with
30 the stream is positioned at the start of the file (byte zero), unless
31 the file is opened with append mode. If append mode is used, it is un‐
32 specified whether the position indicator will be placed at the start or
33 the end of the file. The position indicator is maintained by subse‐
34 quent reads, writes, and positioning requests. All input occurs as if
35 the characters were read by successive calls to the fgetc(3) function;
36 all output takes place as if all characters were written by successive
37 calls to the fputc(3) function.
38
39 A file is disassociated from a stream by closing the file. Output
40 streams are flushed (any unwritten buffer contents are transferred to
41 the host environment) before the stream is disassociated from the file.
42 The value of a pointer to a FILE object is indeterminate after a file
43 is closed (garbage).
44
45 A file may be subsequently reopened, by the same or another program ex‐
46 ecution, and its contents reclaimed or modified (if it can be reposi‐
47 tioned at the start). If the main function returns to its original
48 caller, or the exit(3) function is called, all open files are closed
49 (hence all output streams are flushed) before program termination.
50 Other methods of program termination, such as abort(3) do not bother
51 about closing files properly.
52
53 At program startup, three text streams are predefined and need not be
54 opened explicitly: standard input (for reading conventional input),
55 standard output (for writing conventional output), and standard error
56 (for writing diagnostic output). These streams are abbreviated stdin,
57 stdout, and stderr. When opened, the standard error stream is not
58 fully buffered; the standard input and output streams are fully
59 buffered if and only if the streams do not refer to an interactive de‐
60 vice.
61
62 Output streams that refer to terminal devices are always line buffered
63 by default; pending