xref: /original-bsd/lib/libc/stdio/fflush.3 (revision cfa2a17a)
1.\" Copyright (c) 1990, 1991 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" Chris Torek.
6.\" %sccs.include.redist.man%
7.\"
8.\"     @(#)fflush.3	5.3 (Berkeley) 04/19/91
9.\"
10.Dd
11.Dt FFLUSH 3
12.Os
13.Sh NAME
14.Nm fflush ,
15.Nm fpurge
16.Nd flush a stream
17.Sh SYNOPSIS
18.Fd #include <stdio.h>
19.Ft int
20.Fn fflush "FILE *stream"
21.Ft int
22.Fn fpurge "FILE *stream"
23.Sh DESCRIPTION
24The function
25.Fn fflush
26forces a write of all buffered data for the given output or update
27.Fa stream
28via the stream's underlying write function.
29The open status of the stream is unaffected.
30.Pp
31If the
32.Fa stream
33argument is
34.Dv NULL ,
35.Fn fflush
36flushes
37.Em all
38open output streams.
39.Pp
40The function
41.Fn fpurge
42erases any input or output buffered in the given
43.Fa stream .
44For output streams this discards any unwritten output.
45For input streams this discards any input read from the underlying object
46but not yet obtained via
47.Xr getc 3 ;
48this includes any text pushed back via
49.Xr ungetc .
50.Sh RETURN VALUES
51Upon successful completion 0 is returned.
52Otherwise,
53.Dv EOF
54is returned and the global variable
55.Va errno
56is set to indicate the error.
57.Sh ERRORS
58.Bl -tag -width [EBADF]
59.It Bq Er EBADF
60.Fa Stream
61is not an open stream, or, in the case of
62.Fn fflush ,
63not a stream open for writing.
64.El
65.Pp
66The function
67.Fn fflush
68may also fail and set
69.Va errno
70for any of the errors specified for the routine
71.Xr write 2 .
72.Sh SEE ALSO
73.Xr write 2 ,
74.Xr fopen 3 ,
75.Xr fclose 3 ,
76.Xr setbuf 3
77.Sh STANDARDS
78The
79.Fn fflush
80function
81conforms to
82.St -ansiC .
83