From 7a7e4d4d95e878c62ea5b642da864018b50aae21 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Fri, 17 Jan 2014 10:55:32 +0000 Subject: Introduce _STDIO_BSD_SEMANTICS flag to switch fclose/exit file flushing semantics from POSIX to BSD. * libc/stdio/fclose.c (_fclose_r): Conditionalize file flushing on _STDIO_BSD_SEMANTICS. Call __sflush_r rather than _fflush_r. Add comment. * libc/stdio/fflush.c (__sflushw_r): New function, only available if _STDIO_BSD_SEMANTICS is defined. * libc/stdio/findfp.c (_cleanup_r): Call _fwalk_reent rather than _fwalk. Conditionalize cleanup function call on _STDIO_BSD_SEMANTICS. Add comments. Add FIXME. * libc/stdio/local.h (__sflushw_r): Declare if _STDIO_BSD_SEMANTICS is defined. --- newlib/libc/stdio/fclose.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'newlib/libc/stdio/fclose.c') diff --git a/newlib/libc/stdio/fclose.c b/newlib/libc/stdio/fclose.c index fd054feaa..cd271c490 100644 --- a/newlib/libc/stdio/fclose.c +++ b/newlib/libc/stdio/fclose.c @@ -92,10 +92,15 @@ _DEFUN(_fclose_r, (rptr, fp), #endif return (0); } - /* Unconditionally flush to allow special handling for seekable read - files to reposition file to last byte processed as opposed to - last byte read ahead into the buffer. */ - r = _fflush_r (rptr, fp); +#ifdef _STDIO_BSD_SEMANTICS + /* BSD and Glibc systems only flush streams which have been written to. */ + r = (fp->_flags & __SWR) ? __sflush_r (rptr, fp) : 0; +#else + /* Follow POSIX semantics exactly. Unconditionally flush to allow + special handling for seekable read files to reposition file to last + byte processed as opposed to last byte read ahead into the buffer. */ + r = __sflush_r (rptr, fp); +#endif if (fp->_close != NULL && fp->_close (rptr, fp->_cookie) < 0) r = EOF; if (fp->_flags & __SMBF) -- cgit v1.2.3