]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/fflush.3
man*/: ffix (un-bracket tables)
[thirdparty/man-pages.git] / man3 / fflush.3
1 '\" t
2 .\" Copyright (c) 1990, 1991 The Regents of the University of California.
3 .\" All rights reserved.
4 .\"
5 .\" This code is derived from software contributed to Berkeley by
6 .\" Chris Torek and the American National Standards Committee X3,
7 .\" on Information Processing Systems.
8 .\"
9 .\" SPDX-License-Identifier: BSD-4-Clause-UC
10 .\"
11 .\" @(#)fflush.3 5.4 (Berkeley) 6/29/91
12 .\"
13 .\" Converted for Linux, Mon Nov 29 15:22:01 1993, faith@cs.unc.edu
14 .\"
15 .\" Modified 2000-07-22 by Nicolás Lichtmaier <nick@debian.org>
16 .\" Modified 2001-10-16 by John Levon <moz@compsoc.man.ac.uk>
17 .\"
18 .TH fflush 3 (date) "Linux man-pages (unreleased)"
19 .SH NAME
20 fflush \- flush a stream
21 .SH LIBRARY
22 Standard C library
23 .RI ( libc ", " \-lc )
24 .SH SYNOPSIS
25 .nf
26 .B #include <stdio.h>
27 .PP
28 .BI "int fflush(FILE *_Nullable " stream );
29 .fi
30 .SH DESCRIPTION
31 For output streams,
32 .BR fflush ()
33 forces a write of all user-space buffered data for the given output or update
34 .I stream
35 via the stream's underlying write function.
36 .PP
37 For input streams associated with seekable files
38 (e.g., disk files, but not pipes or terminals),
39 .BR fflush ()
40 discards any buffered data that has been fetched from the underlying file,
41 but has not been consumed by the application.
42 .PP
43 The open status of the stream is unaffected.
44 .PP
45 If the
46 .I stream
47 argument is NULL,
48 .BR fflush ()
49 flushes
50 .I all
51 open output streams.
52 .\" mtk: POSIX specifies that only output streams are flushed for this case.
53 .\" Also verified for glibc by experiment.
54 .PP
55 For a nonlocking counterpart, see
56 .BR unlocked_stdio (3).
57 .SH RETURN VALUE
58 Upon successful completion 0 is returned.
59 Otherwise,
60 .B EOF
61 is returned and
62 .I errno
63 is set to indicate the error.
64 .SH ERRORS
65 .TP
66 .B EBADF
67 .I stream
68 is not an open stream, or is not open for writing.
69 .PP
70 The function
71 .BR fflush ()
72 may also fail and set
73 .I errno
74 for any of the errors specified for
75 .BR write (2).
76 .SH ATTRIBUTES
77 For an explanation of the terms used in this section, see
78 .BR attributes (7).
79 .TS
80 allbox;
81 lbx lb lb
82 l l l.
83 Interface Attribute Value
84 T{
85 .na
86 .nh
87 .BR fflush ()
88 T} Thread safety MT-Safe
89 .TE
90 .sp 1
91 .SH STANDARDS
92 C11, POSIX.1-2008.
93 .SH HISTORY
94 C89, POSIX.1-2001, POSIX.1-2008.
95 .PP
96 POSIX.1-2001 did not specify the behavior for flushing of input streams,
97 but the behavior is specified in POSIX.1-2008.
98 .SH NOTES
99 Note that
100 .BR fflush ()
101 flushes only the user-space buffers provided by the C library.
102 To ensure that the data is physically stored on disk
103 the kernel buffers must be flushed too, for example, with
104 .BR sync (2)
105 or
106 .BR fsync (2).
107 .SH SEE ALSO
108 .BR fsync (2),
109 .BR sync (2),
110 .BR write (2),
111 .BR fclose (3),
112 .BR fileno (3),
113 .BR fopen (3),
114 .BR fpurge (3),
115 .BR setbuf (3),
116 .BR unlocked_stdio (3)