xref: /openbsd/lib/libc/stdio/fflush.3 (revision 78b63d65)
1.\"	$OpenBSD: fflush.3,v 1.5 2000/04/20 01:39:31 aaron Exp $
2.\"
3.\" Copyright (c) 1990, 1991, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\"    notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in the
17.\"    documentation and/or other materials provided with the distribution.
18.\" 3. All advertising materials mentioning features or use of this software
19.\"    must display the following acknowledgement:
20.\"	This product includes software developed by the University of
21.\"	California, Berkeley and its contributors.
22.\" 4. Neither the name of the University nor the names of its contributors
23.\"    may be used to endorse or promote products derived from this software
24.\"    without specific prior written permission.
25.\"
26.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36.\" SUCH DAMAGE.
37.\"
38.Dd June 4, 1993
39.Dt FFLUSH 3
40.Os
41.Sh NAME
42.Nm fflush ,
43.Nm fpurge
44.Nd flush a stream
45.Sh SYNOPSIS
46.Fd #include <stdio.h>
47.Ft int
48.Fn fflush "FILE *stream"
49.Ft int
50.Fn fpurge "FILE *stream"
51.Sh DESCRIPTION
52The function
53.Fn fflush
54forces a write of all buffered data for the given output or update
55.Fa stream
56via the stream's underlying write function.
57The open status of the stream is unaffected.
58.Pp
59If the
60.Fa stream
61argument is
62.Dv NULL ,
63.Fn fflush
64flushes
65.Em all
66open output streams.
67.Pp
68The function
69.Fn fpurge
70erases any input or output buffered in the given
71.Fa stream .
72For output streams this discards any unwritten output.
73For input streams this discards any input read from the underlying object
74but not yet obtained via
75.Xr getc 3 ;
76this includes any text pushed back via
77.Xr ungetc .
78.Sh RETURN VALUES
79Upon successful completion 0 is returned.
80Otherwise,
81.Dv EOF
82is returned and the global variable
83.Va errno
84is set to indicate the error.
85.Sh ERRORS
86.Bl -tag -width Er
87.It Bq Er EBADF
88.Fa stream
89is not an open stream, or, in the case of
90.Fn fflush ,
91not a stream open for writing.
92.El
93.Pp
94The function
95.Fn fflush
96may also fail and set
97.Va errno
98for any of the errors specified for the routine
99.Xr write 2 .
100.Sh SEE ALSO
101.Xr write 2 ,
102.Xr fclose 3 ,
103.Xr fopen 3 ,
104.Xr setbuf 3
105.Sh STANDARDS
106The
107.Fn fflush
108function conforms to
109.St -ansiC .
110