1 .\" Copyright (c) 1990, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\" must display the following acknowledgement:
14 .\" This product includes software developed by the University of
15 .\" California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" @(#)stdio.3 8.7 (Berkeley) 4/19/94
33 .\" $FreeBSD: src/lib/libc/stdio/stdio.3,v 1.10.2.8 2003/02/19 05:12:44 gshapiro Exp $
34 .\" $DragonFly: src/lib/libc/stdio/stdio.3,v 1.3 2006/02/17 19:35:06 swildner Exp $
41 .Nd standard input/output library functions
52 library provides a simple and efficient buffered stream
55 Input and output is mapped into logical data streams
58 characteristics are concealed.
59 The functions and macros are listed
60 below; more information is available from the individual man pages.
62 A stream is associated with an external file (which may be a physical
65 a file, which may involve creating a new file.
67 existing file causes its former contents to be discarded.
68 If a file can support positioning requests (such as a disk file, as opposed
70 .Em file position indicator
71 associated with the stream is positioned at the start of the file (byte
72 zero), unless the file is opened with append mode.
74 is used, the position indicator will be placed at the end-of-file.
75 The position indicator is maintained by subsequent reads, writes
76 and positioning requests.
77 All input occurs as if the characters
78 were read by successive calls to the
80 function; all output takes place as if all characters were
81 written by successive calls to the
85 A file is disassociated from a stream by
88 Output streams are flushed (any unwritten buffer contents are transferred
89 to the host environment) before the stream is disassociated from the file.
90 The value of a pointer to a
92 object is indeterminate (garbage) after a file is closed.
94 A file may be subsequently reopened, by the same or another program
95 execution, and its contents reclaimed or modified (if it can be repositioned
96 at the start). If the main function returns to its original caller, or
99 function is called, all open files are closed (hence all output
100 streams are flushed) before program termination. Other methods
101 of program termination may not close files properly and hence
102 buffered output may be lost. In particular,
104 does not flush stdio files. Neither does an exit due to a signal.
105 Buffers are flushed by
107 as required by POSIX, although previous implementations did not.
109 This implementation makes no distinction between
114 In effect, all streams are binary.
115 No translation is performed and no extra padding appears on any stream.
117 At program startup, three streams are predefined and need not be
119 .Bl -bullet -compact -offset indent
122 (for reading conventional input),
125 (for writing conventional output), and
128 (for writing diagnostic output).
130 These streams are abbreviated
134 Initially, the standard error stream
135 is unbuffered; the standard input and output streams are
136 fully buffered if and only if the streams do not refer to
139 device, as determined by the
144 freshly-opened streams that refer to terminal devices
145 default to line buffering, and
146 pending output to such streams is written automatically
147 whenever such an input stream is read.
148 Note that this applies only to
150 if the read request can be satisfied by existing buffered data,
151 no automatic flush will occur.
153 or when a large amount of computation is done after printing
154 part of a line on an output terminal, it is necessary to
156 the standard output before going off and computing so that the output
158 Alternatively, these defaults may be modified via the
164 library is a part of the library
166 and routines are automatically loaded as needed by the C compiler.
169 sections of the following manual pages indicate which include files
170 are to be used, what the compiler declaration for the function
171 looks like and which external variables are of interest.
173 The following are defined as macros;
174 these names may not be re-used
175 without first removing their current definitions with
204 Function versions of the macro functions
214 exist and will be used if the macro
215 definitions are explicitly removed.
226 .Sh LIST OF FUNCTIONS
227 .Bl -column "Description"
228 .It Sy "Function Description"
229 .It "asprintf formatted output conversion"
230 .It "clearerr check and reset stream status"
231 .It "fclose close a stream"
232 .It "fdopen stream open functions"
233 .It "feof check and reset stream status"
234 .It "ferror check and reset stream status"
235 .It "fflush flush a stream"
236 .It "fgetc get next character or word from input stream"
237 .It "fgetln get a line from a stream"
238 .It "fgetpos reposition a stream"
239 .It "fgets get a line from a stream"
240 .It "fileno check and reset stream status"
241 .It "fopen stream open functions"
242 .It "fprintf formatted output conversion"
243 .It "fpurge flush a stream"
244 .It "fputc output a character or word to a stream"
245 .It "fputs output a line to a stream"
246 .It "fread binary stream input/output"
247 .It "freopen stream open functions"
248 .It "fropen open a stream"
249 .It "fscanf input format conversion"
250 .It "fseek reposition a stream"
251 .It "fsetpos reposition a stream"
252 .It "ftell reposition a stream"
253 .It "funopen open a stream"
254 .It "fwopen open a stream"
255 .It "fwrite binary stream input/output"
256 .It "getc get next character or word from input stream"
257 .It "getchar get next character or word from input stream"
258 .It "gets get a line from a stream"
259 .It "getw get next character or word from input stream"
260 .It "mkdtemp create unique temporary directory"
261 .It "mkstemp create unique temporary file"
262 .It "mktemp create unique temporary file"
263 .It "perror system error messages"
264 .It "printf formatted output conversion"
265 .It "putc output a character or word to a stream"
266 .It "putchar output a character or word to a stream"
267 .It "puts output a line to a stream"
268 .It "putw output a character or word to a stream"
269 .It "remove remove directory entry"
270 .It "rewind reposition a stream"
271 .It "scanf input format conversion"
272 .It "setbuf stream buffering operations"
273 .It "setbuffer stream buffering operations"
274 .It "setlinebuf stream buffering operations"
275 .It "setvbuf stream buffering operations"
276 .It "snprintf formatted output conversion"
277 .It "sprintf formatted output conversion"
278 .It "sscanf input format conversion"
279 .It "strerror system error messages"
280 .It "sys_errlist system error messages"
281 .It "sys_nerr system error messages"
282 .It "tempnam temporary file routines"
283 .It "tmpfile temporary file routines"
284 .It "tmpnam temporary file routines"
285 .It "ungetc un-get character from input stream"
286 .It "vasprintf formatted output conversion"
287 .It "vfprintf formatted output conversion"
288 .It "vfscanf input format conversion"
289 .It "vprintf formatted output conversion"
290 .It "vscanf input format conversion"
291 .It "vsnprintf formatted output conversion"
292 .It "vsprintf formatted output conversion"
293 .It "vsscanf input format conversion"
296 The standard buffered functions do not interact well with certain other
297 library and system functions, especially