]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright (c) 1990, 1991 Regents of the University of California. |
2 | .\" All rights reserved. | |
3 | .\" | |
47009d5e | 4 | .\" SPDX-License-Identifier: BSD-4-Clause-UC |
fea681da MK |
5 | .\" |
6 | .\" @(#)stdio.3 6.5 (Berkeley) 5/6/91 | |
7 | .\" | |
8 | .\" Converted for Linux, Mon Nov 29 16:07:22 1993, faith@cs.unc.edu | |
9 | .\" Modified, 2001-12-26, aeb | |
10 | .\" | |
45186a5d | 11 | .TH STDIO 3 2021-03-22 "Linux man-pages (unreleased)" |
fea681da MK |
12 | .SH NAME |
13 | stdio \- standard input/output library functions | |
77e337de AC |
14 | .SH LIBRARY |
15 | Standard C library | |
8fc3b2cf | 16 | .RI ( libc ", " \-lc ) |
fea681da | 17 | .SH SYNOPSIS |
c7db92b9 | 18 | .nf |
fea681da | 19 | .B #include <stdio.h> |
68e4db0a | 20 | .PP |
c8ce4bc6 | 21 | .BI "FILE *" stdin ; |
d9cf37f4 | 22 | .BI "FILE *" stdout ; |
d9cf37f4 | 23 | .BI "FILE *" stderr ; |
c7db92b9 | 24 | .fi |
fea681da MK |
25 | .SH DESCRIPTION |
26 | The standard I/O library provides a simple and efficient buffered stream | |
c13182ef MK |
27 | I/O interface. |
28 | Input and output is mapped into logical data streams and the | |
29 | physical I/O characteristics are concealed. | |
30 | The functions and macros are | |
fea681da MK |
31 | listed below; more information is available from the individual man pages. |
32 | .PP | |
33 | A stream is associated with an external file (which may be a physical | |
34 | device) by | |
35 | .I opening | |
c13182ef MK |
36 | a file, which may involve creating a new file. |
37 | Creating an existing file | |
38 | causes its former contents to be discarded. | |
39 | If a file can support positioning requests (such as a disk file, | |
4af20010 | 40 | as opposed to a terminal), then a |
fea681da MK |
41 | .I file position indicator |
42 | associated with the stream is positioned at the start of the file (byte | |
c13182ef MK |
43 | zero), unless the file is opened with append mode. |
44 | If append mode is used, | |
fea681da | 45 | it is unspecified whether the position indicator will be placed at the |
c13182ef MK |
46 | start or the end of the file. |
47 | The position indicator is maintained by | |
735334d4 | 48 | subsequent reads, writes, and positioning requests. |
c13182ef | 49 | All input occurs as if the characters were read by successive calls to the |
fea681da MK |
50 | .BR fgetc (3) |
51 | function; all output takes place as if all characters were written by | |
52 | successive calls to the | |
53 | .BR fputc (3) | |
54 | function. | |
55 | .PP | |
56 | A file is disassociated from a stream by | |
57 | .I closing | |
c13182ef MK |
58 | the file. |
59 | Output streams are flushed (any unwritten buffer contents are | |
fea681da | 60 | transferred to the host environment) before the stream is disassociated from |
c13182ef MK |
61 | the file. |
62 | The value of a pointer to a | |
097585ed | 63 | .I FILE |
fea681da MK |
64 | object is indeterminate after a file is closed (garbage). |
65 | .PP | |
66 | A file may be subsequently reopened, by the same or another program | |
67 | execution, and its contents reclaimed or modified (if it can be | |
c13182ef MK |
68 | repositioned at the start). |
69 | If the main function returns to its original | |
fea681da MK |
70 | caller, or the |
71 | .BR exit (3) | |
72 | function is called, all open files are closed (hence all output streams are | |
c13182ef MK |
73 | flushed) before program termination. |
74 | Other methods of program termination, | |
fea681da MK |
75 | such as |
76 | .BR abort (3) | |
77 | do not bother about closing files properly. | |
78 | .PP | |
79 | At program startup, three text streams are predefined and need not be | |
a43aff68 | 80 | opened explicitly: |
c13182ef | 81 | .I standard input |
a43aff68 | 82 | (for reading conventional input), |
c13182ef | 83 | .I standard output |
f5b9f413 | 84 | (for writing conventional output), and |
fea681da | 85 | .I standard error |
c13182ef MK |
86 | (for writing diagnostic output). |
87 | These streams are abbreviated | |
6da3279c SL |
88 | .IR stdin , |
89 | .IR stdout , | |
fea681da MK |
90 | and |
91 | .IR stderr . | |
92 | When opened, the standard error stream is not fully buffered; the standard | |
93 | input and output streams are fully buffered if and only if the streams do | |
29abb77b | 94 | not refer to an interactive device. |
fea681da MK |
95 | .PP |
96 | Output streams that refer to terminal devices are always line buffered by | |
97 | default; pending output to such streams is written automatically whenever | |
c13182ef MK |
98 | an input stream that refers to a terminal device is read. |
99 | In cases where a | |
fea681da MK |
100 | large amount of computation is done after printing part of a line on an |
101 | output terminal, it is necessary to | |
102 | .BR fflush (3) | |
103 | the standard output before going off and computing so that the output will | |
104 | appear. | |
105 | .PP | |
106 | The | |
f19a0f03 | 107 | .I stdio |
fea681da MK |
108 | library is a part of the library |
109 | .B libc | |
5f70d096 MK |
110 | and routines are automatically loaded as needed by |
111 | .BR cc (1). | |
fea681da | 112 | The |
3d341b33 | 113 | SYNOPSIS |
fea681da MK |
114 | sections of the following manual pages indicate which include files are to |
115 | be used, what the compiler declaration for the function looks like and | |
116 | which external variables are of interest. | |
117 | .PP | |
3b777aff | 118 | The following are defined as macros; these names may not be reused without |
fea681da MK |
119 | first removing their current definitions with |
120 | .BR #undef : | |
121 | .BR BUFSIZ , | |
122 | .BR EOF , | |
123 | .BR FILENAME_MAX , | |
124 | .BR FOPEN_MAX , | |
125 | .BR L_cuserid , | |
126 | .BR L_ctermid , | |
a5e0a0e4 | 127 | .BR L_tmpnam , |
fea681da MK |
128 | .BR NULL , |
129 | .BR SEEK_END , | |
130 | .BR SEEK_SET , | |
24a7082a | 131 | .BR SEEK_CUR , |
fea681da MK |
132 | .BR TMP_MAX , |
133 | .BR clearerr , | |
134 | .BR feof , | |
135 | .BR ferror , | |
136 | .BR fileno , | |
834fec09 MK |
137 | .\" Not on Linux: .BR fropen , |
138 | .\" Not on Linux: .BR fwopen , | |
fea681da MK |
139 | .BR getc , |
140 | .BR getchar , | |
141 | .BR putc , | |
142 | .BR putchar , | |
143 | .BR stderr , | |
144 | .BR stdin , | |
145 | .BR stdout . | |
146 | Function versions of the macro functions | |
147 | .BR feof , | |
148 | .BR ferror , | |
149 | .BR clearerr , | |
150 | .BR fileno , | |
151 | .BR getc , | |
152 | .BR getchar , | |
153 | .BR putc , | |
154 | and | |
155 | .B putchar | |
156 | exist and will be used if the macros definitions are explicitly removed. | |
73d8cece | 157 | .SS List of functions |
0b174fe0 MK |
158 | .nh |
159 | .ad l | |
9771e6de MK |
160 | .TS |
161 | ; | |
0b174fe0 | 162 | lb lbx |
3242546c | 163 | l l. |
9771e6de MK |
164 | Function Description |
165 | _ | |
0b174fe0 MK |
166 | \fBclearerr\fP(3) T{ |
167 | check and reset stream status | |
168 | T} | |
169 | \fBfclose\fP(3) T{ | |
170 | close a stream | |
171 | T} | |
172 | \fBfdopen\fP(3) T{ | |
173 | stream open functions | |
174 | T} | |
175 | \fBfeof\fP(3) T{ | |
176 | check and reset stream status | |
177 | T} | |
178 | \fBferror\fP(3) T{ | |
179 | check and reset stream status | |
180 | T} | |
181 | \fBfflush\fP(3) T{ | |
182 | flush a stream | |
183 | T} | |
184 | \fBfgetc\fP(3) T{ | |
185 | get next character or word from input stream | |
186 | T} | |
187 | \fBfgetpos\fP(3) T{ | |
188 | reposition a stream | |
189 | T} | |
190 | \fBfgets\fP(3) T{ | |
191 | get a line from a stream | |
192 | T} | |
193 | \fBfileno\fP(3) T{ | |
194 | return the integer descriptor of the argument stream | |
195 | T} | |
196 | \fBfopen\fP(3) T{ | |
197 | stream open functions | |
198 | T} | |
199 | \fBfprintf\fP(3) T{ | |
200 | formatted output conversion | |
201 | T} | |
202 | \fBfpurge\fP(3) T{ | |
203 | flush a stream | |
204 | T} | |
205 | \fBfputc\fP(3) T{ | |
206 | output a character or word to a stream | |
207 | T} | |
208 | \fBfputs\fP(3) T{ | |
209 | output a line to a stream | |
210 | T} | |
211 | \fBfread\fP(3) T{ | |
212 | binary stream input/output | |
213 | T} | |
214 | \fBfreopen\fP(3) T{ | |
215 | stream open functions | |
216 | T} | |
217 | \fBfscanf\fP(3) T{ | |
218 | input format conversion | |
219 | T} | |
220 | \fBfseek\fP(3) T{ | |
221 | reposition a stream | |
222 | T} | |
223 | \fBfsetpos\fP(3) T{ | |
224 | reposition a stream | |
225 | T} | |
226 | \fBftell\fP(3) T{ | |
227 | reposition a stream | |
228 | T} | |
229 | \fBfwrite\fP(3) T{ | |
230 | binary stream input/output | |
231 | T} | |
232 | \fBgetc\fP(3) T{ | |
233 | get next character or word from input stream | |
234 | T} | |
235 | \fBgetchar\fP(3) T{ | |
236 | get next character or word from input stream | |
237 | T} | |
238 | \fBgets\fP(3) T{ | |
239 | get a line from a stream | |
240 | T} | |
241 | \fBgetw\fP(3) T{ | |
242 | get next character or word from input stream | |
243 | T} | |
244 | \fBmktemp\fP(3) T{ | |
245 | make temporary filename (unique) | |
246 | T} | |
247 | \fBperror\fP(3) T{ | |
248 | system error messages | |
249 | T} | |
250 | \fBprintf\fP(3) T{ | |
251 | formatted output conversion | |
252 | T} | |
253 | \fBputc\fP(3) T{ | |
254 | output a character or word to a stream | |
255 | T} | |
256 | \fBputchar\fP(3) T{ | |
257 | output a character or word to a stream | |
258 | T} | |
259 | \fBputs\fP(3) T{ | |
260 | output a line to a stream | |
261 | T} | |
262 | \fBputw\fP(3) T{ | |
263 | output a character or word to a stream | |
264 | T} | |
265 | \fBremove\fP(3) T{ | |
266 | remove directory entry | |
267 | T} | |
268 | \fBrewind\fP(3) T{ | |
269 | reposition a stream | |
270 | T} | |
271 | \fBscanf\fP(3) T{ | |
272 | input format conversion | |
273 | T} | |
274 | \fBsetbuf\fP(3) T{ | |
275 | stream buffering operations | |
276 | T} | |
277 | \fBsetbuffer\fP(3) T{ | |
278 | stream buffering operations | |
279 | T} | |
280 | \fBsetlinebuf\fP(3) T{ | |
281 | stream buffering operations | |
282 | T} | |
283 | \fBsetvbuf\fP(3) T{ | |
284 | stream buffering operations | |
285 | T} | |
286 | \fBsprintf\fP(3) T{ | |
287 | formatted output conversion | |
288 | T} | |
289 | \fBsscanf\fP(3) T{ | |
290 | input format conversion | |
291 | T} | |
292 | \fBstrerror\fP(3) T{ | |
293 | system error messages | |
294 | T} | |
295 | \fBsys_errlist\fP(3) T{ | |
296 | system error messages | |
297 | T} | |
298 | \fBsys_nerr\fP(3) T{ | |
299 | system error messages | |
300 | T} | |
301 | \fBtempnam\fP(3) T{ | |
302 | temporary file routines | |
303 | T} | |
304 | \fBtmpfile\fP(3) T{ | |
305 | temporary file routines | |
306 | T} | |
307 | \fBtmpnam\fP(3) T{ | |
308 | temporary file routines | |
309 | T} | |
310 | \fBungetc\fP(3) T{ | |
311 | un-get character from input stream | |
312 | T} | |
313 | \fBvfprintf\fP(3) T{ | |
314 | formatted output conversion | |
315 | T} | |
316 | \fBvfscanf\fP(3) T{ | |
317 | input format conversion | |
318 | T} | |
319 | \fBvprintf\fP(3) T{ | |
320 | formatted output conversion | |
321 | T} | |
322 | \fBvscanf\fP(3) T{ | |
323 | input format conversion | |
324 | T} | |
325 | \fBvsprintf\fP(3) T{ | |
326 | formatted output conversion | |
327 | T} | |
328 | \fBvsscanf\fP(3) T{ | |
329 | input format conversion | |
330 | T} | |
9771e6de | 331 | .TE |
0b174fe0 MK |
332 | .ad |
333 | .hy | |
3113c7f3 | 334 | .SH STANDARDS |
fea681da | 335 | The |
f19a0f03 | 336 | .I stdio |
68e1685c | 337 | library conforms to C89. |
47297adb | 338 | .SH SEE ALSO |
fea681da MK |
339 | .BR close (2), |
340 | .BR open (2), | |
341 | .BR read (2), | |
342 | .BR write (2), | |
a2337ea3 MK |
343 | .BR stdout (3), |
344 | .BR unlocked_stdio (3) |