| 1 |
'\" t |
| 2 |
.\" Copyright 1990-1991, The Regents of the University of California. |
| 3 |
.\" Copyright, the authors of the Linux man-pages project |
| 4 |
.\" |
| 5 |
.\" SPDX-License-Identifier: BSD-4-Clause-UC |
| 6 |
.\" |
| 7 |
.TH fflush 3 2025-05-17 "Linux man-pages 6.18" |
| 8 |
.SH NAME |
| 9 |
fflush \- flush a stream |
| 10 |
.SH LIBRARY |
| 11 |
Standard C library |
| 12 |
.RI ( libc ,\~ \-lc ) |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
.B #include <stdio.h> |
| 16 |
.P |
| 17 |
.BI "int fflush(FILE *_Nullable " stream ); |
| 18 |
.fi |
| 19 |
.SH DESCRIPTION |
| 20 |
For output streams, |
| 21 |
.BR fflush () |
| 22 |
forces a write of all user-space buffered data for the given output or update |
| 23 |
.I stream |
| 24 |
via the stream's underlying write function. |
| 25 |
.P |
| 26 |
For input streams associated with seekable files |
| 27 |
(e.g., disk files, but not pipes or terminals), |
| 28 |
.BR fflush () |
| 29 |
discards any buffered data that has been fetched from the underlying file, |
| 30 |
but has not been consumed by the application. |
| 31 |
.P |
| 32 |
The open status of the stream is unaffected. |
| 33 |
.P |
| 34 |
If the |
| 35 |
.I stream |
| 36 |
argument is NULL, |
| 37 |
.BR fflush () |
| 38 |
flushes |
| 39 |
.I all |
| 40 |
open output streams. |
| 41 |
.\" mtk: POSIX specifies that only output streams are flushed for this case. |
| 42 |
.\" Also verified for glibc by experiment. |
| 43 |
.P |
| 44 |
For a nonlocking counterpart, see |
| 45 |
.BR unlocked_stdio (3). |
| 46 |
.SH RETURN VALUE |
| 47 |
Upon successful completion 0 is returned. |
| 48 |
Otherwise, |
| 49 |
.B EOF |
| 50 |
is returned and |
| 51 |
.I errno |
| 52 |
is set to indicate the error. |
| 53 |
.SH ERRORS |
| 54 |
.TP |
| 55 |
.B EBADF |
| 56 |
.I stream |
| 57 |
is not an open stream, or is not open for writing. |
| 58 |
.P |
| 59 |
The function |
| 60 |
.BR fflush () |
| 61 |
may also fail and set |
| 62 |
.I errno |
| 63 |
for any of the errors specified for |
| 64 |
.BR write (2). |
| 65 |
.SH ATTRIBUTES |
| 66 |
For an explanation of the terms used in this section, see |
| 67 |
.BR attributes (7). |
| 68 |
.TS |
| 69 |
allbox; |
| 70 |
lbx lb lb |
| 71 |
l l l. |
| 72 |
Interface Attribute Value |
| 73 |
T{ |
| 74 |
.na |
| 75 |
.nh |
| 76 |
.BR fflush () |
| 77 |
T} Thread safety MT-Safe |
| 78 |
.TE |
| 79 |
.SH STANDARDS |
| 80 |
C11, POSIX.1-2008. |
| 81 |
.SH HISTORY |
| 82 |
C89, POSIX.1-2001, POSIX.1-2008. |
| 83 |
.P |
| 84 |
POSIX.1-2001 did not specify the behavior for flushing of input streams, |
| 85 |
but the behavior is specified in POSIX.1-2008. |
| 86 |
.SH NOTES |
| 87 |
Note that |
| 88 |
.BR fflush () |
| 89 |
flushes only the user-space buffers provided by the C library. |
| 90 |
To ensure that the data is physically stored on disk |
| 91 |
the kernel buffers must be flushed too, for example, with |
| 92 |
.BR sync (2) |
| 93 |
or |
| 94 |
.BR fsync (2). |
| 95 |
.SH SEE ALSO |
| 96 |
.BR fsync (2), |
| 97 |
.BR sync (2), |
| 98 |
.BR write (2), |
| 99 |
.BR fclose (3), |
| 100 |
.BR fileno (3), |
| 101 |
.BR fopen (3), |
| 102 |
.BR fpurge (3), |
| 103 |
.BR setbuf (3), |
| 104 |
.BR unlocked_stdio (3) |