Blame man3/fflush.3

Packit 7cfc04
.\" Copyright (c) 1990, 1991 The Regents of the University of California.
Packit 7cfc04
.\" All rights reserved.
Packit 7cfc04
.\"
Packit 7cfc04
.\" This code is derived from software contributed to Berkeley by
Packit 7cfc04
.\" Chris Torek and the American National Standards Committee X3,
Packit 7cfc04
.\" on Information Processing Systems.
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
Packit 7cfc04
.\" Redistribution and use in source and binary forms, with or without
Packit 7cfc04
.\" modification, are permitted provided that the following conditions
Packit 7cfc04
.\" are met:
Packit 7cfc04
.\" 1. Redistributions of source code must retain the above copyright
Packit 7cfc04
.\"    notice, this list of conditions and the following disclaimer.
Packit 7cfc04
.\" 2. Redistributions in binary form must reproduce the above copyright
Packit 7cfc04
.\"    notice, this list of conditions and the following disclaimer in the
Packit 7cfc04
.\"    documentation and/or other materials provided with the distribution.
Packit 7cfc04
.\" 3. All advertising materials mentioning features or use of this software
Packit 7cfc04
.\"    must display the following acknowledgement:
Packit 7cfc04
.\"	This product includes software developed by the University of
Packit 7cfc04
.\"	California, Berkeley and its contributors.
Packit 7cfc04
.\" 4. Neither the name of the University nor the names of its contributors
Packit 7cfc04
.\"    may be used to endorse or promote products derived from this software
Packit 7cfc04
.\"    without specific prior written permission.
Packit 7cfc04
.\"
Packit 7cfc04
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
Packit 7cfc04
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit 7cfc04
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit 7cfc04
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
Packit 7cfc04
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit 7cfc04
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
Packit 7cfc04
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Packit 7cfc04
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
Packit 7cfc04
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
Packit 7cfc04
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
Packit 7cfc04
.\" SUCH DAMAGE.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\"     @(#)fflush.3	5.4 (Berkeley) 6/29/91
Packit 7cfc04
.\"
Packit 7cfc04
.\" Converted for Linux, Mon Nov 29 15:22:01 1993, faith@cs.unc.edu
Packit 7cfc04
.\"
Packit 7cfc04
.\" Modified 2000-07-22 by Nicolás Lichtmaier <nick@debian.org>
Packit 7cfc04
.\" Modified 2001-10-16 by John Levon <moz@compsoc.man.ac.uk>
Packit 7cfc04
.\"
Packit 7cfc04
.TH FFLUSH 3  2017-09-15 "GNU" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
fflush \- flush a stream
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.B #include <stdio.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int fflush(FILE *" stream );
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
For output streams,
Packit 7cfc04
.BR fflush ()
Packit 7cfc04
forces a write of all user-space buffered data for the given output or update
Packit 7cfc04
.I stream
Packit 7cfc04
via the stream's underlying write function.
Packit 7cfc04
.PP
Packit 7cfc04
For input streams associated with seekable files
Packit 7cfc04
(e.g., disk files, but not pipes or terminals),
Packit 7cfc04
.BR fflush ()
Packit 7cfc04
discards any buffered data that has been fetched from the underlying file,
Packit 7cfc04
but has not been consumed by the application.
Packit 7cfc04
.PP
Packit 7cfc04
The open status of the stream is unaffected.
Packit 7cfc04
.PP
Packit 7cfc04
If the
Packit 7cfc04
.I stream
Packit 7cfc04
argument is NULL,
Packit 7cfc04
.BR fflush ()
Packit 7cfc04
flushes
Packit 7cfc04
.I all
Packit 7cfc04
open output streams.
Packit 7cfc04
.\" mtk: POSIX specifies that only output streams are flushed for this case.
Packit 7cfc04
.\" Also verified for glibc by experiment.
Packit 7cfc04
.PP
Packit 7cfc04
For a nonlocking counterpart, see
Packit 7cfc04
.BR unlocked_stdio (3).
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
Upon successful completion 0 is returned.
Packit 7cfc04
Otherwise,
Packit 7cfc04
.B EOF
Packit 7cfc04
is returned and
Packit 7cfc04
.I errno
Packit 7cfc04
is set to indicate the error.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
.TP
Packit 7cfc04
.B EBADF
Packit 7cfc04
.I stream
Packit 7cfc04
is not an open stream, or is not open for writing.
Packit 7cfc04
.PP
Packit 7cfc04
The function
Packit 7cfc04
.BR fflush ()
Packit 7cfc04
may also fail and set
Packit 7cfc04
.I errno
Packit 7cfc04
for any of the errors specified for
Packit 7cfc04
.BR write (2).
Packit 7cfc04
.SH ATTRIBUTES
Packit 7cfc04
For an explanation of the terms used in this section, see
Packit 7cfc04
.BR attributes (7).
Packit 7cfc04
.TS
Packit 7cfc04
allbox;
Packit 7cfc04
lb lb lb
Packit 7cfc04
l l l.
Packit 7cfc04
Interface	Attribute	Value
Packit 7cfc04
T{
Packit 7cfc04
.BR fflush ()
Packit 7cfc04
T}	Thread safety	MT-Safe
Packit 7cfc04
.TE
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
C89, C99, POSIX.1-2001, POSIX.1-2008.
Packit 7cfc04
.PP
Packit 7cfc04
POSIX.1-2001 did not specify the behavior for flushing of input streams,
Packit 7cfc04
but the behavior is specified in POSIX.1-2008.
Packit 7cfc04
.SH NOTES
Packit 7cfc04
Note that
Packit 7cfc04
.BR fflush ()
Packit 7cfc04
flushes only the user-space buffers provided by the C library.
Packit 7cfc04
To ensure that the data is physically stored on disk
Packit 7cfc04
the kernel buffers must be flushed too, for example, with
Packit 7cfc04
.BR sync (2)
Packit 7cfc04
or
Packit 7cfc04
.BR fsync (2).
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR fsync (2),
Packit 7cfc04
.BR sync (2),
Packit 7cfc04
.BR write (2),
Packit 7cfc04
.BR fclose (3),
Packit 7cfc04
.BR fileno (3),
Packit 7cfc04
.BR fopen (3),
Packit 7cfc04
.BR setbuf (3),
Packit 7cfc04
.BR unlocked_stdio (3)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.