First public contribution.
3 * Portions Copyright (c) 1990-2006 Nokia Corporation and/or its subsidiary(-ies).
8 * Copyright (c) 1990 The Regents of the University of California.
11 * Redistribution and use in source and binary forms are permitted
12 * provided that the above copyright notice and this paragraph are
13 * duplicated in all such forms and that any documentation,
14 * advertising materials, and other materials related to such
15 * distribution and use acknowledge that the software was developed
16 * by the University of California, Berkeley. The name of the
17 * University may not be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
26 <<fflush>>---flush buffered file output
33 int fflush(FILE *<[fp]>);
41 The <<stdio>> output functions can buffer output before delivering it
42 to the host system, in order to minimize the overhead of system calls.
44 Use <<fflush>> to deliver any such pending output (for the file
45 or stream identified by <[fp]>) to the host system.
47 If <[fp]> is <<NULL>>, <<fflush>> delivers pending output from all
51 <<fflush>> returns <<0>> unless it encounters a write error; in that
52 situation, it returns <<EOF>>.
55 ANSI C requires <<fflush>>.
57 No supporting OS subroutines are required.
64 Flush a stream. If the given stream has been opened for writing operations
65 the output buffer is phisically written to the file. If the stream was open
66 for reading operations the content of the input buffer is cleared. The stream
67 remains open after this call.
69 @param fp pointer to an open file.
71 @return On Success, a 0 value indicates success.
72 On Failure, EOF is returned and errno may be set.
77 register unsigned char *p;
82 struct _reent *r = _REENT2;
84 return EOF; // Memory for library globals is not allocated (errno not set).
85 return _fwalk (r, fflush);
90 if ((t & __SWR) == 0 || (p = fp->_bf._base) == NULL)
92 n = fp->_p - p; /* write this much */
95 * Set these immediately to avoid problems with longjmp
96 * and to allow exchange buffering (via setvbuf) in user
100 fp->_w = t & (__SLBF | __SNBF) ? 0 : fp->_bf._size;
104 t = (*fp->_write) (fp->_cookie, (char *) p, n);
107 fp->_flags |= __SERR;