]> git.saurik.com Git - apple/libc.git/blob - stdio/FreeBSD/stdio.3
Libc-763.12.tar.gz
[apple/libc.git] / stdio / FreeBSD / stdio.3
1 .\" Copyright (c) 1990, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
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 .\" 4. Neither the name of the University nor the names of its contributors
13 .\" may be used to endorse or promote products derived from this software
14 .\" without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\" @(#)stdio.3 8.7 (Berkeley) 4/19/94
29 .\" $FreeBSD: src/lib/libc/stdio/stdio.3,v 1.30 2009/03/04 03:38:51 das Exp $
30 .\"
31 .Dd March 3, 2009
32 .Dt STDIO 3
33 .Os
34 .Sh NAME
35 .Nm stdio
36 .Nd standard input/output library functions
37 .Sh LIBRARY
38 .Lb libc
39 .Sh SYNOPSIS
40 .In stdio.h
41 .Vt FILE *stdin ;
42 .Vt FILE *stdout ;
43 .Vt FILE *stderr ;
44 .Sh DESCRIPTION
45 The standard
46 .Tn I/O
47 library provides a simple and efficient buffered stream
48 .Tn I/O
49 interface.
50 Input and output is mapped into logical data streams
51 and the physical
52 .Tn I/O
53 characteristics are concealed.
54 The functions and macros are listed
55 below; more information is available from the individual man pages.
56 .Pp
57 A stream is associated with an external file (which may be a physical
58 device) by
59 .Em opening
60 a file, which may involve creating a new file.
61 Creating an
62 existing file causes its former contents to be discarded.
63 If a file can support positioning requests (such as a disk file, as opposed
64 to a terminal) then a
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.
68 If append mode
69 is used, the position indicator will be placed at 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
74 .Xr fgetc 3
75 function; all output takes place as if all characters were
76 written by successive calls to the
77 .Xr fputc 3
78 function.
79 .Pp
80 A file is disassociated from a stream by
81 .Em closing
82 the file.
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
86 .Dv FILE
87 object is indeterminate (garbage) after a file is closed.
88 .Pp
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
91 at the start).
92 If the main function returns to its original caller, or
93 the
94 .Xr exit 3
95 function is called, all open files are closed (hence all output
96 streams are flushed) before program termination.
97 Other methods
98 of program termination may not close files properly and hence
99 buffered output may be lost.
100 In particular,
101 .Xr _exit 2
102 does not flush stdio files.
103 Neither does an exit due to a signal.
104 Buffers are flushed by
105 .Xr abort 3
106 as required by POSIX, although previous implementations did not.
107 .Pp
108 This implementation makes no distinction between
109 .Dq text
110 and
111 .Dq binary
112 streams.
113 In effect, all streams are binary.
114 No translation is performed and no extra padding appears on any stream.
115 .Pp
116 At program startup, three streams are predefined and need not be
117 opened explicitly:
118 .Bl -bullet -compact -offset indent
119 .It
120 .Em standard input
121 (for reading conventional input),
122 .It
123 .Em standard output
124 (for writing conventional output), and
125 .It
126 .Em standard error
127 (for writing diagnostic output).
128 .El
129 These streams are abbreviated
130 .Dv stdin , stdout
131 and
132 .Dv stderr .
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
136 an interactive or
137 .Dq terminal
138 device, as determined by the
139 .Xr isatty 3
140 function.
141 In fact,
142 .Em all
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
148 .Dq "true reads" ;
149 if the read request can be satisfied by existing buffered data,
150 no automatic flush will occur.
151 In these cases,
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
154 .Xr fflush 3
155 the standard output before going off and computing so that the output
156 will appear.
157 Alternatively, these defaults may be modified via the
158 .Xr setvbuf 3
159 function.
160 .Pp
161 The
162 .Nm
163 library is a part of the library
164 .Nm libc
165 and routines are automatically loaded as needed by the C compiler.
166 The
167 .Tn SYNOPSIS
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.
171 .Pp
172 The following are defined as macros;
173 these names may not be re-used
174 without first removing their current definitions with
175 .Ic #undef :
176 .Dv BUFSIZ ,
177 .Dv EOF ,
178 .Dv FILENAME_MAX ,
179 .Dv FOPEN_MAX ,
180 .Dv L_ctermid ,
181 .Dv L_cuserid ,
182 .Dv L_tmpnam ,
183 .Dv NULL ,
184 .Dv P_tmpdir ,
185 .Dv SEEK_CUR ,
186 .Dv SEEK_END ,
187 .Dv SEEK_SET ,
188 .Dv TMP_MAX ,
189 .Dv clearerr ,
190 .Dv clearerr_unlocked ,
191 .Dv feof ,
192 .Dv feof_unlocked ,
193 .Dv ferror ,
194 .Dv ferror_unlocked ,
195 .Dv fileno ,
196 .Dv fileno_unlocked ,
197 .Dv fropen ,
198 .Dv fwopen ,
199 .Dv getc ,
200 .Dv getc_unlocked ,
201 .Dv getchar ,
202 .Dv getchar_unlocked ,
203 .Dv putc ,
204 .Dv putc_unlocked ,
205 .Dv putchar ,
206 .Dv putchar_unlocked ,
207 .Dv stderr ,
208 .Dv stdin
209 and
210 .Dv stdout .
211 Function versions of the macro functions
212 .Dv clearerr ,
213 .Dv clearerr_unlocked ,
214 .Dv feof ,
215 .Dv feof_unlocked ,
216 .Dv ferror ,
217 .Dv ferror_unlocked ,
218 .Dv fileno ,
219 .Dv fileno_unlocked ,
220 .Dv getc ,
221 .Dv getc_unlocked ,
222 .Dv getchar ,
223 .Dv getchar_unlocked ,
224 .Dv putc ,
225 .Dv putc_unlocked ,
226 .Dv putchar ,
227 and
228 .Dv putchar_unlocked
229 exist and will be used if the macro
230 definitions are explicitly removed.
231 .Sh SEE ALSO
232 .Xr close 2 ,
233 .Xr open 2 ,
234 .Xr read 2 ,
235 .Xr write 2
236 .Sh STANDARDS
237 The
238 .Nm
239 library conforms to
240 .St -isoC-99 .
241 .Sh LIST OF FUNCTIONS
242 .Bl -column "Description"
243 .It Sy "Function Description"
244 .It "asprintf formatted output conversion"
245 .It "clearerr check and reset stream status"
246 .It "dprintf formatted output conversion"
247 .It "fclose close a stream"
248 .It "fdopen stream open functions"
249 .It "feof check and reset stream status"
250 .It "ferror check and reset stream status"
251 .It "fflush flush a stream"
252 .It "fgetc get next character or word from input stream"
253 .It "fgetln get a line from a stream"
254 .It "fgetpos reposition a stream"
255 .It "fgets get a line from a stream"
256 .It "fgetwc get next wide character from input stream"
257 .It "fgetws get a line of wide characters from a stream"
258 .It "fileno check and reset stream status"
259 .It "fopen stream open functions"
260 .It "fprintf formatted output conversion"
261 .It "fpurge flush a stream"
262 .It "fputc output a character or word to a stream"
263 .It "fputs output a line to a stream"
264 .It "fputwc output a wide character to a stream"
265 .It "fputws output a line of wide characters to a stream"
266 .It "fread binary stream input/output"
267 .It "freopen stream open functions"
268 .It "fropen open a stream"
269 .It "fscanf input format conversion"
270 .It "fseek reposition a stream"
271 .It "fsetpos reposition a stream"
272 .It "ftell reposition a stream"
273 .It "funopen open a stream"
274 .It "fwide set/get orientation of stream"
275 .It "fwopen open a stream"
276 .It "fwprintf formatted wide character output conversion"
277 .It "fwrite binary stream input/output"
278 .It "getc get next character or word from input stream"
279 .It "getchar get next character or word from input stream"
280 .It "getdelim get a line 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 "mkdtemp create unique temporary directory"
287 .It "mkstemp create unique temporary file"
288 .It "mktemp create unique temporary file"
289 .It "perror system error messages"
290 .It "printf formatted output conversion"
291 .It "putc output a character or word to a stream"
292 .It "putchar output a character or word to a stream"
293 .It "puts output a line to a stream"
294 .It "putw output a character or word to a stream"
295 .It "putwc output a wide character to a stream"
296 .It "putwchar output a wide character to a stream"
297 .It "remove remove directory entry"
298 .It "rewind reposition a stream"
299 .It "scanf input format conversion"
300 .It "setbuf stream buffering operations"
301 .It "setbuffer stream buffering operations"
302 .It "setlinebuf stream buffering operations"
303 .It "setvbuf stream buffering operations"
304 .It "snprintf formatted output conversion"
305 .It "sprintf formatted output conversion"
306 .It "sscanf input format conversion"
307 .It "strerror system error messages"
308 .It "swprintf formatted wide character output conversion"
309 .It "sys_errlist system error messages"
310 .It "sys_nerr system error messages"
311 .It "tempnam temporary file routines"
312 .It "tmpfile temporary file routines"
313 .It "tmpnam temporary file routines"
314 .It "ungetc un-get character from input stream"
315 .It "ungetwc un-get wide character from input stream"
316 .It "vasprintf formatted output conversion"
317 .It "vdprintf formatted output conversion"
318 .It "vfprintf formatted output conversion"
319 .It "vfscanf input format conversion"
320 .It "vfwprintf formatted wide character output conversion"
321 .It "vprintf formatted output conversion"
322 .It "vscanf input format conversion"
323 .It "vsnprintf formatted output conversion"
324 .It "vsprintf formatted output conversion"
325 .It "vsscanf input format conversion"
326 .It "vswprintf formatted wide character output conversion"
327 .It "vwprintf formatted wide character output conversion"
328 .It "wprintf formatted wide character output conversion"
329 .El
330 .Sh BUGS
331 The standard buffered functions do not interact well with certain other
332 library and system functions, especially
333 .Xr vfork 2 .