mount_setattr.2: ffix
[man-pages.git] / man3 / fflush.3
bloba600da2ae9fb04420d27772ac04dfde6b1fee4d3
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 .\"
8 .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
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.
36 .\" %%%LICENSE_END
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 .\"
42 .\" Modified 2000-07-22 by Nicolás Lichtmaier <nick@debian.org>
43 .\" Modified 2001-10-16 by John Levon <moz@compsoc.man.ac.uk>
44 .\"
45 .TH FFLUSH 3  2021-03-22 "GNU" "Linux Programmer's Manual"
46 .SH NAME
47 fflush \- flush a stream
48 .SH SYNOPSIS
49 .nf
50 .B #include <stdio.h>
51 .PP
52 .BI "int fflush(FILE *" stream );
53 .fi
54 .SH DESCRIPTION
55 For output streams,
56 .BR fflush ()
57 forces a write of all user-space buffered data for the given output or update
58 .I stream
59 via the stream's underlying write function.
60 .PP
61 For input streams associated with seekable files
62 (e.g., disk files, but not pipes or terminals),
63 .BR fflush ()
64 discards any buffered data that has been fetched from the underlying file,
65 but has not been consumed by the application.
66 .PP
67 The open status of the stream is unaffected.
68 .PP
69 If the
70 .I stream
71 argument is NULL,
72 .BR fflush ()
73 flushes
74 .I all
75 open output streams.
76 .\" mtk: POSIX specifies that only output streams are flushed for this case.
77 .\" Also verified for glibc by experiment.
78 .PP
79 For a nonlocking counterpart, see
80 .BR unlocked_stdio (3).
81 .SH RETURN VALUE
82 Upon successful completion 0 is returned.
83 Otherwise,
84 .B EOF
85 is returned and
86 .I errno
87 is set to indicate the error.
88 .SH ERRORS
89 .TP
90 .B EBADF
91 .I stream
92 is not an open stream, or is not open for writing.
93 .PP
94 The function
95 .BR fflush ()
96 may also fail and set
97 .I errno
98 for any of the errors specified for
99 .BR write (2).
100 .SH ATTRIBUTES
101 For an explanation of the terms used in this section, see
102 .BR attributes (7).
103 .ad l
106 allbox;
107 lbx lb lb
108 l l l.
109 Interface       Attribute       Value
111 .BR fflush ()
112 T}      Thread safety   MT-Safe
116 .sp 1
117 .SH CONFORMING TO
118 C89, C99, POSIX.1-2001, POSIX.1-2008.
120 POSIX.1-2001 did not specify the behavior for flushing of input streams,
121 but the behavior is specified in POSIX.1-2008.
122 .SH NOTES
123 Note that
124 .BR fflush ()
125 flushes only the user-space buffers provided by the C library.
126 To ensure that the data is physically stored on disk
127 the kernel buffers must be flushed too, for example, with
128 .BR sync (2)
130 .BR fsync (2).
131 .SH SEE ALSO
132 .BR fsync (2),
133 .BR sync (2),
134 .BR write (2),
135 .BR fclose (3),
136 .BR fpurge (3),
137 .BR fileno (3),
138 .BR fopen (3),
139 .BR setbuf (3),
140 .BR unlocked_stdio (3)