]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/fflush.3
err.3: EXAMPLES: use EXIT_FAILURE rather than 1 as exit status
[thirdparty/man-pages.git] / man3 / fflush.3
CommitLineData
fea681da
MK
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 and the American National Standards Committee X3,
6.\" on Information Processing Systems.
7.\"
a9cd9cb7 8.\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
fea681da
MK
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in the
16.\" documentation and/or other materials provided with the distribution.
17.\" 3. All advertising materials mentioning features or use of this software
18.\" must display the following acknowledgement:
19.\" This product includes software developed by the University of
20.\" California, Berkeley and its contributors.
21.\" 4. Neither the name of the University nor the names of its contributors
22.\" may be used to endorse or promote products derived from this software
23.\" without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35.\" SUCH DAMAGE.
8c9302dc 36.\" %%%LICENSE_END
fea681da
MK
37.\"
38.\" @(#)fflush.3 5.4 (Berkeley) 6/29/91
39.\"
40.\" Converted for Linux, Mon Nov 29 15:22:01 1993, faith@cs.unc.edu
41.\"
e00c3a07 42.\" Modified 2000-07-22 by Nicolás Lichtmaier <nick@debian.org>
fea681da
MK
43.\" Modified 2001-10-16 by John Levon <moz@compsoc.man.ac.uk>
44.\"
4b8c67d9 45.TH FFLUSH 3 2017-09-15 "GNU" "Linux Programmer's Manual"
fea681da
MK
46.SH NAME
47fflush \- flush a stream
48.SH SYNOPSIS
49.B #include <stdio.h>
68e4db0a 50.PP
fea681da
MK
51.BI "int fflush(FILE *" stream );
52.SH DESCRIPTION
2b64c171 53For output streams,
e511ffb6 54.BR fflush ()
fea681da
MK
55forces a write of all user-space buffered data for the given output or update
56.I stream
c13182ef 57via the stream's underlying write function.
847e0d88 58.PP
099263ce
MK
59For input streams associated with seekable files
60(e.g., disk files, but not pipes or terminals),
2b64c171
MK
61.BR fflush ()
62discards any buffered data that has been fetched from the underlying file,
20479b66 63but has not been consumed by the application.
847e0d88 64.PP
c13182ef 65The open status of the stream is unaffected.
fea681da
MK
66.PP
67If the
68.I stream
8478ee02 69argument is NULL,
e511ffb6 70.BR fflush ()
fea681da
MK
71flushes
72.I all
73open output streams.
76033537
MK
74.\" mtk: POSIX specifies that only output streams are flushed for this case.
75.\" Also verified for glibc by experiment.
fea681da 76.PP
24b74457 77For a nonlocking counterpart, see
fea681da 78.BR unlocked_stdio (3).
47297adb 79.SH RETURN VALUE
c13182ef
MK
80Upon successful completion 0 is returned.
81Otherwise,
fea681da 82.B EOF
9e39c4da 83is returned and
fea681da
MK
84.I errno
85is set to indicate the error.
86.SH ERRORS
87.TP
88.B EBADF
199431b6 89.I stream
fea681da
MK
90is not an open stream, or is not open for writing.
91.PP
92The function
e511ffb6 93.BR fflush ()
fea681da
MK
94may also fail and set
95.I errno
9e39c4da 96for any of the errors specified for
fea681da 97.BR write (2).
676420f2 98.SH ATTRIBUTES
0b8af3fa
MK
99For an explanation of the terms used in this section, see
100.BR attributes (7).
101.TS
102allbox;
103lb lb lb
104l l l.
105Interface Attribute Value
106T{
676420f2 107.BR fflush ()
0b8af3fa
MK
108T} Thread safety MT-Safe
109.TE
47297adb 110.SH CONFORMING TO
2b64c171 111C89, C99, POSIX.1-2001, POSIX.1-2008.
847e0d88 112.PP
6db34ce8
MK
113POSIX.1-2001 did not specify the behavior for flushing of input streams,
114but the behavior is specified in POSIX.1-2008.
fea681da
MK
115.SH NOTES
116Note that
63aa9df0 117.BR fflush ()
1c709786 118flushes only the user-space buffers provided by the C library.
fea681da 119To ensure that the data is physically stored on disk
75b94dc3 120the kernel buffers must be flushed too, for example, with
fea681da
MK
121.BR sync (2)
122or
123.BR fsync (2).
47297adb 124.SH SEE ALSO
fea681da
MK
125.BR fsync (2),
126.BR sync (2),
127.BR write (2),
128.BR fclose (3),
f65efcf5 129.BR fileno (3),
fea681da
MK
130.BR fopen (3),
131.BR setbuf (3),
132.BR unlocked_stdio (3)