1.\" $OpenBSD: fflush.3,v 1.13 2019/09/07 10:28:27 schwarze Exp $ 2.\" 3.\" Copyright (c) 1990, 1991, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" This code is derived from software contributed to Berkeley by 7.\" Chris Torek and the American National Standards Committee X3, 8.\" on Information Processing Systems. 9.\" 10.\" Redistribution and use in source and binary forms, with or without 11.\" modification, are permitted provided that the following conditions 12.\" are met: 13.\" 1. Redistributions of source code must retain the above copyright 14.\" notice, this list of conditions and the following disclaimer. 15.\" 2. Redistributions in binary form must reproduce the above copyright 16.\" notice, this list of conditions and the following disclaimer in the 17.\" documentation and/or other materials provided with the distribution. 18.\" 3. Neither the name of the University nor the names of its contributors 19.\" may be used to endorse or promote products derived from this software 20.\" without specific prior written permission. 21.\" 22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32.\" SUCH DAMAGE. 33.\" 34.Dd $Mdocdate: September 7 2019 $ 35.Dt FFLUSH 3 36.Os 37.Sh NAME 38.Nm fflush , 39.Nm fpurge 40.Nd flush a stream 41.Sh SYNOPSIS 42.In stdio.h 43.Ft int 44.Fn fflush "FILE *stream" 45.Ft int 46.Fn fpurge "FILE *stream" 47.Sh DESCRIPTION 48The function 49.Fn fflush 50forces a write of all buffered data for the given output or update 51.Fa stream 52via the stream's underlying write function. 53The open status of the stream is unaffected. 54.Pp 55If the 56.Fa stream 57argument is 58.Dv NULL , 59.Fn fflush 60flushes 61.Em all 62open output streams. 63.Pp 64The function 65.Fn fpurge 66erases any input or output buffered in the given 67.Fa stream . 68For output streams this discards any unwritten output. 69For input streams this discards any input read from the underlying object 70but not yet obtained via 71.Xr getc 3 ; 72this includes any text pushed back via 73.Xr ungetc 3 . 74.Sh RETURN VALUES 75Upon successful completion 0 is returned. 76Otherwise, 77.Dv EOF 78is returned and the global variable 79.Va errno 80is set to indicate the error. 81.Sh ERRORS 82.Bl -tag -width Er 83.It Bq Er EBADF 84.Fa stream 85is not an open stream or, in the case of 86.Fn fflush , 87not a stream open for writing. 88.El 89.Pp 90The function 91.Fn fflush 92may also fail and set 93.Va errno 94for any of the errors specified for the routine 95.Xr write 2 . 96.Sh SEE ALSO 97.Xr write 2 , 98.Xr fclose 3 , 99.Xr fopen 3 , 100.Xr setvbuf 3 101.Sh STANDARDS 102The 103.Fn fflush 104function conforms to 105.St -ansiC . 106.Sh HISTORY 107A predecessor 108.Fn flush 109first appeared in 110.At v1 . 111The 112.Fn fflush 113function first appeared in 114.At v4 . 115