Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'newlib/libc/stdio/fflush.c')
-rw-r--r--newlib/libc/stdio/fflush.c27
1 files changed, 8 insertions, 19 deletions
diff --git a/newlib/libc/stdio/fflush.c b/newlib/libc/stdio/fflush.c
index 05084dde0..30ac9967f 100644
--- a/newlib/libc/stdio/fflush.c
+++ b/newlib/libc/stdio/fflush.c
@@ -51,15 +51,14 @@ ANSI C requires <<fflush>>.
No supporting OS subroutines are required.
*/
-#include <_ansi.h>
#include <stdio.h>
#include "local.h"
/* Flush a single file, or (if fp is NULL) all files. */
int
-_DEFUN(fflush, (fp),
- register FILE * fp)
+_DEFUN (fflush, (fp),
+ register FILE * fp)
{
register unsigned char *p;
register int n, t;
@@ -67,24 +66,14 @@ _DEFUN(fflush, (fp),
if (fp == NULL)
return _fwalk (_GLOBAL_REENT, fflush);
- CHECK_INIT (_REENT);
+ _flockfile(fp);
- _flockfile (fp);
+ CHECK_INIT (fp);
t = fp->_flags;
- if ((t & __SWR) == 0)
+ if ((t & __SWR) == 0 || (p = fp->_bf._base) == NULL)
{
- /* For a read stream, an fflush causes the next seek to be
- unoptimized (i.e. forces a system-level seek). This conforms
- to the POSIX and SUSv3 standards. */
- fp->_flags |= __SNPT;
- _funlockfile (fp);
- return 0;
- }
- if ((p = fp->_bf._base) == NULL)
- {
- /* Nothing to flush. */
- _funlockfile (fp);
+ _funlockfile(fp);
return 0;
}
n = fp->_p - p; /* write this much */
@@ -103,12 +92,12 @@ _DEFUN(fflush, (fp),
if (t <= 0)
{
fp->_flags |= __SERR;
- _funlockfile (fp);
+ _funlockfile(fp);
return EOF;
}
p += t;
n -= t;
}
- _funlockfile (fp);
+ _funlockfile(fp);
return 0;
}