mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-02-01 03:50:28 +08:00
2005-02-07 Antony King <antony.king@st.com>
* libc/stdio/clearerr.c (clearerr): Ensure CHECK_INIT() is called before _flockfile to prevent lock object use before initialisation. _REENT_SMALL_CHECK_INIT() and CHECK_INIT() take a struct _reent * instead of a FILE *. * libc/stdio/fclose.c (_fclose_r): Ditto. * libc/stdio/feof.c (feof): Ditto. * libc/stdio/ferror.c (ferror): Ditto. * libc/stdio/fflush.c (fflush): Ditto. * libc/stdio/fgetc.c (fgetc): Ditto. * libc/stdio/fgets.c (fgets): Ditto. * libc/stdio/fileno.c (fileno): Ditto. * libc/stdio/fputc.c (fputc): Ditto. * libc/stdio/fputs.c (fputs): Ditto. * libc/stdio/fread.c (fread): Ditto. * libc/stdio/freopen.c (_freopen_r): Ditto. * libc/stdio/fseek.c (_fseek_r): Ditto. * libc/stdio/ftell.c (_ftell_r): Ditto. * libc/stdio/fwrite.c (fwrite): Ditto. * libc/stdio/getc.c (getc): Ditto. * libc/stdio/getdelim.c (__getdelim): Ditto. * libc/stdio/putc.c (putc): Ditto. * libc/stdio/setvbuf.c (setvbuf): Ditto. * libc/stdio/ungetc.c (_ungetc_r): Ditto. * libc/stdio/vfprintf.c (_VFPRINTF_R): Ditto. * libc/stdio64/freopen64.c (_freopen64_r): Ditto. * libc/stdio64/fseeko64.c (_fseeko64_r): Ditto. * libc/stdio64/ftello64.c (_ftello64_r): Ditto. * libc/stdio/local.h (CHECK_INIT): Argument is now a struct _reent * instead of a FILE * and so replace incorrect use of _REENT with argument. * libc/sys/arm/syscalls.c (CHECK_INIT): Ditto. * libc/stdio/getchar.c (getchar): _REENT_SMALL_CHECK_INIT() and CHECK_INIT() take a struct _reent * instead of a FILE *. * libc/stdio/iprintf.c (iprintf, _iprintf_r): Ditto. * libc/stdio/iscanf.c (iscanf, _iscanf_r): Ditto. * libc/stdio/perror.c (perror): Ditto. * libc/stdio/printf.c (printf, _printf_r): Ditto. * libc/stdio/putchar.c (putchar): Ditto. * libc/stdio/puts.c (puts): Ditto. * libc/stdio/refill.c (__srefill): Ditto. * libc/stdio/scanf.c (scanf, _scanf_r): Ditto. * libc/stdio/vfscanf.c (VFSCANF, _VFSCANF_R): Ditto. * libc/stdio/viprintf.c (viprintf, _viprintf_r): Ditto. * libc/stdio/viscanf.c (viscanf, _viscanf_r): Ditto. * libc/stdio/vprintf.c (vprintf, _vprintf_r): Ditto. * libc/stdio/vscanf.c (vscanf, _vscanf_r): Ditto. * libc/stdio/wbuf.c (__swbuf): Ditto. * libc/stdio/wsetup.c (__swsetup): Ditto. * libc/stdlib/mallocr.c (malloc_stats): Ditto. * libc/stdlib/mstats.c (_mstats_r): Ditto. * libc/include/sys/reent.h (_REENT_SMALL_CHECK_INIT): Ditto. * libc/machine/powerpc/vfscanf.c (vfscanf): Ditto. * libc/stdio/fgetpos.c (_fgetpos_r): Removed unnecessary calls to _flockfile and _funlockfile; rely on locking in _ftell_r. * libc/stdio64/fgetpos64.c (_fgetpos64_r): Ditto (_ftello64_r). * libc/machine/powerpc/vfprintf.c (__sbprintf): Removed unnecessary initialision of _data field in FILE structure. * libc/machine/powerpc/vfprintf.c (VFPRINTF): Added CHECK_INIT() call.
This commit is contained in:
parent
3d91567088
commit
1159e0fd94
@ -1,3 +1,64 @@
|
||||
2005-02-07 Antony King <antony.king@st.com>
|
||||
|
||||
* libc/stdio/clearerr.c (clearerr): Ensure CHECK_INIT() is
|
||||
called before _flockfile to prevent lock object use before
|
||||
initialisation. _REENT_SMALL_CHECK_INIT() and CHECK_INIT()
|
||||
take a struct _reent * instead of a FILE *.
|
||||
* libc/stdio/fclose.c (_fclose_r): Ditto.
|
||||
* libc/stdio/feof.c (feof): Ditto.
|
||||
* libc/stdio/ferror.c (ferror): Ditto.
|
||||
* libc/stdio/fflush.c (fflush): Ditto.
|
||||
* libc/stdio/fgetc.c (fgetc): Ditto.
|
||||
* libc/stdio/fgets.c (fgets): Ditto.
|
||||
* libc/stdio/fileno.c (fileno): Ditto.
|
||||
* libc/stdio/fputc.c (fputc): Ditto.
|
||||
* libc/stdio/fputs.c (fputs): Ditto.
|
||||
* libc/stdio/fread.c (fread): Ditto.
|
||||
* libc/stdio/freopen.c (_freopen_r): Ditto.
|
||||
* libc/stdio/fseek.c (_fseek_r): Ditto.
|
||||
* libc/stdio/ftell.c (_ftell_r): Ditto.
|
||||
* libc/stdio/fwrite.c (fwrite): Ditto.
|
||||
* libc/stdio/getc.c (getc): Ditto.
|
||||
* libc/stdio/getdelim.c (__getdelim): Ditto.
|
||||
* libc/stdio/putc.c (putc): Ditto.
|
||||
* libc/stdio/setvbuf.c (setvbuf): Ditto.
|
||||
* libc/stdio/ungetc.c (_ungetc_r): Ditto.
|
||||
* libc/stdio/vfprintf.c (_VFPRINTF_R): Ditto.
|
||||
* libc/stdio64/freopen64.c (_freopen64_r): Ditto.
|
||||
* libc/stdio64/fseeko64.c (_fseeko64_r): Ditto.
|
||||
* libc/stdio64/ftello64.c (_ftello64_r): Ditto.
|
||||
* libc/stdio/local.h (CHECK_INIT): Argument is now a struct
|
||||
_reent * instead of a FILE * and so replace incorrect use of
|
||||
_REENT with argument.
|
||||
* libc/sys/arm/syscalls.c (CHECK_INIT): Ditto.
|
||||
* libc/stdio/getchar.c (getchar): _REENT_SMALL_CHECK_INIT() and
|
||||
CHECK_INIT() take a struct _reent * instead of a FILE *.
|
||||
* libc/stdio/iprintf.c (iprintf, _iprintf_r): Ditto.
|
||||
* libc/stdio/iscanf.c (iscanf, _iscanf_r): Ditto.
|
||||
* libc/stdio/perror.c (perror): Ditto.
|
||||
* libc/stdio/printf.c (printf, _printf_r): Ditto.
|
||||
* libc/stdio/putchar.c (putchar): Ditto.
|
||||
* libc/stdio/puts.c (puts): Ditto.
|
||||
* libc/stdio/refill.c (__srefill): Ditto.
|
||||
* libc/stdio/scanf.c (scanf, _scanf_r): Ditto.
|
||||
* libc/stdio/vfscanf.c (VFSCANF, _VFSCANF_R): Ditto.
|
||||
* libc/stdio/viprintf.c (viprintf, _viprintf_r): Ditto.
|
||||
* libc/stdio/viscanf.c (viscanf, _viscanf_r): Ditto.
|
||||
* libc/stdio/vprintf.c (vprintf, _vprintf_r): Ditto.
|
||||
* libc/stdio/vscanf.c (vscanf, _vscanf_r): Ditto.
|
||||
* libc/stdio/wbuf.c (__swbuf): Ditto.
|
||||
* libc/stdio/wsetup.c (__swsetup): Ditto.
|
||||
* libc/stdlib/mallocr.c (malloc_stats): Ditto.
|
||||
* libc/stdlib/mstats.c (_mstats_r): Ditto.
|
||||
* libc/include/sys/reent.h (_REENT_SMALL_CHECK_INIT): Ditto.
|
||||
* libc/machine/powerpc/vfscanf.c (vfscanf): Ditto.
|
||||
* libc/stdio/fgetpos.c (_fgetpos_r): Removed unnecessary calls
|
||||
to _flockfile and _funlockfile; rely on locking in _ftell_r.
|
||||
* libc/stdio64/fgetpos64.c (_fgetpos64_r): Ditto (_ftello64_r).
|
||||
* libc/machine/powerpc/vfprintf.c (__sbprintf): Removed unnecessary
|
||||
initialision of _data field in FILE structure.
|
||||
* libc/machine/powerpc/vfprintf.c (VFPRINTF): Added CHECK_INIT() call.
|
||||
|
||||
2005-02-07 Jeff Johnston <jjohnstn@redhat.com>
|
||||
|
||||
* libc/stdio/findfp.c (__sinit): Protect with new lock.
|
||||
|
@ -158,9 +158,9 @@ struct __sFILE_fake {
|
||||
struct _reent *_data;
|
||||
};
|
||||
/* CHECK_INIT() comes from stdio/local.h; be sure to include that. */
|
||||
# define _REENT_SMALL_CHECK_INIT(fp) CHECK_INIT(fp)
|
||||
# define _REENT_SMALL_CHECK_INIT(ptr) CHECK_INIT(ptr)
|
||||
#else
|
||||
# define _REENT_SMALL_CHECK_INIT(fp) /* nothing */
|
||||
# define _REENT_SMALL_CHECK_INIT(ptr) /* nothing */
|
||||
#endif
|
||||
|
||||
struct __sFILE {
|
||||
|
@ -239,7 +239,6 @@ __sbprintf(fp, fmt, ap)
|
||||
unsigned char buf[BUFSIZ];
|
||||
|
||||
/* copy the important variables */
|
||||
fake._data = fp->_data;
|
||||
fake._flags = fp->_flags & ~__SNBF;
|
||||
fake._file = fp->_file;
|
||||
fake._cookie = fp->_cookie;
|
||||
@ -322,6 +321,7 @@ _DEFUN (VFPRINTF, (fp, fmt0, ap),
|
||||
_CONST char *fmt0 _AND
|
||||
va_list ap)
|
||||
{
|
||||
CHECK_INIT (_REENT);
|
||||
return _VFPRINTF_R (_REENT, fp, fmt0, ap);
|
||||
}
|
||||
|
||||
|
@ -224,8 +224,8 @@ _DEFUN (vfscanf, (fp, fmt, ap),
|
||||
_CONST char *fmt _AND
|
||||
va_list ap)
|
||||
{
|
||||
CHECK_INIT(fp);
|
||||
return __svfscanf_r (fp->_data, fp, fmt, ap);
|
||||
CHECK_INIT(_REENT);
|
||||
return __svfscanf_r (_REENT, fp, fmt, ap);
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -54,12 +54,17 @@ No supporting OS subroutines are required.
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <stdio.h>
|
||||
#include "local.h"
|
||||
|
||||
/* A subroutine version of the macro clearerr. */
|
||||
|
||||
#undef clearerr
|
||||
|
||||
_VOID
|
||||
_DEFUN(clearerr, (fp),
|
||||
FILE * fp)
|
||||
{
|
||||
CHECK_INIT(_REENT);
|
||||
_flockfile (fp);
|
||||
__sclearerr (fp);
|
||||
_funlockfile (fp);
|
||||
|
@ -76,10 +76,10 @@ _DEFUN(_fclose_r, (rptr, fp),
|
||||
|
||||
__sfp_lock_acquire ();
|
||||
|
||||
CHECK_INIT (rptr);
|
||||
|
||||
_flockfile (fp);
|
||||
|
||||
CHECK_INIT (fp);
|
||||
|
||||
if (fp->_flags == 0) /* not open! */
|
||||
{
|
||||
_funlockfile (fp);
|
||||
|
@ -46,6 +46,9 @@ No supporting OS subroutines are required.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "local.h"
|
||||
|
||||
/* A subroutine version of the macro feof. */
|
||||
|
||||
#undef feof
|
||||
|
||||
@ -54,6 +57,7 @@ _DEFUN(feof, (fp),
|
||||
FILE * fp)
|
||||
{
|
||||
int result;
|
||||
CHECK_INIT(_REENT);
|
||||
_flockfile (fp);
|
||||
result = __sfeof (fp);
|
||||
_funlockfile (fp);
|
||||
|
@ -55,6 +55,7 @@ static char sccsid[] = "%W% (Berkeley) %G%";
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <stdio.h>
|
||||
#include "local.h"
|
||||
|
||||
/* A subroutine version of the macro ferror. */
|
||||
|
||||
@ -65,6 +66,7 @@ _DEFUN(ferror, (fp),
|
||||
FILE * fp)
|
||||
{
|
||||
int result;
|
||||
CHECK_INIT(_REENT);
|
||||
_flockfile (fp);
|
||||
result = __sferror (fp);
|
||||
_funlockfile (fp);
|
||||
|
@ -67,9 +67,9 @@ _DEFUN(fflush, (fp),
|
||||
if (fp == NULL)
|
||||
return _fwalk (_GLOBAL_REENT, fflush);
|
||||
|
||||
_flockfile (fp);
|
||||
CHECK_INIT (_REENT);
|
||||
|
||||
CHECK_INIT (fp);
|
||||
_flockfile (fp);
|
||||
|
||||
t = fp->_flags;
|
||||
if ((t & __SWR) == 0 || (p = fp->_bf._base) == NULL)
|
||||
|
@ -55,12 +55,14 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <stdio.h>
|
||||
#include "local.h"
|
||||
|
||||
int
|
||||
_DEFUN(fgetc, (fp),
|
||||
FILE * fp)
|
||||
{
|
||||
int result;
|
||||
CHECK_INIT(_REENT);
|
||||
_flockfile (fp);
|
||||
result = __sgetc (fp);
|
||||
_funlockfile (fp);
|
||||
|
@ -81,15 +81,12 @@ _DEFUN(_fgetpos_r, (ptr, fp, pos),
|
||||
FILE * fp _AND
|
||||
_fpos_t * pos)
|
||||
{
|
||||
_flockfile (fp);
|
||||
*pos = _ftell_r (ptr, fp);
|
||||
|
||||
if (*pos != -1)
|
||||
{
|
||||
_funlockfile (fp);
|
||||
return 0;
|
||||
}
|
||||
_funlockfile (fp);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -80,6 +80,8 @@ _DEFUN(fgets, (buf, n, fp),
|
||||
|
||||
s = buf;
|
||||
|
||||
CHECK_INIT(_REENT);
|
||||
|
||||
_flockfile (fp);
|
||||
#ifdef __SCLE
|
||||
if (fp->_flags & __SCLE)
|
||||
|
@ -54,8 +54,8 @@ _DEFUN(fileno, (f),
|
||||
FILE * f)
|
||||
{
|
||||
int result;
|
||||
CHECK_INIT (_REENT);
|
||||
_flockfile (f);
|
||||
CHECK_INIT (f);
|
||||
result = __sfileno (f);
|
||||
_funlockfile (f);
|
||||
return result;
|
||||
|
@ -59,6 +59,7 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <stdio.h>
|
||||
#include "local.h"
|
||||
|
||||
int
|
||||
_DEFUN(fputc, (ch, file),
|
||||
@ -66,6 +67,7 @@ _DEFUN(fputc, (ch, file),
|
||||
FILE * file)
|
||||
{
|
||||
int result;
|
||||
CHECK_INIT(_REENT);
|
||||
_flockfile (file);
|
||||
result = putc (ch, file);
|
||||
_funlockfile (file);
|
||||
|
@ -51,6 +51,7 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "fvwrite.h"
|
||||
#include "local.h"
|
||||
|
||||
/*
|
||||
* Write the given string to the given file.
|
||||
@ -69,6 +70,9 @@ _DEFUN(fputs, (s, fp),
|
||||
iov.iov_len = uio.uio_resid = strlen (s);
|
||||
uio.uio_iov = &iov;
|
||||
uio.uio_iovcnt = 1;
|
||||
|
||||
CHECK_INIT(_REENT);
|
||||
|
||||
_flockfile (fp);
|
||||
result = __sfvwrite (fp, &uio);
|
||||
_funlockfile (fp);
|
||||
|
@ -125,6 +125,8 @@ _DEFUN(fread, (buf, size, count, fp),
|
||||
if ((resid = count * size) == 0)
|
||||
return 0;
|
||||
|
||||
CHECK_INIT(_REENT);
|
||||
|
||||
_flockfile (fp);
|
||||
if (fp->_r < 0)
|
||||
fp->_r = 0;
|
||||
|
@ -91,9 +91,9 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp),
|
||||
|
||||
__sfp_lock_acquire ();
|
||||
|
||||
_flockfile (fp);
|
||||
CHECK_INIT (ptr);
|
||||
|
||||
CHECK_INIT (fp);
|
||||
_flockfile (fp);
|
||||
|
||||
if ((flags = __sflags (ptr, mode, &oflags)) == 0)
|
||||
{
|
||||
|
@ -129,11 +129,11 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
|
||||
struct stat st;
|
||||
int havepos;
|
||||
|
||||
_flockfile (fp);
|
||||
|
||||
/* Make sure stdio is set up. */
|
||||
|
||||
CHECK_INIT (fp);
|
||||
CHECK_INIT (ptr);
|
||||
|
||||
_flockfile (fp);
|
||||
|
||||
/* If we've been doing some writing, and we're in append mode
|
||||
then we don't really know where the filepos is. */
|
||||
|
@ -105,11 +105,11 @@ _DEFUN(_ftell_r, (ptr, fp),
|
||||
{
|
||||
_fpos_t pos;
|
||||
|
||||
_flockfile (fp);
|
||||
|
||||
/* Ensure stdio is set up. */
|
||||
|
||||
CHECK_INIT (fp);
|
||||
CHECK_INIT (ptr);
|
||||
|
||||
_flockfile (fp);
|
||||
|
||||
if (fp->_seek == NULL)
|
||||
{
|
||||
|
@ -99,6 +99,8 @@ _DEFUN(fwrite, (buf, size, count, fp),
|
||||
* generally slow and since this occurs whenever size==0.
|
||||
*/
|
||||
|
||||
CHECK_INIT(_REENT);
|
||||
|
||||
_flockfile (fp);
|
||||
if (__sfvwrite (fp, &uio) == 0)
|
||||
{
|
||||
|
@ -64,6 +64,7 @@ static char sccsid[] = "%W% (Berkeley) %G%";
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <stdio.h>
|
||||
#include "local.h"
|
||||
|
||||
/*
|
||||
* A subroutine version of the macro getc.
|
||||
@ -76,8 +77,8 @@ _DEFUN(getc, (fp),
|
||||
register FILE *fp)
|
||||
{
|
||||
int result;
|
||||
CHECK_INIT (_REENT);
|
||||
_flockfile (fp);
|
||||
/* CHECK_INIT is called (eventually) by __srefill. */
|
||||
result = __sgetc (fp);
|
||||
_funlockfile (fp);
|
||||
return result;
|
||||
|
@ -82,7 +82,7 @@ int
|
||||
_DEFUN(_getchar_r, (f),
|
||||
struct _reent *f)
|
||||
{
|
||||
_REENT_SMALL_CHECK_INIT (_stdin_r (f));
|
||||
_REENT_SMALL_CHECK_INIT (f);
|
||||
return getc (_stdin_r (f));
|
||||
}
|
||||
|
||||
|
@ -79,9 +79,9 @@ _DEFUN(__getdelim, (bufptr, n, delim, fp),
|
||||
*n = DEFAULT_LINE_SIZE;
|
||||
}
|
||||
|
||||
_flockfile (fp);
|
||||
CHECK_INIT (_REENT);
|
||||
|
||||
CHECK_INIT (fp);
|
||||
_flockfile (fp);
|
||||
|
||||
numbytes = *n;
|
||||
ptr = buf;
|
||||
|
@ -40,7 +40,7 @@ iprintf(fmt, va_alist)
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
||||
_REENT_SMALL_CHECK_INIT (_stdout_r (_REENT));
|
||||
_REENT_SMALL_CHECK_INIT (_REENT);
|
||||
#ifdef _HAVE_STDC
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
@ -67,7 +67,7 @@ _iprintf_r(ptr, fmt, va_alist)
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
||||
_REENT_SMALL_CHECK_INIT (_stdout_r (ptr));
|
||||
_REENT_SMALL_CHECK_INIT (ptr);
|
||||
#ifdef _HAVE_STDC
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
|
@ -39,7 +39,7 @@ iscanf(fmt, va_alist)
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
||||
_REENT_SMALL_CHECK_INIT (_stdin_r (_REENT));
|
||||
_REENT_SMALL_CHECK_INIT (_REENT);
|
||||
#ifdef _HAVE_STDC
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
@ -65,7 +65,7 @@ _iscanf_r(ptr, fmt, va_alist)
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
||||
_REENT_SMALL_CHECK_INIT (_stdin_r (ptr));
|
||||
_REENT_SMALL_CHECK_INIT (ptr);
|
||||
#ifdef _HAVE_STDC
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
|
@ -49,11 +49,11 @@ extern int _EXFUN(__srefill,(FILE *fp));
|
||||
|
||||
/* Called by the main entry point fns to ensure stdio has been initialized. */
|
||||
|
||||
#define CHECK_INIT(fp) \
|
||||
#define CHECK_INIT(ptr) \
|
||||
do \
|
||||
{ \
|
||||
if (_REENT && !_REENT->__sdidinit) \
|
||||
__sinit (_REENT); \
|
||||
if ((ptr) && !(ptr)->__sdidinit) \
|
||||
__sinit (ptr); \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
|
@ -74,7 +74,7 @@ _DEFUN(_perror_r, (ptr, s),
|
||||
{
|
||||
char *error;
|
||||
|
||||
_REENT_SMALL_CHECK_INIT (_stderr_r (ptr));
|
||||
_REENT_SMALL_CHECK_INIT (ptr);
|
||||
if (s != NULL && *s != '\0')
|
||||
{
|
||||
fputs (s, _stderr_r (ptr));
|
||||
|
@ -39,7 +39,7 @@ _printf_r(ptr, fmt, va_alist)
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
||||
_REENT_SMALL_CHECK_INIT (_stdout_r (ptr));
|
||||
_REENT_SMALL_CHECK_INIT (ptr);
|
||||
#ifdef _HAVE_STDC
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
@ -65,7 +65,7 @@ printf(fmt, va_alist)
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
||||
_REENT_SMALL_CHECK_INIT (_stdout_r (_REENT));
|
||||
_REENT_SMALL_CHECK_INIT (_REENT);
|
||||
#ifdef _HAVE_STDC
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
|
@ -67,6 +67,7 @@ static char sccsid[] = "%W% (Berkeley) %G%";
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <stdio.h>
|
||||
#include "local.h"
|
||||
|
||||
/*
|
||||
* A subroutine version of the macro putc.
|
||||
@ -80,8 +81,8 @@ _DEFUN(putc, (c, fp),
|
||||
register FILE *fp)
|
||||
{
|
||||
int result;
|
||||
CHECK_INIT (_REENT);
|
||||
_flockfile (fp);
|
||||
/* CHECK_INIT is (eventually) called by __swbuf. */
|
||||
result = __sputc (c, fp);
|
||||
_funlockfile (fp);
|
||||
return result;
|
||||
|
@ -80,7 +80,7 @@ _DEFUN(_putchar_r, (ptr, c),
|
||||
struct _reent *ptr _AND
|
||||
int c)
|
||||
{
|
||||
_REENT_SMALL_CHECK_INIT (_stdout_r (ptr));
|
||||
_REENT_SMALL_CHECK_INIT (ptr);
|
||||
return putc (c, _stdout_r (ptr));
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ _DEFUN(_puts_r, (ptr, s),
|
||||
uio.uio_iov = &iov[0];
|
||||
uio.uio_iovcnt = 2;
|
||||
|
||||
_REENT_SMALL_CHECK_INIT (_stdout_r (ptr));
|
||||
_REENT_SMALL_CHECK_INIT (ptr);
|
||||
return (__sfvwrite (_stdout_r (ptr), &uio) ? EOF : '\n');
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ _DEFUN(__srefill, (fp),
|
||||
{
|
||||
/* make sure stdio is set up */
|
||||
|
||||
CHECK_INIT (fp);
|
||||
CHECK_INIT (_REENT);
|
||||
|
||||
fp->_r = 0; /* largely a convenience for callers */
|
||||
|
||||
|
@ -39,7 +39,7 @@ scanf(fmt, va_alist)
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
||||
_REENT_SMALL_CHECK_INIT (_stdin_r (_REENT));
|
||||
_REENT_SMALL_CHECK_INIT (_REENT);
|
||||
#ifdef _HAVE_STDC
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
@ -65,7 +65,7 @@ _scanf_r(ptr, fmt, va_alist)
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
||||
_REENT_SMALL_CHECK_INIT (_stdin_r (ptr));
|
||||
_REENT_SMALL_CHECK_INIT (ptr);
|
||||
#ifdef _HAVE_STDC
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
|
@ -104,9 +104,9 @@ _DEFUN(setvbuf, (fp, buf, mode, size),
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
_flockfile (fp);
|
||||
CHECK_INIT (_REENT);
|
||||
|
||||
CHECK_INIT (fp);
|
||||
_flockfile (fp);
|
||||
|
||||
/*
|
||||
* Verify arguments. The `int' limit on `size' is due to this
|
||||
|
@ -77,14 +77,14 @@ _DEFUN(_ungetc_r, (rptr, c, fp),
|
||||
if (c == EOF)
|
||||
return (EOF);
|
||||
|
||||
_flockfile (fp);
|
||||
|
||||
/* Ensure stdio has been initialized.
|
||||
??? Might be able to remove this as some other stdio routine should
|
||||
have already been called to get the char we are un-getting. */
|
||||
|
||||
CHECK_INIT (fp);
|
||||
CHECK_INIT (rptr);
|
||||
|
||||
_flockfile (fp);
|
||||
|
||||
/* After ungetc, we won't be at eof anymore */
|
||||
fp->_flags &= ~__SEOF;
|
||||
|
||||
|
@ -533,8 +533,8 @@ _DEFUN(_VFPRINTF_R, (data, fp, fmt0, ap),
|
||||
(u_long)GET_ARG (N, ap, u_int))
|
||||
#endif
|
||||
|
||||
CHECK_INIT (data);
|
||||
_flockfile (fp);
|
||||
CHECK_INIT (fp);
|
||||
|
||||
/* sorry, fprintf(read_only_file, "") returns EOF, not 0 */
|
||||
if (cantwrite (fp)) {
|
||||
|
@ -231,7 +231,7 @@ _DEFUN(VFSCANF, (fp, fmt, ap),
|
||||
_CONST char *fmt _AND
|
||||
va_list ap)
|
||||
{
|
||||
CHECK_INIT(fp);
|
||||
CHECK_INIT(_REENT);
|
||||
return __SVFSCANF_R (_REENT, fp, fmt, ap);
|
||||
}
|
||||
|
||||
@ -253,6 +253,7 @@ _DEFUN(_VFSCANF_R, (data, fp, fmt, ap),
|
||||
_CONST char *fmt _AND
|
||||
va_list ap)
|
||||
{
|
||||
CHECK_INIT(data);
|
||||
return __SVFSCANF_R (data, fp, fmt, ap);
|
||||
}
|
||||
|
||||
|
@ -145,7 +145,7 @@ _DEFUN(viprintf, (fmt, ap),
|
||||
_CONST char *fmt _AND
|
||||
va_list ap)
|
||||
{
|
||||
_REENT_SMALL_CHECK_INIT (_stdout_r (_REENT));
|
||||
_REENT_SMALL_CHECK_INIT (_REENT);
|
||||
return _vfiprintf_r (_REENT, _stdout_r (_REENT), fmt, ap);
|
||||
}
|
||||
|
||||
@ -157,6 +157,6 @@ _DEFUN(_viprintf_r, (ptr, fmt, ap),
|
||||
_CONST char *fmt _AND
|
||||
va_list ap)
|
||||
{
|
||||
_REENT_SMALL_CHECK_INIT (_stdout_r (ptr));
|
||||
_REENT_SMALL_CHECK_INIT (ptr);
|
||||
return _vfiprintf_r (ptr, _stdout_r (ptr), fmt, ap);
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ _DEFUN(viscanf, (fmt, ap),
|
||||
_CONST char *fmt _AND
|
||||
va_list ap)
|
||||
{
|
||||
_REENT_SMALL_CHECK_INIT (_stdin_r (_REENT));
|
||||
_REENT_SMALL_CHECK_INIT (_REENT);
|
||||
return __svfiscanf_r (_REENT, _stdin_r (_REENT), fmt, ap);
|
||||
}
|
||||
|
||||
@ -133,7 +133,7 @@ _DEFUN(_viscanf_r, (ptr, fmt, ap),
|
||||
_CONST char *fmt _AND
|
||||
va_list ap)
|
||||
{
|
||||
_REENT_SMALL_CHECK_INIT (_stdin_r (ptr));
|
||||
_REENT_SMALL_CHECK_INIT (ptr);
|
||||
return __svfiscanf_r (ptr, _stdin_r (ptr), fmt, ap);
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ _DEFUN(vprintf, (fmt, ap),
|
||||
_CONST char *fmt _AND
|
||||
va_list ap)
|
||||
{
|
||||
_REENT_SMALL_CHECK_INIT (_stdout_r (_REENT));
|
||||
_REENT_SMALL_CHECK_INIT (_REENT);
|
||||
return _vfprintf_r (_REENT, _stdout_r (_REENT), fmt, ap);
|
||||
}
|
||||
|
||||
@ -45,6 +45,6 @@ _DEFUN(_vprintf_r, (ptr, fmt, ap),
|
||||
_CONST char *fmt _AND
|
||||
va_list ap)
|
||||
{
|
||||
_REENT_SMALL_CHECK_INIT (_stdout_r (ptr));
|
||||
_REENT_SMALL_CHECK_INIT (ptr);
|
||||
return _vfprintf_r (ptr, _stdout_r (ptr), fmt, ap);
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ _DEFUN(vscanf, (fmt, ap),
|
||||
_CONST char *fmt _AND
|
||||
va_list ap)
|
||||
{
|
||||
_REENT_SMALL_CHECK_INIT (_stdin_r (_REENT));
|
||||
_REENT_SMALL_CHECK_INIT (_REENT);
|
||||
return __svfscanf_r (_REENT, _stdin_r (_REENT), fmt, ap);
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ _DEFUN(_vscanf_r, (ptr, fmt, ap),
|
||||
_CONST char *fmt _AND
|
||||
va_list ap)
|
||||
{
|
||||
_REENT_SMALL_CHECK_INIT (_stdin_r (ptr));
|
||||
_REENT_SMALL_CHECK_INIT (ptr);
|
||||
return __svfscanf_r (ptr, _stdin_r (ptr), fmt, ap);
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ _DEFUN(__swbuf, (c, fp),
|
||||
|
||||
/* Ensure stdio has been initialized. */
|
||||
|
||||
CHECK_INIT (fp);
|
||||
CHECK_INIT (_REENT);
|
||||
|
||||
/*
|
||||
* In case we cannot write, or longjmp takes us out early,
|
||||
|
@ -34,7 +34,7 @@ _DEFUN(__swsetup, (fp),
|
||||
{
|
||||
/* Make sure stdio is set up. */
|
||||
|
||||
CHECK_INIT (fp);
|
||||
CHECK_INIT (_REENT);
|
||||
|
||||
/*
|
||||
* If we are not writing, we had better be reading and writing.
|
||||
|
@ -60,15 +60,12 @@ _DEFUN (_fgetpos64_r, (ptr, fp, pos),
|
||||
FILE * fp _AND
|
||||
_fpos64_t * pos)
|
||||
{
|
||||
_flockfile(fp);
|
||||
*pos = (_fpos64_t)_ftello64_r (ptr, fp);
|
||||
|
||||
if (*pos != -1)
|
||||
{
|
||||
_funlockfile(fp);
|
||||
return 0;
|
||||
}
|
||||
_funlockfile(fp);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -91,9 +91,9 @@ _DEFUN (_freopen64_r, (ptr, file, mode, fp),
|
||||
|
||||
__sfp_lock_acquire ();
|
||||
|
||||
_flockfile(fp);
|
||||
CHECK_INIT (ptr);
|
||||
|
||||
CHECK_INIT (fp);
|
||||
_flockfile(fp);
|
||||
|
||||
if ((flags = __sflags (ptr, mode, &oflags)) == 0)
|
||||
{
|
||||
|
@ -111,11 +111,11 @@ _DEFUN (_fseeko64_r, (ptr, fp, offset, whence),
|
||||
struct stat64 st;
|
||||
int havepos;
|
||||
|
||||
_flockfile(fp);
|
||||
|
||||
/* Make sure stdio is set up. */
|
||||
|
||||
CHECK_INIT (fp);
|
||||
CHECK_INIT (ptr);
|
||||
|
||||
_flockfile(fp);
|
||||
|
||||
curoff = fp->_offset;
|
||||
|
||||
|
@ -91,11 +91,11 @@ _DEFUN (_ftello64_r, (ptr, fp),
|
||||
{
|
||||
_fpos64_t pos;
|
||||
|
||||
_flockfile(fp);
|
||||
|
||||
/* Ensure stdio is set up. */
|
||||
|
||||
CHECK_INIT (fp);
|
||||
CHECK_INIT (ptr);
|
||||
|
||||
_flockfile(fp);
|
||||
|
||||
if (fp->_seek64 == NULL)
|
||||
{
|
||||
|
@ -3484,7 +3484,7 @@ void malloc_stats(RONEARG) RDECL
|
||||
MALLOC_UNLOCK;
|
||||
|
||||
#ifdef INTERNAL_NEWLIB
|
||||
_REENT_SMALL_CHECK_INIT(_stderr_r (reent_ptr));
|
||||
_REENT_SMALL_CHECK_INIT(reent_ptr);
|
||||
fp = _stderr_r(reent_ptr);
|
||||
#define fprintf fiprintf
|
||||
#else
|
||||
|
@ -140,7 +140,7 @@ _DEFUN (_mstats_r, (ptr, s),
|
||||
struct _reent *ptr _AND
|
||||
char *s)
|
||||
{
|
||||
_REENT_SMALL_CHECK_INIT(_stderr_r (ptr));
|
||||
_REENT_SMALL_CHECK_INIT(ptr);
|
||||
fiprintf (_stderr_r (ptr), "Memory allocation statistics %s\n", s);
|
||||
_malloc_stats_r (ptr);
|
||||
}
|
||||
|
@ -55,20 +55,17 @@ register char * stack_ptr asm ("sp");
|
||||
|
||||
/* following is copied from libc/stdio/local.h to check std streams */
|
||||
extern void _EXFUN(__sinit,(struct _reent *));
|
||||
#define CHECK_INIT(fp) \
|
||||
do \
|
||||
{ \
|
||||
if ((fp)->_data == 0) \
|
||||
(fp)->_data = _REENT; \
|
||||
if (!(fp)->_data->__sdidinit) \
|
||||
__sinit ((fp)->_data); \
|
||||
} \
|
||||
#define CHECK_INIT(ptr) \
|
||||
do \
|
||||
{ \
|
||||
if ((ptr) && !(ptr)->__sdidinit) \
|
||||
__sinit (ptr); \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
/* Adjust our internal handles to stay away from std* handles. */
|
||||
#define FILE_HANDLE_OFFSET (0x20)
|
||||
|
||||
static int std_files_checked;
|
||||
static int monitor_stdin;
|
||||
static int monitor_stdout;
|
||||
static int monitor_stderr;
|
||||
@ -119,13 +116,8 @@ do_AngelSWI (int reason, void * arg)
|
||||
static int
|
||||
remap_handle (int fh)
|
||||
{
|
||||
if (!std_files_checked)
|
||||
{
|
||||
CHECK_INIT(stdin);
|
||||
CHECK_INIT(stdout);
|
||||
CHECK_INIT(stderr);
|
||||
std_files_checked = 1;
|
||||
}
|
||||
CHECK_INIT(_REENT);
|
||||
|
||||
if (fh == STDIN_FILENO)
|
||||
return monitor_stdin;
|
||||
if (fh == STDOUT_FILENO)
|
||||
|
Loading…
x
Reference in New Issue
Block a user