]> git.saurik.com Git - apple/libc.git/blame - stdio/FreeBSD/stdio.3
Libc-997.1.1.tar.gz
[apple/libc.git] / stdio / FreeBSD / stdio.3
CommitLineData
5b2abdfb
A
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.
5b2abdfb
A
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
1f2f436a 29.\" $FreeBSD: src/lib/libc/stdio/stdio.3,v 1.30 2009/03/04 03:38:51 das Exp $
5b2abdfb 30.\"
1f2f436a 31.Dd March 3, 2009
5b2abdfb
A
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 ;
ad3c9f2a
A
44.Pp
45Note:
46The current implementation does not allow these variables
47to be evaluated at C compile/link time.
48That is, a runtime calculation must be performed, such as:
49.Bd -literal -offset indent
50#include <stdio.h>
51
52static FILE *var;
53
54int main() {
55 var = stdout;
56}
57.Ed
5b2abdfb
A
58.Sh DESCRIPTION
59The standard
60.Tn I/O
61library provides a simple and efficient buffered stream
62.Tn I/O
63interface.
64Input and output is mapped into logical data streams
65and the physical
66.Tn I/O
67characteristics are concealed.
68The functions and macros are listed
69below; more information is available from the individual man pages.
70.Pp
71A stream is associated with an external file (which may be a physical
72device) by
73.Em opening
74a file, which may involve creating a new file.
75Creating an
76existing file causes its former contents to be discarded.
77If a file can support positioning requests (such as a disk file, as opposed
78to a terminal) then a
79.Em file position indicator
80associated with the stream is positioned at the start of the file (byte
81zero), unless the file is opened with append mode.
82If append mode
83is used, the position indicator will be placed at the end-of-file.
84The position indicator is maintained by subsequent reads, writes
85and positioning requests.
86All input occurs as if the characters
87were read by successive calls to the
88.Xr fgetc 3
89function; all output takes place as if all characters were
90written by successive calls to the
91.Xr fputc 3
92function.
93.Pp
94A file is disassociated from a stream by
95.Em closing
96the file.
97Output streams are flushed (any unwritten buffer contents are transferred
98to the host environment) before the stream is disassociated from the file.
99The value of a pointer to a
100.Dv FILE
101object is indeterminate (garbage) after a file is closed.
102.Pp
103A file may be subsequently reopened, by the same or another program
104execution, and its contents reclaimed or modified (if it can be repositioned
3d9156a7
A
105at the start).
106If the main function returns to its original caller, or
5b2abdfb
A
107the
108.Xr exit 3
109function is called, all open files are closed (hence all output
3d9156a7
A
110streams are flushed) before program termination.
111Other methods
5b2abdfb 112of program termination may not close files properly and hence
3d9156a7
A
113buffered output may be lost.
114In particular,
5b2abdfb 115.Xr _exit 2
3d9156a7
A
116does not flush stdio files.
117Neither does an exit due to a signal.
5b2abdfb
A
118Buffers are flushed by
119.Xr abort 3
120as required by POSIX, although previous implementations did not.
121.Pp
122This implementation makes no distinction between
123.Dq text
124and
125.Dq binary
126streams.
127In effect, all streams are binary.
128No translation is performed and no extra padding appears on any stream.
129.Pp
130At program startup, three streams are predefined and need not be
131opened explicitly:
132.Bl -bullet -compact -offset indent
133.It
134.Em standard input
135(for reading conventional input),
136.It
137.Em standard output
138(for writing conventional output), and
139.It
140.Em standard error
141(for writing diagnostic output).
142.El
143These streams are abbreviated
9385eb3d 144.Dv stdin , stdout
5b2abdfb 145and
9385eb3d 146.Dv stderr .
5b2abdfb
A
147Initially, the standard error stream
148is unbuffered; the standard input and output streams are
149fully buffered if and only if the streams do not refer to
150an interactive or
151.Dq terminal
152device, as determined by the
153.Xr isatty 3
154function.
155In fact,
156.Em all
157freshly-opened streams that refer to terminal devices
158default to line buffering, and
159pending output to such streams is written automatically
160whenever such an input stream is read.
161Note that this applies only to
162.Dq "true reads" ;
163if the read request can be satisfied by existing buffered data,
164no automatic flush will occur.
165In these cases,
166or when a large amount of computation is done after printing
167part of a line on an output terminal, it is necessary to
168.Xr fflush 3
169the standard output before going off and computing so that the output
170will appear.
171Alternatively, these defaults may be modified via the
172.Xr setvbuf 3
173function.
174.Pp
175The
176.Nm
177library is a part of the library
178.Nm libc
179and routines are automatically loaded as needed by the C compiler.
180The
181.Tn SYNOPSIS
182sections of the following manual pages indicate which include files
183are to be used, what the compiler declaration for the function
184looks like and which external variables are of interest.
185.Pp
186The following are defined as macros;
187these names may not be re-used
188without first removing their current definitions with
9385eb3d 189.Ic #undef :
5b2abdfb
A
190.Dv BUFSIZ ,
191.Dv EOF ,
192.Dv FILENAME_MAX ,
193.Dv FOPEN_MAX ,
5b2abdfb 194.Dv L_ctermid ,
9385eb3d 195.Dv L_cuserid ,
5b2abdfb
A
196.Dv L_tmpnam ,
197.Dv NULL ,
198.Dv P_tmpdir ,
199.Dv SEEK_CUR ,
200.Dv SEEK_END ,
201.Dv SEEK_SET ,
202.Dv TMP_MAX ,
3d9156a7 203.Dv clearerr ,
9385eb3d 204.Dv clearerr_unlocked ,
3d9156a7 205.Dv feof ,
9385eb3d 206.Dv feof_unlocked ,
3d9156a7 207.Dv ferror ,
9385eb3d 208.Dv ferror_unlocked ,
3d9156a7 209.Dv fileno ,
9385eb3d 210.Dv fileno_unlocked ,
5b2abdfb
A
211.Dv fropen ,
212.Dv fwopen ,
3d9156a7 213.Dv getc ,
9385eb3d 214.Dv getc_unlocked ,
3d9156a7 215.Dv getchar ,
9385eb3d 216.Dv getchar_unlocked ,
3d9156a7 217.Dv putc ,
9385eb3d 218.Dv putc_unlocked ,
3d9156a7 219.Dv putchar ,
9385eb3d 220.Dv putchar_unlocked ,
5b2abdfb 221.Dv stderr ,
9385eb3d
A
222.Dv stdin
223and
224.Dv stdout .
5b2abdfb 225Function versions of the macro functions
3d9156a7 226.Dv clearerr ,
9385eb3d 227.Dv clearerr_unlocked ,
3d9156a7 228.Dv feof ,
9385eb3d 229.Dv feof_unlocked ,
3d9156a7 230.Dv ferror ,
9385eb3d 231.Dv ferror_unlocked ,
3d9156a7 232.Dv fileno ,
9385eb3d 233.Dv fileno_unlocked ,
3d9156a7 234.Dv getc ,
9385eb3d 235.Dv getc_unlocked ,
3d9156a7 236.Dv getchar ,
9385eb3d 237.Dv getchar_unlocked ,
3d9156a7
A
238.Dv putc ,
239.Dv putc_unlocked ,
240.Dv putchar ,
5b2abdfb 241and
9385eb3d 242.Dv putchar_unlocked
5b2abdfb
A
243exist and will be used if the macro
244definitions are explicitly removed.
ad3c9f2a
A
245.Sh LEGACY SYNOPSIS
246The -D_NONSTD_SOURCE flag can be used
247to allow stdin, stdout, and/or stderr
248to be evaluated at compile/link time, as:
249.Bd -literal -offset indent
250#include <stdio.h>
251
252static FILE *var = stdout;
253.Ed
5b2abdfb
A
254.Sh SEE ALSO
255.Xr close 2 ,
256.Xr open 2 ,
257.Xr read 2 ,
ad3c9f2a
A
258.Xr write 2 ,
259.Xr compat 5
5b2abdfb
A
260.Sh STANDARDS
261The
262.Nm
263library conforms to
9385eb3d 264.St -isoC-99 .
5b2abdfb
A
265.Sh LIST OF FUNCTIONS
266.Bl -column "Description"
267.It Sy "Function Description"
268.It "asprintf formatted output conversion"
ad3c9f2a 269.It ""
5b2abdfb 270.It "clearerr check and reset stream status"
ad3c9f2a 271.It ""
5b2abdfb
A
272.It "fclose close a stream"
273.It "fdopen stream open functions"
274.It "feof check and reset stream status"
275.It "ferror check and reset stream status"
276.It "fflush flush a stream"
277.It "fgetc get next character or word from input stream"
278.It "fgetln get a line from a stream"
279.It "fgetpos reposition a stream"
280.It "fgets get a line from a stream"
9385eb3d
A
281.It "fgetwc get next wide character from input stream"
282.It "fgetws get a line of wide characters from a stream"
5b2abdfb
A
283.It "fileno check and reset stream status"
284.It "fopen stream open functions"
285.It "fprintf formatted output conversion"
286.It "fpurge flush a stream"
287.It "fputc output a character or word to a stream"
288.It "fputs output a line to a stream"
9385eb3d
A
289.It "fputwc output a wide character to a stream"
290.It "fputws output a line of wide characters to a stream"
5b2abdfb
A
291.It "fread binary stream input/output"
292.It "freopen stream open functions"
293.It "fropen open a stream"
294.It "fscanf input format conversion"
295.It "fseek reposition a stream"
296.It "fsetpos reposition a stream"
297.It "ftell reposition a stream"
298.It "funopen open a stream"
9385eb3d 299.It "fwide set/get orientation of stream"
5b2abdfb 300.It "fwopen open a stream"
9385eb3d 301.It "fwprintf formatted wide character output conversion"
5b2abdfb 302.It "fwrite binary stream input/output"
ad3c9f2a 303.It ""
5b2abdfb
A
304.It "getc get next character or word from input stream"
305.It "getchar get next character or word from input stream"
1f2f436a
A
306.It "getdelim get a line from a stream"
307.It "getline get a line from a stream"
5b2abdfb
A
308.It "gets get a line from a stream"
309.It "getw get next character or word from input stream"
9385eb3d
A
310.It "getwc get next wide character from input stream"
311.It "getwchar get next wide character from input stream"
ad3c9f2a 312.It ""
9385eb3d 313.It "mkdtemp create unique temporary directory"
5b2abdfb
A
314.It "mkstemp create unique temporary file"
315.It "mktemp create unique temporary file"
ad3c9f2a 316.It ""
5b2abdfb
A
317.It "perror system error messages"
318.It "printf formatted output conversion"
319.It "putc output a character or word to a stream"
320.It "putchar output a character or word to a stream"
321.It "puts output a line to a stream"
322.It "putw output a character or word to a stream"
9385eb3d
A
323.It "putwc output a wide character to a stream"
324.It "putwchar output a wide character to a stream"
ad3c9f2a 325.It ""
5b2abdfb
A
326.It "remove remove directory entry"
327.It "rewind reposition a stream"
ad3c9f2a 328.It ""
5b2abdfb
A
329.It "scanf input format conversion"
330.It "setbuf stream buffering operations"
331.It "setbuffer stream buffering operations"
332.It "setlinebuf stream buffering operations"
333.It "setvbuf stream buffering operations"
334.It "snprintf formatted output conversion"
335.It "sprintf formatted output conversion"
336.It "sscanf input format conversion"
337.It "strerror system error messages"
9385eb3d 338.It "swprintf formatted wide character output conversion"
5b2abdfb
A
339.It "sys_errlist system error messages"
340.It "sys_nerr system error messages"
ad3c9f2a 341.It ""
5b2abdfb
A
342.It "tempnam temporary file routines"
343.It "tmpfile temporary file routines"
344.It "tmpnam temporary file routines"
ad3c9f2a 345.It ""
5b2abdfb 346.It "ungetc un-get character from input stream"
9385eb3d 347.It "ungetwc un-get wide character from input stream"
ad3c9f2a 348.It ""
5b2abdfb
A
349.It "vasprintf formatted output conversion"
350.It "vfprintf formatted output conversion"
351.It "vfscanf input format conversion"
9385eb3d 352.It "vfwprintf formatted wide character output conversion"
5b2abdfb
A
353.It "vprintf formatted output conversion"
354.It "vscanf input format conversion"
355.It "vsnprintf formatted output conversion"
356.It "vsprintf formatted output conversion"
357.It "vsscanf input format conversion"
9385eb3d
A
358.It "vswprintf formatted wide character output conversion"
359.It "vwprintf formatted wide character output conversion"
ad3c9f2a 360.It ""
9385eb3d 361.It "wprintf formatted wide character output conversion"
5b2abdfb 362.El
1f2f436a
A
363.Sh BUGS
364The standard buffered functions do not interact well with certain other
365library and system functions, especially
366.Xr vfork 2 .