1 .\" $NetBSD: stdio.3,v 1.21 2009/07/13 22:19:25 roy Exp $
3 .\" Copyright (c) 1990, 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)stdio.3 8.7 (Berkeley) 4/19/94
37 .Nd standard input/output library functions
48 library provides a simple and efficient buffered stream
51 Input and output is mapped into logical data streams
54 characteristics are concealed.
55 The functions and macros are listed below;
56 more information is available from the individual man pages.
58 A stream is associated with an external file (which may be a physical
61 a file, which may involve creating a new file.
62 Creating an existing file causes its former contents to be discarded.
63 If a file can support positioning requests (such as a disk file, as opposed
65 .Em file position indicator
66 associated with the stream is positioned at the start of the file (byte
67 zero), unless the file is opened with append mode.
69 is used, the position indicator will be placed the end-of-file.
70 The position indicator is maintained by subsequent reads, writes
71 and positioning requests.
72 All input occurs as if the characters
73 were read by successive calls to the
75 function; all output takes place as if all characters were
76 read by successive calls to the
80 A file is disassociated from a stream by
83 Output streams are flushed (any unwritten buffer contents are transferred
84 to the host environment) before the stream is disassociated from the file.
85 The value of a pointer to a
87 object is indeterminate after a file is closed (garbage).
89 A file may be subsequently reopened, by the same or another program
90 execution, and its contents reclaimed or modified (if it can be repositioned
92 If the main function returns to its original caller, or the
94 function is called, all open files are closed (hence all output
95 streams are flushed) before program termination.
96 Other methods of program termination, such as
98 do not bother about closing files properly.
100 This implementation needs and makes
101 no distinction between
106 In effect, all streams are binary.
107 No translation is performed and no extra padding appears on any stream.
109 At program startup, three streams are predefined and need not be
111 .Bl -bullet -compact -offset indent
114 (for reading conventional input),
117 (for writing conventional output), and
120 (for writing diagnostic output).
122 These streams are abbreviated
126 Initially, the standard error stream
127 is unbuffered; the standard input and output streams are
128 fully buffered if and only if the streams do not refer to
131 device, as determined by the
136 freshly-opened streams that refer to terminal devices
137 default to line buffering, and
138 pending output to such streams is written automatically
139 whenever an such an input stream is read.
140 Note that this applies only to
142 if the read request can be satisfied by existing buffered data,
143 no automatic flush will occur.
145 or when a large amount of computation is done after printing
146 part of a line on an output terminal, it is necessary to
148 the standard output before going off and computing so that the output
150 Alternatively, these defaults may be modified via the
156 library is a part of the library
158 and routines are automatically loaded as needed by compilers such
163 sections of the following manual pages indicate which include files
164 are to be used, what the compiler declaration for the function
165 looks like and which external variables are of interest.
167 In multi-threaded applications, operations on streams perform implicit
168 locking, except for the
170 .Fa getchar_unlocked ,
175 Explicit control of stream locking is available through the
182 The following are defined as macros; these names may not be re-used
183 without first removing their current definitions with
206 .Fn getchar_unlocked ,
210 .Fn putchar_unlocked ,
214 Function versions of the macro functions
222 .Fn getchar_unlocked ,
228 exist and will be used if the macros definitions are explicitly removed.
239 .Sh LIST OF FUNCTIONS
240 .Bl -column "putchar_unlocked" "Description"
241 .It Sy Function Description
242 .It clearerr check and reset stream status
243 .It fclose close a stream
244 .It fdopen stream open functions
245 .It feof check and reset stream status
246 .It ferror check and reset stream status
247 .It fflush flush a stream
248 .It fgetc get next character or word from input stream
249 .It fgetln get a line from a stream
250 .It fgetpos reposition a stream
251 .It fgets get a line from a stream
252 .It fgetwc get next wide character from input stream
253 .It fileno check and reset stream status
254 .It flockfile lock a stream
255 .It fopen stream open functions
256 .It fprintf formatted output conversion
257 .It fpurge flush a stream
258 .It fputc output a character or word to a stream
259 .It fputs output a line to a stream
260 .It fputwc output a wide character to a stream
261 .It fread binary stream input/output
262 .It freopen stream open functions
263 .It fropen open a stream
264 .It fscanf input format conversion
265 .It fseek reposition a stream
266 .It fsetpos reposition a stream
267 .It ftell reposition a stream
268 .It ftrylockfile lock a stream (non-blocking)
269 .It funlockfile unlock a stream
270 .It funopen open a stream
271 .It fwide set/get orientation of a stream
272 .It fwopen open a stream
273 .It fwrite binary stream input/output
274 .It getc get next character or word from input stream
275 .It getc_unlocked get next character or word from input stream
276 .It Ta (no implicit locking)
277 .It getchar get next character or word from input stream
278 .It getchar_unlocked get next character or word from input stream
279 .It Ta (no implicit locking)
280 .It getdelim get a delimited record from a stream
281 .It getline get a line from a stream
282 .It gets get a line from a stream
283 .It getw get next character or word from input stream
284 .It getwc get next wide character from input stream
285 .It getwchar get next wide character from input stream
286 .It mkstemp create unique temporary file
287 .It mktemp create unique temporary file
288 .It perror system error messages
289 .It printf formatted output conversion
290 .It putc output a character or word to a stream
291 .It putc_unlocked output a character or word to a stream
292 .It Ta (no implicit locking)
293 .It putchar output a character or word to a stream
294 .It putchar_unlocked output a character or word to a stream
295 .It Ta (no implicit locking)
296 .It puts output a line to a stream
297 .It putw output a character or word to a stream
298 .It putwc output a wide character to a stream
299 .It putwchar output a wide character to a stream
300 .It remove remove directory entry
301 .It rewind reposition a stream
302 .It scanf input format conversion
303 .It setbuf stream buffering operations
304 .It setbuffer stream buffering operations
305 .It setlinebuf stream buffering operations
306 .It setvbuf stream buffering operations
307 .It snprintf formatted output conversion
308 .It sprintf formatted output conversion
309 .It sscanf input format conversion
310 .It strerror system error messages
311 .It sys_errlist system error messages
312 .It sys_nerr system error messages
313 .It tempnam temporary file routines
314 .It tmpfile temporary file routines
315 .It tmpnam temporary file routines
316 .It ungetc un-get character from input stream
317 .It ungetwc un-get wide character from input stream
318 .It vfprintf formatted output conversion
319 .It vfscanf input format conversion
320 .It vprintf formatted output conversion
321 .It vscanf input format conversion
322 .It vsnprintf formatted output conversion
323 .It vsprintf formatted output conversion
324 .It vsscanf input format conversion
327 The standard buffered functions do not interact well with certain other
328 library and system functions, especially