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.24 2003/02/23 01:47:47 ru Exp $
40 .Nd standard input/output library functions
51 library provides a simple and efficient buffered stream
54 Input and output is mapped into logical data streams
57 characteristics are concealed.
58 The functions and macros are listed
59 below; more information is available from the individual man pages.
61 A stream is associated with an external file (which may be a physical
64 a file, which may involve creating a new file.
66 existing file causes its former contents to be discarded.
67 If a file can support positioning requests (such as a disk file, as opposed
69 .Em file position indicator
70 associated with the stream is positioned at the start of the file (byte
71 zero), unless the file is opened with append mode.
73 is used, the position indicator will be placed at the end-of-file.
74 The position indicator is maintained by subsequent reads, writes
75 and positioning requests.
76 All input occurs as if the characters
77 were read by successive calls to the
79 function; all output takes place as if all characters were
80 written by successive calls to the
84 A file is disassociated from a stream by
87 Output streams are flushed (any unwritten buffer contents are transferred
88 to the host environment) before the stream is disassociated from the file.
89 The value of a pointer to a
91 object is indeterminate (garbage) after a file is closed.
93 A file may be subsequently reopened, by the same or another program
94 execution, and its contents reclaimed or modified (if it can be repositioned
95 at the start). If the main function returns to its original caller, or
98 function is called, all open files are closed (hence all output
99 streams are flushed) before program termination. Other methods
100 of program termination may not close files properly and hence
101 buffered output may be lost. In particular,
103 does not flush stdio files. Neither does an exit due to a signal.
104 Buffers are flushed by
106 as required by POSIX, although previous implementations did not.
108 This implementation makes no distinction between
113 In effect, all streams are binary.
114 No translation is performed and no extra padding appears on any stream.
116 At program startup, three streams are predefined and need not be
118 .Bl -bullet -compact -offset indent
121 (for reading conventional input),
124 (for writing conventional output), and
127 (for writing diagnostic output).
129 These streams are abbreviated
133 Initially, the standard error stream
134 is unbuffered; the standard input and output streams are
135 fully buffered if and only if the streams do not refer to
138 device, as determined by the
143 freshly-opened streams that refer to terminal devices
144 default to line buffering, and
145 pending output to such streams is written automatically
146 whenever such an input stream is read.
147 Note that this applies only to
149 if the read request can be satisfied by existing buffered data,
150 no automatic flush will occur.
152 or when a large amount of computation is done after printing
153 part of a line on an output terminal, it is necessary to
155 the standard output before going off and computing so that the output
157 Alternatively, these defaults may be modified via the
163 library is a part of the library
165 and routines are automatically loaded as needed by the C compiler.
168 sections of the following manual pages indicate which include files
169 are to be used, what the compiler declaration for the function
170 looks like and which external variables are of interest.
172 The following are defined as macros;
173 these names may not be re-used
174 without first removing their current definitions with
189 .Dv clearerr_unlocked ,
191 .Dv ferror_unlocked ,
192 .Dv fileno_unlocked ,
196 .Dv getchar_unlocked ,
198 .Dv putchar_unlocked ,
203 Function versions of the macro functions
204 .Dv clearerr_unlocked ,
206 .Dv ferror_unlocked ,
207 .Dv fileno_unlocked ,
209 .Dv getchar_unlocked ,
213 exist and will be used if the macro
214 definitions are explicitly removed.
221 The standard buffered functions do not interact well with certain other
222 library and system functions, especially
229 .Sh LIST OF FUNCTIONS
230 .Bl -column "Description"
231 .It Sy "Function Description"
232 .It "asprintf formatted output conversion"
233 .It "clearerr check and reset stream status"
234 .It "fclose close a stream"
235 .It "fdopen stream open functions"
236 .It "feof check and reset stream status"
237 .It "ferror check and reset stream status"
238 .It "fflush flush a stream"
239 .It "fgetc get next character or word from input stream"
240 .It "fgetln get a line from a stream"
241 .It "fgetpos reposition a stream"
242 .It "fgets get a line from a stream"
243 .It "fgetwc get next wide character from input stream"
244 .It "fgetws get a line of wide characters from a stream"
245 .It "fileno check and reset stream status"
246 .It "fopen stream open functions"
247 .It "fprintf formatted output conversion"
248 .It "fpurge flush a stream"
249 .It "fputc output a character or word to a stream"
250 .It "fputs output a line to a stream"
251 .It "fputwc output a wide character to a stream"
252 .It "fputws output a line of wide characters to a stream"
253 .It "fread binary stream input/output"
254 .It "freopen stream open functions"
255 .It "fropen open a stream"
256 .It "fscanf input format conversion"
257 .It "fseek reposition a stream"
258 .It "fsetpos reposition a stream"
259 .It "ftell reposition a stream"
260 .It "funopen open a stream"
261 .It "fwide set/get orientation of stream"
262 .It "fwopen open a stream"
263 .It "fwprintf formatted wide character output conversion"
264 .It "fwrite binary stream input/output"
265 .It "getc get next character or word from input stream"
266 .It "getchar get next character or word from input stream"
267 .It "gets get a line from a stream"
268 .It "getw get next character or word from input stream"
269 .It "getwc get next wide character from input stream"
270 .It "getwchar get next wide character from input stream"
271 .It "mkdtemp create unique temporary directory"
272 .It "mkstemp create unique temporary file"
273 .It "mktemp create unique temporary file"
274 .It "perror system error messages"
275 .It "printf formatted output conversion"
276 .It "putc output a character or word to a stream"
277 .It "putchar output a character or word to a stream"
278 .It "puts output a line to a stream"
279 .It "putw output a character or word to a stream"
280 .It "putwc output a wide character to a stream"
281 .It "putwchar output a wide character to a stream"
282 .It "remove remove directory entry"
283 .It "rewind reposition a stream"
284 .It "scanf input format conversion"
285 .It "setbuf stream buffering operations"
286 .It "setbuffer stream buffering operations"
287 .It "setlinebuf stream buffering operations"
288 .It "setvbuf stream buffering operations"
289 .It "snprintf formatted output conversion"
290 .It "sprintf formatted output conversion"
291 .It "sscanf input format conversion"
292 .It "strerror system error messages"
293 .It "swprintf formatted wide character output conversion"
294 .It "sys_errlist system error messages"
295 .It "sys_nerr system error messages"
296 .It "tempnam temporary file routines"
297 .It "tmpfile temporary file routines"
298 .It "tmpnam temporary file routines"
299 .It "ungetc un-get character from input stream"
300 .It "ungetwc un-get wide character from input stream"
301 .It "vasprintf formatted output conversion"
302 .It "vfprintf formatted output conversion"
303 .It "vfscanf input format conversion"
304 .It "vfwprintf formatted wide character output conversion"
305 .It "vprintf formatted output conversion"
306 .It "vscanf input format conversion"
307 .It "vsnprintf formatted output conversion"
308 .It "vsprintf formatted output conversion"
309 .It "vsscanf input format conversion"
310 .It "vswprintf formatted wide character output conversion"
311 .It "vwprintf formatted wide character output conversion"
312 .It "wprintf formatted wide character output conversion"