4
0
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:
Jeff Johnston 2005-02-08 01:33:19 +00:00
parent 3d91567088
commit 1159e0fd94
50 changed files with 162 additions and 87 deletions

View File

@ -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> 2005-02-07 Jeff Johnston <jjohnstn@redhat.com>
* libc/stdio/findfp.c (__sinit): Protect with new lock. * libc/stdio/findfp.c (__sinit): Protect with new lock.

View File

@ -158,9 +158,9 @@ struct __sFILE_fake {
struct _reent *_data; struct _reent *_data;
}; };
/* CHECK_INIT() comes from stdio/local.h; be sure to include that. */ /* 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 #else
# define _REENT_SMALL_CHECK_INIT(fp) /* nothing */ # define _REENT_SMALL_CHECK_INIT(ptr) /* nothing */
#endif #endif
struct __sFILE { struct __sFILE {

View File

@ -239,7 +239,6 @@ __sbprintf(fp, fmt, ap)
unsigned char buf[BUFSIZ]; unsigned char buf[BUFSIZ];
/* copy the important variables */ /* copy the important variables */
fake._data = fp->_data;
fake._flags = fp->_flags & ~__SNBF; fake._flags = fp->_flags & ~__SNBF;
fake._file = fp->_file; fake._file = fp->_file;
fake._cookie = fp->_cookie; fake._cookie = fp->_cookie;
@ -322,6 +321,7 @@ _DEFUN (VFPRINTF, (fp, fmt0, ap),
_CONST char *fmt0 _AND _CONST char *fmt0 _AND
va_list ap) va_list ap)
{ {
CHECK_INIT (_REENT);
return _VFPRINTF_R (_REENT, fp, fmt0, ap); return _VFPRINTF_R (_REENT, fp, fmt0, ap);
} }

View File

@ -224,8 +224,8 @@ _DEFUN (vfscanf, (fp, fmt, ap),
_CONST char *fmt _AND _CONST char *fmt _AND
va_list ap) va_list ap)
{ {
CHECK_INIT(fp); CHECK_INIT(_REENT);
return __svfscanf_r (fp->_data, fp, fmt, ap); return __svfscanf_r (_REENT, fp, fmt, ap);
} }
int int

View File

@ -54,12 +54,17 @@ No supporting OS subroutines are required.
#include <_ansi.h> #include <_ansi.h>
#include <stdio.h> #include <stdio.h>
#include "local.h"
/* A subroutine version of the macro clearerr. */
#undef clearerr #undef clearerr
_VOID _VOID
_DEFUN(clearerr, (fp), _DEFUN(clearerr, (fp),
FILE * fp) FILE * fp)
{ {
CHECK_INIT(_REENT);
_flockfile (fp); _flockfile (fp);
__sclearerr (fp); __sclearerr (fp);
_funlockfile (fp); _funlockfile (fp);

View File

@ -76,10 +76,10 @@ _DEFUN(_fclose_r, (rptr, fp),
__sfp_lock_acquire (); __sfp_lock_acquire ();
CHECK_INIT (rptr);
_flockfile (fp); _flockfile (fp);
CHECK_INIT (fp);
if (fp->_flags == 0) /* not open! */ if (fp->_flags == 0) /* not open! */
{ {
_funlockfile (fp); _funlockfile (fp);

View File

@ -46,6 +46,9 @@ No supporting OS subroutines are required.
*/ */
#include <stdio.h> #include <stdio.h>
#include "local.h"
/* A subroutine version of the macro feof. */
#undef feof #undef feof
@ -54,6 +57,7 @@ _DEFUN(feof, (fp),
FILE * fp) FILE * fp)
{ {
int result; int result;
CHECK_INIT(_REENT);
_flockfile (fp); _flockfile (fp);
result = __sfeof (fp); result = __sfeof (fp);
_funlockfile (fp); _funlockfile (fp);

View File

@ -55,6 +55,7 @@ static char sccsid[] = "%W% (Berkeley) %G%";
#include <_ansi.h> #include <_ansi.h>
#include <stdio.h> #include <stdio.h>
#include "local.h"
/* A subroutine version of the macro ferror. */ /* A subroutine version of the macro ferror. */
@ -65,6 +66,7 @@ _DEFUN(ferror, (fp),
FILE * fp) FILE * fp)
{ {
int result; int result;
CHECK_INIT(_REENT);
_flockfile (fp); _flockfile (fp);
result = __sferror (fp); result = __sferror (fp);
_funlockfile (fp); _funlockfile (fp);

View File

@ -67,9 +67,9 @@ _DEFUN(fflush, (fp),
if (fp == NULL) if (fp == NULL)
return _fwalk (_GLOBAL_REENT, fflush); return _fwalk (_GLOBAL_REENT, fflush);
_flockfile (fp); CHECK_INIT (_REENT);
CHECK_INIT (fp); _flockfile (fp);
t = fp->_flags; t = fp->_flags;
if ((t & __SWR) == 0 || (p = fp->_bf._base) == NULL) if ((t & __SWR) == 0 || (p = fp->_bf._base) == NULL)

View File

@ -55,12 +55,14 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
#include <_ansi.h> #include <_ansi.h>
#include <stdio.h> #include <stdio.h>
#include "local.h"
int int
_DEFUN(fgetc, (fp), _DEFUN(fgetc, (fp),
FILE * fp) FILE * fp)
{ {
int result; int result;
CHECK_INIT(_REENT);
_flockfile (fp); _flockfile (fp);
result = __sgetc (fp); result = __sgetc (fp);
_funlockfile (fp); _funlockfile (fp);

View File

@ -81,15 +81,12 @@ _DEFUN(_fgetpos_r, (ptr, fp, pos),
FILE * fp _AND FILE * fp _AND
_fpos_t * pos) _fpos_t * pos)
{ {
_flockfile (fp);
*pos = _ftell_r (ptr, fp); *pos = _ftell_r (ptr, fp);
if (*pos != -1) if (*pos != -1)
{ {
_funlockfile (fp);
return 0; return 0;
} }
_funlockfile (fp);
return 1; return 1;
} }

View File

@ -80,6 +80,8 @@ _DEFUN(fgets, (buf, n, fp),
s = buf; s = buf;
CHECK_INIT(_REENT);
_flockfile (fp); _flockfile (fp);
#ifdef __SCLE #ifdef __SCLE
if (fp->_flags & __SCLE) if (fp->_flags & __SCLE)

View File

@ -54,8 +54,8 @@ _DEFUN(fileno, (f),
FILE * f) FILE * f)
{ {
int result; int result;
CHECK_INIT (_REENT);
_flockfile (f); _flockfile (f);
CHECK_INIT (f);
result = __sfileno (f); result = __sfileno (f);
_funlockfile (f); _funlockfile (f);
return result; return result;

View File

@ -59,6 +59,7 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
#include <_ansi.h> #include <_ansi.h>
#include <stdio.h> #include <stdio.h>
#include "local.h"
int int
_DEFUN(fputc, (ch, file), _DEFUN(fputc, (ch, file),
@ -66,6 +67,7 @@ _DEFUN(fputc, (ch, file),
FILE * file) FILE * file)
{ {
int result; int result;
CHECK_INIT(_REENT);
_flockfile (file); _flockfile (file);
result = putc (ch, file); result = putc (ch, file);
_funlockfile (file); _funlockfile (file);

View File

@ -51,6 +51,7 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "fvwrite.h" #include "fvwrite.h"
#include "local.h"
/* /*
* Write the given string to the given file. * Write the given string to the given file.
@ -69,6 +70,9 @@ _DEFUN(fputs, (s, fp),
iov.iov_len = uio.uio_resid = strlen (s); iov.iov_len = uio.uio_resid = strlen (s);
uio.uio_iov = &iov; uio.uio_iov = &iov;
uio.uio_iovcnt = 1; uio.uio_iovcnt = 1;
CHECK_INIT(_REENT);
_flockfile (fp); _flockfile (fp);
result = __sfvwrite (fp, &uio); result = __sfvwrite (fp, &uio);
_funlockfile (fp); _funlockfile (fp);

View File

@ -125,6 +125,8 @@ _DEFUN(fread, (buf, size, count, fp),
if ((resid = count * size) == 0) if ((resid = count * size) == 0)
return 0; return 0;
CHECK_INIT(_REENT);
_flockfile (fp); _flockfile (fp);
if (fp->_r < 0) if (fp->_r < 0)
fp->_r = 0; fp->_r = 0;

View File

@ -91,9 +91,9 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp),
__sfp_lock_acquire (); __sfp_lock_acquire ();
_flockfile (fp); CHECK_INIT (ptr);
CHECK_INIT (fp); _flockfile (fp);
if ((flags = __sflags (ptr, mode, &oflags)) == 0) if ((flags = __sflags (ptr, mode, &oflags)) == 0)
{ {

View File

@ -129,11 +129,11 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
struct stat st; struct stat st;
int havepos; int havepos;
_flockfile (fp);
/* Make sure stdio is set up. */ /* 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 /* If we've been doing some writing, and we're in append mode
then we don't really know where the filepos is. */ then we don't really know where the filepos is. */

View File

@ -105,11 +105,11 @@ _DEFUN(_ftell_r, (ptr, fp),
{ {
_fpos_t pos; _fpos_t pos;
_flockfile (fp);
/* Ensure stdio is set up. */ /* Ensure stdio is set up. */
CHECK_INIT (fp); CHECK_INIT (ptr);
_flockfile (fp);
if (fp->_seek == NULL) if (fp->_seek == NULL)
{ {

View File

@ -99,6 +99,8 @@ _DEFUN(fwrite, (buf, size, count, fp),
* generally slow and since this occurs whenever size==0. * generally slow and since this occurs whenever size==0.
*/ */
CHECK_INIT(_REENT);
_flockfile (fp); _flockfile (fp);
if (__sfvwrite (fp, &uio) == 0) if (__sfvwrite (fp, &uio) == 0)
{ {

View File

@ -64,6 +64,7 @@ static char sccsid[] = "%W% (Berkeley) %G%";
#include <_ansi.h> #include <_ansi.h>
#include <stdio.h> #include <stdio.h>
#include "local.h"
/* /*
* A subroutine version of the macro getc. * A subroutine version of the macro getc.
@ -76,8 +77,8 @@ _DEFUN(getc, (fp),
register FILE *fp) register FILE *fp)
{ {
int result; int result;
CHECK_INIT (_REENT);
_flockfile (fp); _flockfile (fp);
/* CHECK_INIT is called (eventually) by __srefill. */
result = __sgetc (fp); result = __sgetc (fp);
_funlockfile (fp); _funlockfile (fp);
return result; return result;

View File

@ -82,7 +82,7 @@ int
_DEFUN(_getchar_r, (f), _DEFUN(_getchar_r, (f),
struct _reent *f) struct _reent *f)
{ {
_REENT_SMALL_CHECK_INIT (_stdin_r (f)); _REENT_SMALL_CHECK_INIT (f);
return getc (_stdin_r (f)); return getc (_stdin_r (f));
} }

View File

@ -79,9 +79,9 @@ _DEFUN(__getdelim, (bufptr, n, delim, fp),
*n = DEFAULT_LINE_SIZE; *n = DEFAULT_LINE_SIZE;
} }
_flockfile (fp); CHECK_INIT (_REENT);
CHECK_INIT (fp); _flockfile (fp);
numbytes = *n; numbytes = *n;
ptr = buf; ptr = buf;

View File

@ -40,7 +40,7 @@ iprintf(fmt, va_alist)
int ret; int ret;
va_list ap; va_list ap;
_REENT_SMALL_CHECK_INIT (_stdout_r (_REENT)); _REENT_SMALL_CHECK_INIT (_REENT);
#ifdef _HAVE_STDC #ifdef _HAVE_STDC
va_start (ap, fmt); va_start (ap, fmt);
#else #else
@ -67,7 +67,7 @@ _iprintf_r(ptr, fmt, va_alist)
int ret; int ret;
va_list ap; va_list ap;
_REENT_SMALL_CHECK_INIT (_stdout_r (ptr)); _REENT_SMALL_CHECK_INIT (ptr);
#ifdef _HAVE_STDC #ifdef _HAVE_STDC
va_start (ap, fmt); va_start (ap, fmt);
#else #else

View File

@ -39,7 +39,7 @@ iscanf(fmt, va_alist)
int ret; int ret;
va_list ap; va_list ap;
_REENT_SMALL_CHECK_INIT (_stdin_r (_REENT)); _REENT_SMALL_CHECK_INIT (_REENT);
#ifdef _HAVE_STDC #ifdef _HAVE_STDC
va_start (ap, fmt); va_start (ap, fmt);
#else #else
@ -65,7 +65,7 @@ _iscanf_r(ptr, fmt, va_alist)
int ret; int ret;
va_list ap; va_list ap;
_REENT_SMALL_CHECK_INIT (_stdin_r (ptr)); _REENT_SMALL_CHECK_INIT (ptr);
#ifdef _HAVE_STDC #ifdef _HAVE_STDC
va_start (ap, fmt); va_start (ap, fmt);
#else #else

View File

@ -49,11 +49,11 @@ extern int _EXFUN(__srefill,(FILE *fp));
/* Called by the main entry point fns to ensure stdio has been initialized. */ /* Called by the main entry point fns to ensure stdio has been initialized. */
#define CHECK_INIT(fp) \ #define CHECK_INIT(ptr) \
do \ do \
{ \ { \
if (_REENT && !_REENT->__sdidinit) \ if ((ptr) && !(ptr)->__sdidinit) \
__sinit (_REENT); \ __sinit (ptr); \
} \ } \
while (0) while (0)

View File

@ -74,7 +74,7 @@ _DEFUN(_perror_r, (ptr, s),
{ {
char *error; char *error;
_REENT_SMALL_CHECK_INIT (_stderr_r (ptr)); _REENT_SMALL_CHECK_INIT (ptr);
if (s != NULL && *s != '\0') if (s != NULL && *s != '\0')
{ {
fputs (s, _stderr_r (ptr)); fputs (s, _stderr_r (ptr));

View File

@ -39,7 +39,7 @@ _printf_r(ptr, fmt, va_alist)
int ret; int ret;
va_list ap; va_list ap;
_REENT_SMALL_CHECK_INIT (_stdout_r (ptr)); _REENT_SMALL_CHECK_INIT (ptr);
#ifdef _HAVE_STDC #ifdef _HAVE_STDC
va_start (ap, fmt); va_start (ap, fmt);
#else #else
@ -65,7 +65,7 @@ printf(fmt, va_alist)
int ret; int ret;
va_list ap; va_list ap;
_REENT_SMALL_CHECK_INIT (_stdout_r (_REENT)); _REENT_SMALL_CHECK_INIT (_REENT);
#ifdef _HAVE_STDC #ifdef _HAVE_STDC
va_start (ap, fmt); va_start (ap, fmt);
#else #else

View File

@ -67,6 +67,7 @@ static char sccsid[] = "%W% (Berkeley) %G%";
#include <_ansi.h> #include <_ansi.h>
#include <stdio.h> #include <stdio.h>
#include "local.h"
/* /*
* A subroutine version of the macro putc. * A subroutine version of the macro putc.
@ -80,8 +81,8 @@ _DEFUN(putc, (c, fp),
register FILE *fp) register FILE *fp)
{ {
int result; int result;
CHECK_INIT (_REENT);
_flockfile (fp); _flockfile (fp);
/* CHECK_INIT is (eventually) called by __swbuf. */
result = __sputc (c, fp); result = __sputc (c, fp);
_funlockfile (fp); _funlockfile (fp);
return result; return result;

View File

@ -80,7 +80,7 @@ _DEFUN(_putchar_r, (ptr, c),
struct _reent *ptr _AND struct _reent *ptr _AND
int c) int c)
{ {
_REENT_SMALL_CHECK_INIT (_stdout_r (ptr)); _REENT_SMALL_CHECK_INIT (ptr);
return putc (c, _stdout_r (ptr)); return putc (c, _stdout_r (ptr));
} }

View File

@ -90,7 +90,7 @@ _DEFUN(_puts_r, (ptr, s),
uio.uio_iov = &iov[0]; uio.uio_iov = &iov[0];
uio.uio_iovcnt = 2; uio.uio_iovcnt = 2;
_REENT_SMALL_CHECK_INIT (_stdout_r (ptr)); _REENT_SMALL_CHECK_INIT (ptr);
return (__sfvwrite (_stdout_r (ptr), &uio) ? EOF : '\n'); return (__sfvwrite (_stdout_r (ptr), &uio) ? EOF : '\n');
} }

View File

@ -41,7 +41,7 @@ _DEFUN(__srefill, (fp),
{ {
/* make sure stdio is set up */ /* make sure stdio is set up */
CHECK_INIT (fp); CHECK_INIT (_REENT);
fp->_r = 0; /* largely a convenience for callers */ fp->_r = 0; /* largely a convenience for callers */

View File

@ -39,7 +39,7 @@ scanf(fmt, va_alist)
int ret; int ret;
va_list ap; va_list ap;
_REENT_SMALL_CHECK_INIT (_stdin_r (_REENT)); _REENT_SMALL_CHECK_INIT (_REENT);
#ifdef _HAVE_STDC #ifdef _HAVE_STDC
va_start (ap, fmt); va_start (ap, fmt);
#else #else
@ -65,7 +65,7 @@ _scanf_r(ptr, fmt, va_alist)
int ret; int ret;
va_list ap; va_list ap;
_REENT_SMALL_CHECK_INIT (_stdin_r (ptr)); _REENT_SMALL_CHECK_INIT (ptr);
#ifdef _HAVE_STDC #ifdef _HAVE_STDC
va_start (ap, fmt); va_start (ap, fmt);
#else #else

View File

@ -104,9 +104,9 @@ _DEFUN(setvbuf, (fp, buf, mode, size),
{ {
int ret = 0; int ret = 0;
_flockfile (fp); CHECK_INIT (_REENT);
CHECK_INIT (fp); _flockfile (fp);
/* /*
* Verify arguments. The `int' limit on `size' is due to this * Verify arguments. The `int' limit on `size' is due to this

View File

@ -77,14 +77,14 @@ _DEFUN(_ungetc_r, (rptr, c, fp),
if (c == EOF) if (c == EOF)
return (EOF); return (EOF);
_flockfile (fp);
/* Ensure stdio has been initialized. /* Ensure stdio has been initialized.
??? Might be able to remove this as some other stdio routine should ??? Might be able to remove this as some other stdio routine should
have already been called to get the char we are un-getting. */ 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 */ /* After ungetc, we won't be at eof anymore */
fp->_flags &= ~__SEOF; fp->_flags &= ~__SEOF;

View File

@ -533,8 +533,8 @@ _DEFUN(_VFPRINTF_R, (data, fp, fmt0, ap),
(u_long)GET_ARG (N, ap, u_int)) (u_long)GET_ARG (N, ap, u_int))
#endif #endif
CHECK_INIT (data);
_flockfile (fp); _flockfile (fp);
CHECK_INIT (fp);
/* sorry, fprintf(read_only_file, "") returns EOF, not 0 */ /* sorry, fprintf(read_only_file, "") returns EOF, not 0 */
if (cantwrite (fp)) { if (cantwrite (fp)) {

View File

@ -231,7 +231,7 @@ _DEFUN(VFSCANF, (fp, fmt, ap),
_CONST char *fmt _AND _CONST char *fmt _AND
va_list ap) va_list ap)
{ {
CHECK_INIT(fp); CHECK_INIT(_REENT);
return __SVFSCANF_R (_REENT, fp, fmt, ap); return __SVFSCANF_R (_REENT, fp, fmt, ap);
} }
@ -253,6 +253,7 @@ _DEFUN(_VFSCANF_R, (data, fp, fmt, ap),
_CONST char *fmt _AND _CONST char *fmt _AND
va_list ap) va_list ap)
{ {
CHECK_INIT(data);
return __SVFSCANF_R (data, fp, fmt, ap); return __SVFSCANF_R (data, fp, fmt, ap);
} }

View File

@ -145,7 +145,7 @@ _DEFUN(viprintf, (fmt, ap),
_CONST char *fmt _AND _CONST char *fmt _AND
va_list ap) va_list ap)
{ {
_REENT_SMALL_CHECK_INIT (_stdout_r (_REENT)); _REENT_SMALL_CHECK_INIT (_REENT);
return _vfiprintf_r (_REENT, _stdout_r (_REENT), fmt, ap); return _vfiprintf_r (_REENT, _stdout_r (_REENT), fmt, ap);
} }
@ -157,6 +157,6 @@ _DEFUN(_viprintf_r, (ptr, fmt, ap),
_CONST char *fmt _AND _CONST char *fmt _AND
va_list ap) va_list ap)
{ {
_REENT_SMALL_CHECK_INIT (_stdout_r (ptr)); _REENT_SMALL_CHECK_INIT (ptr);
return _vfiprintf_r (ptr, _stdout_r (ptr), fmt, ap); return _vfiprintf_r (ptr, _stdout_r (ptr), fmt, ap);
} }

View File

@ -121,7 +121,7 @@ _DEFUN(viscanf, (fmt, ap),
_CONST char *fmt _AND _CONST char *fmt _AND
va_list ap) va_list ap)
{ {
_REENT_SMALL_CHECK_INIT (_stdin_r (_REENT)); _REENT_SMALL_CHECK_INIT (_REENT);
return __svfiscanf_r (_REENT, _stdin_r (_REENT), fmt, ap); return __svfiscanf_r (_REENT, _stdin_r (_REENT), fmt, ap);
} }
@ -133,7 +133,7 @@ _DEFUN(_viscanf_r, (ptr, fmt, ap),
_CONST char *fmt _AND _CONST char *fmt _AND
va_list ap) va_list ap)
{ {
_REENT_SMALL_CHECK_INIT (_stdin_r (ptr)); _REENT_SMALL_CHECK_INIT (ptr);
return __svfiscanf_r (ptr, _stdin_r (ptr), fmt, ap); return __svfiscanf_r (ptr, _stdin_r (ptr), fmt, ap);
} }

View File

@ -33,7 +33,7 @@ _DEFUN(vprintf, (fmt, ap),
_CONST char *fmt _AND _CONST char *fmt _AND
va_list ap) va_list ap)
{ {
_REENT_SMALL_CHECK_INIT (_stdout_r (_REENT)); _REENT_SMALL_CHECK_INIT (_REENT);
return _vfprintf_r (_REENT, _stdout_r (_REENT), fmt, ap); return _vfprintf_r (_REENT, _stdout_r (_REENT), fmt, ap);
} }
@ -45,6 +45,6 @@ _DEFUN(_vprintf_r, (ptr, fmt, ap),
_CONST char *fmt _AND _CONST char *fmt _AND
va_list ap) va_list ap)
{ {
_REENT_SMALL_CHECK_INIT (_stdout_r (ptr)); _REENT_SMALL_CHECK_INIT (ptr);
return _vfprintf_r (ptr, _stdout_r (ptr), fmt, ap); return _vfprintf_r (ptr, _stdout_r (ptr), fmt, ap);
} }

View File

@ -34,7 +34,7 @@ _DEFUN(vscanf, (fmt, ap),
_CONST char *fmt _AND _CONST char *fmt _AND
va_list ap) va_list ap)
{ {
_REENT_SMALL_CHECK_INIT (_stdin_r (_REENT)); _REENT_SMALL_CHECK_INIT (_REENT);
return __svfscanf_r (_REENT, _stdin_r (_REENT), fmt, ap); return __svfscanf_r (_REENT, _stdin_r (_REENT), fmt, ap);
} }
@ -46,7 +46,7 @@ _DEFUN(_vscanf_r, (ptr, fmt, ap),
_CONST char *fmt _AND _CONST char *fmt _AND
va_list ap) va_list ap)
{ {
_REENT_SMALL_CHECK_INIT (_stdin_r (ptr)); _REENT_SMALL_CHECK_INIT (ptr);
return __svfscanf_r (ptr, _stdin_r (ptr), fmt, ap); return __svfscanf_r (ptr, _stdin_r (ptr), fmt, ap);
} }

View File

@ -40,7 +40,7 @@ _DEFUN(__swbuf, (c, fp),
/* Ensure stdio has been initialized. */ /* Ensure stdio has been initialized. */
CHECK_INIT (fp); CHECK_INIT (_REENT);
/* /*
* In case we cannot write, or longjmp takes us out early, * In case we cannot write, or longjmp takes us out early,

View File

@ -34,7 +34,7 @@ _DEFUN(__swsetup, (fp),
{ {
/* Make sure stdio is set up. */ /* Make sure stdio is set up. */
CHECK_INIT (fp); CHECK_INIT (_REENT);
/* /*
* If we are not writing, we had better be reading and writing. * If we are not writing, we had better be reading and writing.

View File

@ -60,15 +60,12 @@ _DEFUN (_fgetpos64_r, (ptr, fp, pos),
FILE * fp _AND FILE * fp _AND
_fpos64_t * pos) _fpos64_t * pos)
{ {
_flockfile(fp);
*pos = (_fpos64_t)_ftello64_r (ptr, fp); *pos = (_fpos64_t)_ftello64_r (ptr, fp);
if (*pos != -1) if (*pos != -1)
{ {
_funlockfile(fp);
return 0; return 0;
} }
_funlockfile(fp);
return 1; return 1;
} }

View File

@ -91,9 +91,9 @@ _DEFUN (_freopen64_r, (ptr, file, mode, fp),
__sfp_lock_acquire (); __sfp_lock_acquire ();
_flockfile(fp); CHECK_INIT (ptr);
CHECK_INIT (fp); _flockfile(fp);
if ((flags = __sflags (ptr, mode, &oflags)) == 0) if ((flags = __sflags (ptr, mode, &oflags)) == 0)
{ {

View File

@ -111,11 +111,11 @@ _DEFUN (_fseeko64_r, (ptr, fp, offset, whence),
struct stat64 st; struct stat64 st;
int havepos; int havepos;
_flockfile(fp);
/* Make sure stdio is set up. */ /* Make sure stdio is set up. */
CHECK_INIT (fp); CHECK_INIT (ptr);
_flockfile(fp);
curoff = fp->_offset; curoff = fp->_offset;

View File

@ -91,11 +91,11 @@ _DEFUN (_ftello64_r, (ptr, fp),
{ {
_fpos64_t pos; _fpos64_t pos;
_flockfile(fp);
/* Ensure stdio is set up. */ /* Ensure stdio is set up. */
CHECK_INIT (fp); CHECK_INIT (ptr);
_flockfile(fp);
if (fp->_seek64 == NULL) if (fp->_seek64 == NULL)
{ {

View File

@ -3484,7 +3484,7 @@ void malloc_stats(RONEARG) RDECL
MALLOC_UNLOCK; MALLOC_UNLOCK;
#ifdef INTERNAL_NEWLIB #ifdef INTERNAL_NEWLIB
_REENT_SMALL_CHECK_INIT(_stderr_r (reent_ptr)); _REENT_SMALL_CHECK_INIT(reent_ptr);
fp = _stderr_r(reent_ptr); fp = _stderr_r(reent_ptr);
#define fprintf fiprintf #define fprintf fiprintf
#else #else

View File

@ -140,7 +140,7 @@ _DEFUN (_mstats_r, (ptr, s),
struct _reent *ptr _AND struct _reent *ptr _AND
char *s) char *s)
{ {
_REENT_SMALL_CHECK_INIT(_stderr_r (ptr)); _REENT_SMALL_CHECK_INIT(ptr);
fiprintf (_stderr_r (ptr), "Memory allocation statistics %s\n", s); fiprintf (_stderr_r (ptr), "Memory allocation statistics %s\n", s);
_malloc_stats_r (ptr); _malloc_stats_r (ptr);
} }

View File

@ -55,20 +55,17 @@ register char * stack_ptr asm ("sp");
/* following is copied from libc/stdio/local.h to check std streams */ /* following is copied from libc/stdio/local.h to check std streams */
extern void _EXFUN(__sinit,(struct _reent *)); extern void _EXFUN(__sinit,(struct _reent *));
#define CHECK_INIT(fp) \ #define CHECK_INIT(ptr) \
do \ do \
{ \ { \
if ((fp)->_data == 0) \ if ((ptr) && !(ptr)->__sdidinit) \
(fp)->_data = _REENT; \ __sinit (ptr); \
if (!(fp)->_data->__sdidinit) \ } \
__sinit ((fp)->_data); \
} \
while (0) while (0)
/* Adjust our internal handles to stay away from std* handles. */ /* Adjust our internal handles to stay away from std* handles. */
#define FILE_HANDLE_OFFSET (0x20) #define FILE_HANDLE_OFFSET (0x20)
static int std_files_checked;
static int monitor_stdin; static int monitor_stdin;
static int monitor_stdout; static int monitor_stdout;
static int monitor_stderr; static int monitor_stderr;
@ -119,13 +116,8 @@ do_AngelSWI (int reason, void * arg)
static int static int
remap_handle (int fh) remap_handle (int fh)
{ {
if (!std_files_checked) CHECK_INIT(_REENT);
{
CHECK_INIT(stdin);
CHECK_INIT(stdout);
CHECK_INIT(stderr);
std_files_checked = 1;
}
if (fh == STDIN_FILENO) if (fh == STDIN_FILENO)
return monitor_stdin; return monitor_stdin;
if (fh == STDOUT_FILENO) if (fh == STDOUT_FILENO)