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.
This commit is contained in:
parent
ae5b40a65b
commit
7a7e4d4d95
@ -1,3 +1,18 @@
|
|||||||
|
2014-01-17 Corinna Vinschen <vinschen@redhat.com>
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
2014-01-06 Sebastian Huber <sebastian.huber@embedded-brains.de>
|
2014-01-06 Sebastian Huber <sebastian.huber@embedded-brains.de>
|
||||||
|
|
||||||
* libc/include/sys/_default_fcntl.h (AT_FDCWD): Define according
|
* libc/include/sys/_default_fcntl.h (AT_FDCWD): Define according
|
||||||
|
@ -92,10 +92,15 @@ _DEFUN(_fclose_r, (rptr, fp),
|
|||||||
#endif
|
#endif
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
/* Unconditionally flush to allow special handling for seekable read
|
#ifdef _STDIO_BSD_SEMANTICS
|
||||||
files to reposition file to last byte processed as opposed to
|
/* BSD and Glibc systems only flush streams which have been written to. */
|
||||||
last byte read ahead into the buffer. */
|
r = (fp->_flags & __SWR) ? __sflush_r (rptr, fp) : 0;
|
||||||
r = _fflush_r (rptr, fp);
|
#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)
|
if (fp->_close != NULL && fp->_close (rptr, fp->_cookie) < 0)
|
||||||
r = EOF;
|
r = EOF;
|
||||||
if (fp->_flags & __SMBF)
|
if (fp->_flags & __SMBF)
|
||||||
|
@ -204,6 +204,19 @@ _DEFUN(__sflush_r, (ptr, fp),
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _STDIO_BSD_SEMANTICS
|
||||||
|
/* Called from _cleanup_r. At exit time, we don't need file locking,
|
||||||
|
and we don't want to move the underlying file pointer unless we're
|
||||||
|
writing. */
|
||||||
|
int
|
||||||
|
_DEFUN(__sflushw_r, (ptr, fp),
|
||||||
|
struct _reent *ptr _AND
|
||||||
|
register FILE *fp)
|
||||||
|
{
|
||||||
|
return (fp->_flags & __SWR) ? __sflush_r (ptr, fp) : 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int
|
int
|
||||||
_DEFUN(_fflush_r, (ptr, fp),
|
_DEFUN(_fflush_r, (ptr, fp),
|
||||||
struct _reent *ptr _AND
|
struct _reent *ptr _AND
|
||||||
|
@ -170,8 +170,17 @@ _VOID
|
|||||||
_DEFUN(_cleanup_r, (ptr),
|
_DEFUN(_cleanup_r, (ptr),
|
||||||
struct _reent *ptr)
|
struct _reent *ptr)
|
||||||
{
|
{
|
||||||
_CAST_VOID _fwalk(ptr, fclose);
|
#ifdef _STDIO_BSD_SEMANTICS
|
||||||
/* _CAST_VOID _fwalk (ptr, fflush); */ /* `cheating' */
|
/* BSD and Glibc systems only flush streams which have been written to
|
||||||
|
at exit time. Calling flush rather than close for speed, as on
|
||||||
|
the aforementioned systems. */
|
||||||
|
_CAST_VOID _fwalk_reent (ptr, __sflushw_r);
|
||||||
|
#else
|
||||||
|
/* Otherwise close files and flush read streams, too.
|
||||||
|
FIXME: Do we really have to call fclose rather than fflush for
|
||||||
|
RTOS compatibility? */
|
||||||
|
_CAST_VOID _fwalk_reent (ptr, _fclose_r);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef _REENT_ONLY
|
#ifndef _REENT_ONLY
|
||||||
|
@ -147,6 +147,9 @@ int _EXFUN(_svfiwprintf_r,(struct _reent *, FILE *, const wchar_t *,
|
|||||||
extern FILE *_EXFUN(__sfp,(struct _reent *));
|
extern FILE *_EXFUN(__sfp,(struct _reent *));
|
||||||
extern int _EXFUN(__sflags,(struct _reent *,_CONST char*, int*));
|
extern int _EXFUN(__sflags,(struct _reent *,_CONST char*, int*));
|
||||||
extern int _EXFUN(__sflush_r,(struct _reent *,FILE *));
|
extern int _EXFUN(__sflush_r,(struct _reent *,FILE *));
|
||||||
|
#ifdef _STDIO_BSD_SEMANTICS
|
||||||
|
extern int _EXFUN(__sflushw_r,(struct _reent *,FILE *));
|
||||||
|
#endif
|
||||||
extern int _EXFUN(__srefill_r,(struct _reent *,FILE *));
|
extern int _EXFUN(__srefill_r,(struct _reent *,FILE *));
|
||||||
extern _READ_WRITE_RETURN_TYPE _EXFUN(__sread,(struct _reent *, void *, char *,
|
extern _READ_WRITE_RETURN_TYPE _EXFUN(__sread,(struct _reent *, void *, char *,
|
||||||
_READ_WRITE_BUFSIZE_TYPE));
|
_READ_WRITE_BUFSIZE_TYPE));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user