add strdup for S5
[unix-history] / usr / src / lib / libc / stdio / stdio.3
CommitLineData
466c4377
KM
1.\" Copyright (c) 1980 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
a1cde3c2 5.\" @(#)stdio.3 6.2 (Berkeley) %G%
466c4377 6.\"
a1cde3c2 7.TH STDIO 3S ""
466c4377
KM
8.UC 4
9.SH NAME
10stdio \- standard buffered input/output package
11.SH SYNOPSIS
12.B #include <stdio.h>
13.PP
14.SM
15.B FILE
16.B *stdin;
17.br
18.SM
19.B FILE
20.B *stdout;
21.br
22.SM
23.B FILE
24.B *stderr;
25.SH DESCRIPTION
8a0524cf
KM
26The functions described in section 3S constitute a user-level buffering
27scheme. The in-line macros
466c4377
KM
28.I getc
29and
8a0524cf
KM
30.IR putc (3S)
31handle characters quickly. The higher level routines
32.IR gets ,
33.IR fgets ,
34.IR scanf ,
35.IR fscanf ,
36.IR fread ,
37.IR puts ,
38.IR fputs ,
39.IR printf ,
40.IR fprintf ,
41.IR fwrite
466c4377
KM
42all use
43.I getc
44and
8a0524cf 45.IR putc ;
466c4377
KM
46they can be freely intermixed.
47.PP
48A file with associated buffering is called a
8a0524cf 49.IR stream ,
466c4377
KM
50and is declared to be a pointer to a defined type
51.SM
8a0524cf
KM
52.BR FILE .
53.IR Fopen (3S)
466c4377 54creates certain descriptive data for a stream
8a0524cf
KM
55and returns a pointer to designate the stream in all further transactions.
56There are three normally open streams with constant pointers declared in
466c4377
KM
57the include file and associated with the standard open files:
58.TP 10n
8a0524cf 59.B stdin
466c4377
KM
60standard input file
61.br
62.ns
63.TP
64.B stdout
65standard output file
66.br
67.ns
68.TP
8a0524cf 69.B stderr
466c4377
KM
70standard error file
71.PP
72A constant `pointer'
73.SM
74.B NULL
75(0)
76designates no stream at all.
77.PP
78An integer constant
79.SM
80.B EOF
8a0524cf 81(\-1) is returned upon end of file or error by integer functions that
466c4377
KM
82deal with streams.
83.PP
84Any routine that uses the standard input/output package
8a0524cf
KM
85must include the header file
86.RI < stdio.h >
87of pertinent macro definitions.
466c4377 88The functions and constants mentioned in sections labeled 3S
8a0524cf 89are declared in the include file and need no further declaration.
466c4377 90The constants, and the following `functions' are
8a0524cf
KM
91implemented as macros; redeclaration of these names is perilous:
92.IR getc ,
93.IR getchar ,
94.IR putc ,
95.IR putchar ,
96.IR feof ,
97.IR ferror ,
466c4377
KM
98.IR fileno .
99.SH "SEE ALSO"
8a0524cf 100open(2), close(2), read(2), write(2), fread(3S), fseek(3S), f*(3S)
466c4377
KM
101.SH DIAGNOSTICS
102The value
103.SM
104.B EOF
105is returned uniformly to indicate that a
106.SM
107.B FILE
108pointer has not been initialized with
8a0524cf
KM
109.IR fopen ,
110input (output) has been attempted on an output (input) stream, or a
466c4377
KM
111.SM
112.B FILE
113pointer designates corrupt or otherwise unintelligible
114.SM
115.B FILE
116data.
117.PP
118For purposes of efficiency, this implementation of the standard library
119has been changed to line buffer output to a terminal by default and attempts
120to do this transparently by flushing the output whenever a
121.IR read (2)
122from the standard input is necessary. This is almost always transparent,
123but may cause confusion or malfunctioning of programs which use
124standard i/o routines but use
125.IR read (2)
126themselves to read from the standard input.
127.PP
128In cases where a large amount of computation is done after printing
129part of a line on an output terminal, it is necessary to
8a0524cf 130.IR fflush (3S)
466c4377
KM
131the standard output before going off and computing so that the output
132will appear.
8a0524cf
KM
133.SH BUGS
134The standard buffered functions do not interact well with certain other
135library and system functions, especially \fIvfork\fP and \fIabort\fP.
136.SH "LIST OF FUNCTIONS"
137.sp 2
138.nf
139.ta \w'setlinebuf'u+2n +\w'setbuf.3s'u+10n
140\fIName\fP \fIAppears on Page\fP \fIDescription\fP
141.ta \w'setlinebuf'u+4n +\w'setbuf.3s'u+4n
142.sp 5p
143clearerr ferror.3s stream status inquiries
144fclose fclose.3s close or flush a stream
145fdopen fopen.3s open a stream
146feof ferror.3s stream status inquiries
147ferror ferror.3s stream status inquiries
148fflush fclose.3s close or flush a stream
149fgetc getc.3s get character or word from stream
150fgets gets.3s get a string from a stream
151fileno ferror.3s stream status inquiries
152fopen fopen.3s open a stream
153fprintf printf.3s formatted output conversion
154fputc putc.3s put character or word on a stream
155fputs puts.3s put a string on a stream
156fread fread.3s buffered binary input/output
157freopen fopen.3s open a stream
158fscanf scanf.3s formatted input conversion
159fseek fseek.3s reposition a stream
160ftell fseek.3s reposition a stream
161fwrite fread.3s buffered binary input/output
162getc getc.3s get character or word from stream
163getchar getc.3s get character or word from stream
164gets gets.3s get a string from a stream
165getw getc.3s get character or word from stream
166printf printf.3s formatted output conversion
167putc putc.3s put character or word on a stream
168putchar putc.3s put character or word on a stream
169puts puts.3s put a string on a stream
170putw putc.3s put character or word on a stream
171rewind fseek.3s reposition a stream
172scanf scanf.3s formatted input conversion
173setbuf setbuf.3s assign buffering to a stream
174setbuffer setbuf.3s assign buffering to a stream
175setlinebuf setbuf.3s assign buffering to a stream
176sprintf printf.3s formatted output conversion
177sscanf scanf.3s formatted input conversion
178ungetc ungetc.3s push character back into input stream
179.fi