2007-03-15 Eric Blake <ebb9@byu.net>
* libc/stdio/local.h (cantwrite, FREEUB, FREELB): Make reentrant. (__smakebuf): Rename... (__smakebuf_r): to this. * libc/stdio/fvwrite.h (__swsetup_r): Rename, from __swsetup. * libc/stdio/makebuf.c (__smakebuf): Detect failed asprint allocation, then rename... (__smakebuf_r): ...to this and fix reentrancy. * libc/stdio/wsetup.c (__swsetup): Detect failed asprintf allocation, then rename... (__swsetup_r): ...to this and fix reentrancy. * libc/stdio/fseek.c (_fseek_r): Fix reentrancy. * libc/stdio/refill.c (__srefill_r): Likewise. * libc/stdio/fclose.c (_fclose_r): Likewise. * libc/stdio/fread.c (_fread_r): Likewise. * libc/stdio/freopen.c (_freopen_r): Likewise. * libc/stdio/wbuf.c (__swbuf_r): Likewise. * libc/stdio64/fseeko64.c (_fseeko64_r): Likewise. * libc/stdio/fvwrite.c (__sfvwrite_r): Set errno properly on failed asprintf allocation, and fix reentrancy. * libc/stdio/snprintf.c (snprintf, _snprintf_r): Report overflow, as required by POSIX. * libc/stdio/sniprintf.c (sniprintf, _sniprintf_r): Likewise. * libc/stdio/vsnprintf.c (vsnprintf, _vsnprintf_r): Likewise. * libc/stdio/vsniprintf.c (vsniprintf, _vsniprintf_r): Likewise.
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1990 The Regents of the University of California.
|
||||
* Copyright (c) 1990, 2007 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
@ -35,7 +35,8 @@
|
||||
*/
|
||||
|
||||
_VOID
|
||||
_DEFUN(__smakebuf, (fp),
|
||||
_DEFUN(__smakebuf_r, (ptr, fp),
|
||||
struct _reent *ptr _AND
|
||||
register FILE *fp)
|
||||
{
|
||||
register size_t size, couldbetty;
|
||||
@ -49,9 +50,9 @@ _DEFUN(__smakebuf, (fp),
|
||||
return;
|
||||
}
|
||||
#ifdef __USE_INTERNAL_STAT64
|
||||
if (fp->_file < 0 || _fstat64_r (_REENT, fp->_file, &st) < 0)
|
||||
if (fp->_file < 0 || _fstat64_r (ptr, fp->_file, &st) < 0)
|
||||
#else
|
||||
if (fp->_file < 0 || _fstat_r (_REENT, fp->_file, &st) < 0)
|
||||
if (fp->_file < 0 || _fstat_r (ptr, fp->_file, &st) < 0)
|
||||
#endif
|
||||
{
|
||||
couldbetty = 0;
|
||||
@ -87,15 +88,18 @@ _DEFUN(__smakebuf, (fp),
|
||||
else
|
||||
fp->_flags |= __SNPT;
|
||||
}
|
||||
if ((p = _malloc_r (_REENT, size)) == NULL)
|
||||
if ((p = _malloc_r (ptr, size)) == NULL)
|
||||
{
|
||||
fp->_flags |= __SNBF;
|
||||
fp->_bf._base = fp->_p = fp->_nbuf;
|
||||
fp->_bf._size = 1;
|
||||
if (!(fp->_flags & __SSTR))
|
||||
{
|
||||
fp->_flags |= __SNBF;
|
||||
fp->_bf._base = fp->_p = fp->_nbuf;
|
||||
fp->_bf._size = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_REENT->__cleanup = _cleanup_r;
|
||||
ptr->__cleanup = _cleanup_r;
|
||||
fp->_flags |= __SMBF;
|
||||
fp->_bf._base = fp->_p = (unsigned char *) p;
|
||||
fp->_bf._size = size;
|
||||
|
Reference in New Issue
Block a user