Implement funopen, fopencookie.
* libc/include/sys/reent.h (struct __sFILE, struct __sFILE64): Switch to reentrant callbacks. * libc/include/stdio.h (funopen): Fix declaration. (fopencookie): Declare. * libc/stdio/local.h (__sread, __swrite, __sseek, __sclose) (__sseek64, __swrite64): Fix prototypes. [__SCLE]: Pull in setmode declaration. * libc/stdio/stdio.c (__sread, __swrite, __sseek, __sclose): Fix reentrancy. * libc/stdio64/stdio64.c (__sseek64_r, __swrite64_r): Delete. (__sseek64, __swrite64): Fix reentrancy. * libc/stdio/fseek.c (_fseek_r): Account for overflow, and fix reentrancy. * libc/stdio/ftell.c (_ftell_r): Likewise. * libc/stdio/flags.c (__sflags): Don't lose __SAPP on "a+". * libc/stdio/fclose.c (_fclose_r): Fix reentrancy. * libc/stdio/freopen.c (_freopen_r): Likewise. * libc/stdio/fvwrite.c (__sfvwrite_r): Likewise. * libc/stdio/refill.c (__srefill_r): Likewise. * libc/stdio/siscanf.c (eofread): Likewise. * libc/stdio/sscanf.c (eofread): Likewise. * libc/stdio/vsiscanf.c (eofread1): Likewise. * libc/stdio/vsscanf.c (eofread1): Likewise. * libc/stdio64/freopen64.c (_freopen64_r): Likewise. * libc/stdio64/fseeko64.c (_fseeko64_r): Likewise. * libc/stdio64/ftello64.c (_ftello64_r): Likewise. * libc/stdio/fflush.c (fflush): Improve reentrancy, although more could be fixed. * libc/stdio/fopencookie.c (_fopencookie_r, fopencookie): New file. * libc/stdio/funopen.c (_funopen_r, funopen): New file. * libc/stdio/Makefile.am (ELIX_4_SOURCES, CHEWOUT_FILES): Build new files. * libc/stdio/Makefile.in: Regenerate.
This commit is contained in:
@ -106,7 +106,7 @@ _DEFUN (_freopen64_r, (ptr, file, mode, fp),
|
||||
if ((flags = __sflags (ptr, mode, &oflags)) == 0)
|
||||
{
|
||||
_funlockfile(fp);
|
||||
(void) _fclose_r (ptr, fp);
|
||||
_fclose_r (ptr, fp);
|
||||
__sfp_lock_release ();
|
||||
return NULL;
|
||||
}
|
||||
@ -124,13 +124,13 @@ _DEFUN (_freopen64_r, (ptr, file, mode, fp),
|
||||
else
|
||||
{
|
||||
if (fp->_flags & __SWR)
|
||||
(void) fflush (fp);
|
||||
fflush (fp);
|
||||
/*
|
||||
* If close is NULL, closing is a no-op, hence pointless.
|
||||
* If file is NULL, the file should not be closed.
|
||||
*/
|
||||
if (fp->_close != NULL && file != NULL)
|
||||
(void) (*fp->_close) (fp->_cookie);
|
||||
fp->_close (ptr, fp->_cookie);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -154,10 +154,10 @@ _DEFUN (_freopen64_r, (ptr, file, mode, fp),
|
||||
*/
|
||||
f = fp->_file;
|
||||
if ((oldflags = _fcntl_r (ptr, f, F_GETFL, 0)) == -1
|
||||
|| ! ((oldflags & O_ACCMODE) == O_RDWR
|
||||
|| ((oldflags ^ oflags) & O_ACCMODE) == 0)
|
||||
|| _fcntl_r (ptr, f, F_SETFL, oflags) == -1)
|
||||
f = -1;
|
||||
|| ! ((oldflags & O_ACCMODE) == O_RDWR
|
||||
|| ((oldflags ^ oflags) & O_ACCMODE) == 0)
|
||||
|| _fcntl_r (ptr, f, F_SETFL, oflags) == -1)
|
||||
f = -1;
|
||||
#else
|
||||
/* We cannot modify without fcntl support. */
|
||||
f = -1;
|
||||
@ -168,16 +168,16 @@ _DEFUN (_freopen64_r, (ptr, file, mode, fp),
|
||||
* F_SETFL doesn't change textmode. Don't mess with modes of ttys.
|
||||
*/
|
||||
if (0 <= f && ! isatty (f)
|
||||
&& setmode (f, oflags & (O_BINARY | O_TEXT)) == -1)
|
||||
f = -1;
|
||||
&& setmode (f, oflags & (O_BINARY | O_TEXT)) == -1)
|
||||
f = -1;
|
||||
#endif
|
||||
|
||||
if (f < 0)
|
||||
{
|
||||
e = EBADF;
|
||||
if (fp->_close != NULL)
|
||||
(void) (*fp->_close) (fp->_cookie);
|
||||
}
|
||||
{
|
||||
e = EBADF;
|
||||
if (fp->_close != NULL)
|
||||
fp->_close (ptr, fp->_cookie);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -104,7 +104,7 @@ _DEFUN (_fseeko64_r, (ptr, fp, offset, whence),
|
||||
_off64_t offset _AND
|
||||
int whence)
|
||||
{
|
||||
_fpos64_t _EXFUN ((*seekfn), (void *, _fpos64_t, int));
|
||||
_fpos64_t _EXFUN ((*seekfn), (struct _reent *, void *, _fpos64_t, int));
|
||||
_fpos64_t target, curoff;
|
||||
size_t n;
|
||||
|
||||
@ -155,7 +155,7 @@ _DEFUN (_fseeko64_r, (ptr, fp, offset, whence),
|
||||
curoff = fp->_offset;
|
||||
else
|
||||
{
|
||||
curoff = (*seekfn) (fp->_cookie, (_fpos64_t) 0, SEEK_CUR);
|
||||
curoff = seekfn (ptr, fp->_cookie, (_fpos64_t) 0, SEEK_CUR);
|
||||
if (curoff == -1L)
|
||||
{
|
||||
_funlockfile(fp);
|
||||
@ -238,7 +238,7 @@ _DEFUN (_fseeko64_r, (ptr, fp, offset, whence),
|
||||
curoff = fp->_offset;
|
||||
else
|
||||
{
|
||||
curoff = (*seekfn) (fp->_cookie, (_fpos64_t)0, SEEK_CUR);
|
||||
curoff = seekfn (ptr, fp->_cookie, (_fpos64_t)0, SEEK_CUR);
|
||||
if (curoff == POS_ERR)
|
||||
goto dumb;
|
||||
}
|
||||
@ -299,7 +299,7 @@ _DEFUN (_fseeko64_r, (ptr, fp, offset, whence),
|
||||
*/
|
||||
|
||||
curoff = target & ~((_fpos64_t)(fp->_blksize - 1));
|
||||
if ((*seekfn) (fp->_cookie, curoff, SEEK_SET) == POS_ERR)
|
||||
if (seekfn (ptr, fp->_cookie, curoff, SEEK_SET) == POS_ERR)
|
||||
goto dumb;
|
||||
fp->_r = 0;
|
||||
fp->_p = fp->_bf._base;
|
||||
@ -323,7 +323,7 @@ _DEFUN (_fseeko64_r, (ptr, fp, offset, whence),
|
||||
*/
|
||||
|
||||
dumb:
|
||||
if (fflush (fp) || (*seekfn) (fp->_cookie, offset, whence) == POS_ERR)
|
||||
if (fflush (fp) || seekfn (ptr, fp->_cookie, offset, whence) == POS_ERR)
|
||||
{
|
||||
_funlockfile(fp);
|
||||
return EOF;
|
||||
|
@ -111,7 +111,7 @@ _DEFUN (_ftello64_r, (ptr, fp),
|
||||
pos = fp->_offset;
|
||||
else
|
||||
{
|
||||
pos = (*fp->_seek64) (fp->_cookie, (_fpos64_t) 0, SEEK_CUR);
|
||||
pos = fp->_seek64 (ptr, fp->_cookie, (_fpos64_t) 0, SEEK_CUR);
|
||||
if (pos == -1L)
|
||||
{
|
||||
_funlockfile(fp);
|
||||
|
@ -26,11 +26,11 @@
|
||||
|
||||
#ifdef __LARGE64_FILES
|
||||
_fpos64_t
|
||||
__sseek64_r (ptr, cookie, offset, whence)
|
||||
struct _reent *ptr;
|
||||
_PTR cookie;
|
||||
_fpos64_t offset;
|
||||
int whence;
|
||||
_DEFUN(__sseek64, (ptr, cookie, offset, whence),
|
||||
struct _reent *ptr _AND
|
||||
void *cookie _AND
|
||||
_fpos64_t offset _AND
|
||||
int whence)
|
||||
{
|
||||
register FILE *fp = (FILE *) cookie;
|
||||
register _off64_t ret;
|
||||
@ -47,11 +47,11 @@ __sseek64_r (ptr, cookie, offset, whence)
|
||||
}
|
||||
|
||||
_READ_WRITE_RETURN_TYPE
|
||||
__swrite64_r (ptr, cookie, buf, n)
|
||||
struct _reent *ptr;
|
||||
_PTR cookie;
|
||||
char _CONST *buf;
|
||||
int n;
|
||||
_DEFUN(__swrite64, (ptr, cookie, buf, n),
|
||||
struct _reent *ptr _AND
|
||||
void *cookie _AND
|
||||
char const *buf _AND
|
||||
int n)
|
||||
{
|
||||
register FILE *fp = (FILE *) cookie;
|
||||
int w;
|
||||
@ -78,26 +78,4 @@ __swrite64_r (ptr, cookie, buf, n)
|
||||
return w;
|
||||
}
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
_fpos64_t
|
||||
__sseek64 (cookie, offset, whence)
|
||||
_PTR cookie;
|
||||
_fpos64_t offset;
|
||||
int whence;
|
||||
{
|
||||
return __sseek64_r (_REENT, cookie, offset, whence);
|
||||
}
|
||||
|
||||
_READ_WRITE_RETURN_TYPE
|
||||
__swrite64 (cookie, buf, n)
|
||||
_PTR cookie;
|
||||
char _CONST *buf;
|
||||
int n;
|
||||
{
|
||||
return __swrite64_r (_REENT, cookie, buf, n);
|
||||
}
|
||||
|
||||
#endif /* !_REENT_ONLY */
|
||||
|
||||
#endif /* __LARGE64_FILES */
|
||||
|
||||
|
Reference in New Issue
Block a user