Fix fflush issues.
* libc/stdio/fflush.c (_fflush_r): New function. (fflush): Fix reentrancy and large offset behavior. * libc/include/stdio.h (_fflush_r): Add prototype. * libc/stdio/fclose.c (_fclose_r): All fflush callers changed. * libc/stdio/freopen.c (_freopen_r): Likewise. * libc/stdio/fseek.c (_fseek_r): Likewise. * libc/stdio/ftell.c (_ftell_r): Likewise. * libc/stdio/fvwrite.c (__sfvwrite_r): Likewise. * libc/stdio/refill.c (__srefill_r): Likewise. * libc/stdio/setvbuf.c (setvbuf): Likewise. * libc/stdio/ungetc.c (_ungetc_r): Likewise. * libc/stdio/vfprintf.c (__sbprintf): Likewise. * libc/stdio/wbuf.c (__swbuf_r): Likewise. * libc/stdio64/freopen64.c (_freopen64_r): Likewise. * libc/stdio64/fseeko64.c (_fseeko64_r): Likewise. Defer to 32-bit version if not large file. * libc/stdio64/ftello64.c (_ftello64_r): Likewise. * libc/stdio64/tmpfile64.c (_tmpfile64_r): Avoid compile warning.
This commit is contained in:
@ -111,11 +111,22 @@ _DEFUN (_fseeko64_r, (ptr, fp, offset, whence),
|
||||
struct stat64 st;
|
||||
int havepos;
|
||||
|
||||
/* Only do 64-bit seek on large file. */
|
||||
if (!(fp->_flags & __SL64))
|
||||
{
|
||||
if ((_off_t) offset != offset)
|
||||
{
|
||||
ptr->_errno = EOVERFLOW;
|
||||
return EOF;
|
||||
}
|
||||
return (_off64_t) _fseeko_r (ptr, fp, offset, whence);
|
||||
}
|
||||
|
||||
/* Make sure stdio is set up. */
|
||||
|
||||
CHECK_INIT (ptr, fp);
|
||||
|
||||
_flockfile(fp);
|
||||
_flockfile (fp);
|
||||
|
||||
curoff = fp->_offset;
|
||||
|
||||
@ -125,12 +136,12 @@ _DEFUN (_fseeko64_r, (ptr, fp, offset, whence),
|
||||
if (fp->_flags & __SAPP && fp->_flags & __SWR)
|
||||
{
|
||||
/* So flush the buffer and seek to the end. */
|
||||
fflush (fp);
|
||||
_fflush_r (ptr, fp);
|
||||
}
|
||||
|
||||
/* Have to be able to seek. */
|
||||
|
||||
if ((seekfn = fp->_seek64) == NULL || !(fp->_flags & __SL64))
|
||||
if ((seekfn = fp->_seek64) == NULL)
|
||||
{
|
||||
ptr->_errno = ESPIPE; /* ??? */
|
||||
_funlockfile(fp);
|
||||
@ -150,7 +161,7 @@ _DEFUN (_fseeko64_r, (ptr, fp, offset, whence),
|
||||
* we have to first find the current stream offset a la
|
||||
* ftell (see ftell for details).
|
||||
*/
|
||||
fflush(fp); /* may adjust seek offset on append stream */
|
||||
_fflush_r (ptr, fp); /* may adjust seek offset on append stream */
|
||||
if (fp->_flags & __SOFF)
|
||||
curoff = fp->_offset;
|
||||
else
|
||||
@ -323,7 +334,8 @@ _DEFUN (_fseeko64_r, (ptr, fp, offset, whence),
|
||||
*/
|
||||
|
||||
dumb:
|
||||
if (fflush (fp) || seekfn (ptr, fp->_cookie, offset, whence) == POS_ERR)
|
||||
if (_fflush_r (ptr, fp)
|
||||
|| seekfn (ptr, fp->_cookie, offset, whence) == POS_ERR)
|
||||
{
|
||||
_funlockfile(fp);
|
||||
return EOF;
|
||||
|
Reference in New Issue
Block a user