diff options
Diffstat (limited to 'newlib/libc/stdio')
27 files changed, 64 insertions, 31 deletions
diff --git a/newlib/libc/stdio/clearerr.c b/newlib/libc/stdio/clearerr.c index 0923ff84d..d3b620bed 100644 --- a/newlib/libc/stdio/clearerr.c +++ b/newlib/libc/stdio/clearerr.c @@ -64,7 +64,7 @@ _VOID _DEFUN(clearerr, (fp), FILE * fp) { - CHECK_INIT(_REENT); + CHECK_INIT(_REENT, fp); _flockfile (fp); __sclearerr (fp); _funlockfile (fp); diff --git a/newlib/libc/stdio/fclose.c b/newlib/libc/stdio/fclose.c index 66d71c2d4..bb3acb624 100644 --- a/newlib/libc/stdio/fclose.c +++ b/newlib/libc/stdio/fclose.c @@ -76,7 +76,7 @@ _DEFUN(_fclose_r, (rptr, fp), __sfp_lock_acquire (); - CHECK_INIT (rptr); + CHECK_INIT (rptr, fp); _flockfile (fp); diff --git a/newlib/libc/stdio/feof.c b/newlib/libc/stdio/feof.c index aff4e84c8..e8db65b86 100644 --- a/newlib/libc/stdio/feof.c +++ b/newlib/libc/stdio/feof.c @@ -57,7 +57,7 @@ _DEFUN(feof, (fp), FILE * fp) { int result; - CHECK_INIT(_REENT); + CHECK_INIT(_REENT, fp); _flockfile (fp); result = __sfeof (fp); _funlockfile (fp); diff --git a/newlib/libc/stdio/ferror.c b/newlib/libc/stdio/ferror.c index ea701bec7..72b7ce2c5 100644 --- a/newlib/libc/stdio/ferror.c +++ b/newlib/libc/stdio/ferror.c @@ -66,7 +66,7 @@ _DEFUN(ferror, (fp), FILE * fp) { int result; - CHECK_INIT(_REENT); + CHECK_INIT(_REENT, fp); _flockfile (fp); result = __sferror (fp); _funlockfile (fp); diff --git a/newlib/libc/stdio/fflush.c b/newlib/libc/stdio/fflush.c index 05084dde0..bac49804f 100644 --- a/newlib/libc/stdio/fflush.c +++ b/newlib/libc/stdio/fflush.c @@ -67,7 +67,7 @@ _DEFUN(fflush, (fp), if (fp == NULL) return _fwalk (_GLOBAL_REENT, fflush); - CHECK_INIT (_REENT); + CHECK_INIT (_REENT, fp); _flockfile (fp); diff --git a/newlib/libc/stdio/fgetc.c b/newlib/libc/stdio/fgetc.c index 1802acf7e..e275cfeeb 100644 --- a/newlib/libc/stdio/fgetc.c +++ b/newlib/libc/stdio/fgetc.c @@ -77,7 +77,7 @@ _DEFUN(_fgetc_r, (ptr, fp), FILE * fp) { int result; - CHECK_INIT(ptr); + CHECK_INIT(ptr, fp); _flockfile (fp); result = __sgetc_r (ptr, fp); _funlockfile (fp); @@ -92,7 +92,7 @@ _DEFUN(fgetc, (fp), { #if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) int result; - CHECK_INIT(_REENT); + CHECK_INIT(_REENT, fp); _flockfile (fp); result = __sgetc_r (_REENT, fp); _funlockfile (fp); diff --git a/newlib/libc/stdio/fgets.c b/newlib/libc/stdio/fgets.c index 741618705..7f02e3fcb 100644 --- a/newlib/libc/stdio/fgets.c +++ b/newlib/libc/stdio/fgets.c @@ -96,7 +96,7 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp), s = buf; - CHECK_INIT(ptr); + CHECK_INIT(ptr, fp); _flockfile (fp); #ifdef __SCLE diff --git a/newlib/libc/stdio/fileno.c b/newlib/libc/stdio/fileno.c index b202cc5e3..db399eb12 100644 --- a/newlib/libc/stdio/fileno.c +++ b/newlib/libc/stdio/fileno.c @@ -54,7 +54,7 @@ _DEFUN(fileno, (f), FILE * f) { int result; - CHECK_INIT (_REENT); + CHECK_INIT (_REENT, f); _flockfile (f); result = __sfileno (f); _funlockfile (f); diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c index e3270af38..ac1354619 100644 --- a/newlib/libc/stdio/findfp.c +++ b/newlib/libc/stdio/findfp.c @@ -26,6 +26,15 @@ #include <sys/lock.h> #include "local.h" +#ifdef _REENT_SMALL +const struct __sFILE_fake __sf_fake_stdin = + {_NULL, 0, 0, 0, 0, {_NULL, 0}, 0, _NULL}; +const struct __sFILE_fake __sf_fake_stdout = + {_NULL, 0, 0, 0, 0, {_NULL, 0}, 0, _NULL}; +const struct __sFILE_fake __sf_fake_stderr = + {_NULL, 0, 0, 0, 0, {_NULL, 0}, 0, _NULL}; +#endif + static _VOID _DEFUN(std, (ptr, flags, file, data), FILE *ptr _AND diff --git a/newlib/libc/stdio/fputc.c b/newlib/libc/stdio/fputc.c index 520fc0250..777a34242 100644 --- a/newlib/libc/stdio/fputc.c +++ b/newlib/libc/stdio/fputc.c @@ -82,7 +82,7 @@ _DEFUN(_fputc_r, (ptr, ch, file), FILE * file) { int result; - CHECK_INIT(ptr); + CHECK_INIT(ptr, file); _flockfile (file); result = _putc_r (ptr, ch, file); _funlockfile (file); @@ -97,7 +97,7 @@ _DEFUN(fputc, (ch, file), { #if !defined(__OPTIMIZE_SIZE__) && !defined(PREFER_SIZE_OVER_SPEED) int result; - CHECK_INIT(_REENT); + CHECK_INIT(_REENT, file); _flockfile (file); result = _putc_r (_REENT, ch, file); _funlockfile (file); diff --git a/newlib/libc/stdio/fputs.c b/newlib/libc/stdio/fputs.c index 93537b9e4..24a108b15 100644 --- a/newlib/libc/stdio/fputs.c +++ b/newlib/libc/stdio/fputs.c @@ -86,7 +86,7 @@ _DEFUN(_fputs_r, (ptr, s, fp), uio.uio_iov = &iov; uio.uio_iovcnt = 1; - CHECK_INIT(ptr); + CHECK_INIT(ptr, fp); _flockfile (fp); result = __sfvwrite_r (ptr, fp, &uio); diff --git a/newlib/libc/stdio/fread.c b/newlib/libc/stdio/fread.c index d87d9f966..c2c248979 100644 --- a/newlib/libc/stdio/fread.c +++ b/newlib/libc/stdio/fread.c @@ -145,7 +145,7 @@ _DEFUN(_fread_r, (ptr, buf, size, count, fp), if ((resid = count * size) == 0) return 0; - CHECK_INIT(ptr); + CHECK_INIT(ptr, fp); _flockfile (fp); if (fp->_r < 0) diff --git a/newlib/libc/stdio/freopen.c b/newlib/libc/stdio/freopen.c index f1fc9dad8..445baf1ac 100644 --- a/newlib/libc/stdio/freopen.c +++ b/newlib/libc/stdio/freopen.c @@ -99,7 +99,7 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp), __sfp_lock_acquire (); - CHECK_INIT (ptr); + CHECK_INIT (ptr, fp); _flockfile (fp); diff --git a/newlib/libc/stdio/fseek.c b/newlib/libc/stdio/fseek.c index 09edc42d1..9944fd809 100644 --- a/newlib/libc/stdio/fseek.c +++ b/newlib/libc/stdio/fseek.c @@ -131,7 +131,7 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence), /* Make sure stdio is set up. */ - CHECK_INIT (ptr); + CHECK_INIT (ptr, fp); _flockfile (fp); diff --git a/newlib/libc/stdio/ftell.c b/newlib/libc/stdio/ftell.c index 74d6d906c..de5d55d44 100644 --- a/newlib/libc/stdio/ftell.c +++ b/newlib/libc/stdio/ftell.c @@ -107,7 +107,7 @@ _DEFUN(_ftell_r, (ptr, fp), /* Ensure stdio is set up. */ - CHECK_INIT (ptr); + CHECK_INIT (ptr, fp); _flockfile (fp); diff --git a/newlib/libc/stdio/fwrite.c b/newlib/libc/stdio/fwrite.c index dd739d6b7..3443d95d1 100644 --- a/newlib/libc/stdio/fwrite.c +++ b/newlib/libc/stdio/fwrite.c @@ -117,7 +117,7 @@ _DEFUN(_fwrite_r, (ptr, buf, size, count, fp), * generally slow and since this occurs whenever size==0. */ - CHECK_INIT(ptr); + CHECK_INIT(ptr, fp); _flockfile (fp); if (__sfvwrite_r (ptr, fp, &uio) == 0) diff --git a/newlib/libc/stdio/getc.c b/newlib/libc/stdio/getc.c index c02fe6b3d..5b1fa888a 100644 --- a/newlib/libc/stdio/getc.c +++ b/newlib/libc/stdio/getc.c @@ -91,7 +91,7 @@ _DEFUN(_getc_r, (ptr, fp), register FILE *fp) { int result; - CHECK_INIT (ptr); + CHECK_INIT (ptr, fp); _flockfile (fp); result = __sgetc_r (ptr, fp); _funlockfile (fp); @@ -105,7 +105,7 @@ _DEFUN(getc, (fp), register FILE *fp) { int result; - CHECK_INIT (_REENT); + CHECK_INIT (_REENT, fp); _flockfile (fp); result = __sgetc_r (_REENT, fp); _funlockfile (fp); diff --git a/newlib/libc/stdio/getdelim.c b/newlib/libc/stdio/getdelim.c index 0fdfb3add..23fc50218 100644 --- a/newlib/libc/stdio/getdelim.c +++ b/newlib/libc/stdio/getdelim.c @@ -79,7 +79,7 @@ _DEFUN(__getdelim, (bufptr, n, delim, fp), *n = DEFAULT_LINE_SIZE; } - CHECK_INIT (_REENT); + CHECK_INIT (_REENT, fp); _flockfile (fp); diff --git a/newlib/libc/stdio/local.h b/newlib/libc/stdio/local.h index 301abce33..9ae9b4046 100644 --- a/newlib/libc/stdio/local.h +++ b/newlib/libc/stdio/local.h @@ -48,7 +48,31 @@ struct _glue * _EXFUN(__sfmoreglue,(struct _reent *,int n)); /* Called by the main entry point fns to ensure stdio has been initialized. */ -#define CHECK_INIT(ptr) \ +#ifdef _REENT_SMALL +#define CHECK_INIT(ptr, fp) \ + do \ + { \ + if ((ptr) && !(ptr)->__sdidinit) \ + __sinit (ptr); \ + if ((fp) == (FILE *)&__sf_fake_stdin) \ + (fp) = stdin; \ + else if ((fp) == (FILE *)&__sf_fake_stdout) \ + (fp) = stdout; \ + else if ((fp) == (FILE *)&__sf_fake_stderr) \ + (fp) = stderr; \ + } \ + while (0) +#else /* !_REENT_SMALL */ +#define CHECK_INIT(ptr, fp) \ + do \ + { \ + if ((ptr) && !(ptr)->__sdidinit) \ + __sinit (ptr); \ + } \ + while (0) +#endif /* !_REENT_SMALL */ + +#define CHECK_STD_INIT(ptr) \ do \ { \ if ((ptr) && !(ptr)->__sdidinit) \ diff --git a/newlib/libc/stdio/putc.c b/newlib/libc/stdio/putc.c index b3008e287..667324d9d 100644 --- a/newlib/libc/stdio/putc.c +++ b/newlib/libc/stdio/putc.c @@ -96,7 +96,7 @@ _DEFUN(_putc_r, (ptr, c, fp), register FILE *fp) { int result; - CHECK_INIT (ptr); + CHECK_INIT (ptr, fp); _flockfile (fp); result = __sputc_r (ptr, c, fp); _funlockfile (fp); @@ -111,7 +111,7 @@ _DEFUN(putc, (c, fp), { #if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) int result; - CHECK_INIT (_REENT); + CHECK_INIT (_REENT, fp); _flockfile (fp); result = __sputc_r (_REENT, c, fp); _funlockfile (fp); diff --git a/newlib/libc/stdio/refill.c b/newlib/libc/stdio/refill.c index 047387e79..75ba0565f 100644 --- a/newlib/libc/stdio/refill.c +++ b/newlib/libc/stdio/refill.c @@ -43,7 +43,7 @@ _DEFUN(__srefill_r, (ptr, fp), { /* make sure stdio is set up */ - CHECK_INIT (_REENT); + CHECK_INIT (_REENT, fp); fp->_r = 0; /* largely a convenience for callers */ diff --git a/newlib/libc/stdio/setvbuf.c b/newlib/libc/stdio/setvbuf.c index f6871c59d..561f68b54 100644 --- a/newlib/libc/stdio/setvbuf.c +++ b/newlib/libc/stdio/setvbuf.c @@ -104,7 +104,7 @@ _DEFUN(setvbuf, (fp, buf, mode, size), { int ret = 0; - CHECK_INIT (_REENT); + CHECK_INIT (_REENT, fp); _flockfile (fp); diff --git a/newlib/libc/stdio/ungetc.c b/newlib/libc/stdio/ungetc.c index fc6fa3160..333baa278 100644 --- a/newlib/libc/stdio/ungetc.c +++ b/newlib/libc/stdio/ungetc.c @@ -81,7 +81,7 @@ _DEFUN(_ungetc_r, (rptr, c, fp), ??? 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 (rptr); + CHECK_INIT (rptr, fp); _flockfile (fp); diff --git a/newlib/libc/stdio/vfprintf.c b/newlib/libc/stdio/vfprintf.c index 9e5477aa6..91b2c234d 100644 --- a/newlib/libc/stdio/vfprintf.c +++ b/newlib/libc/stdio/vfprintf.c @@ -540,7 +540,7 @@ _DEFUN(_VFPRINTF_R, (data, fp, fmt0, ap), (u_long)GET_ARG (N, ap, u_int)) #endif - CHECK_INIT (data); + CHECK_INIT (data, fp); _flockfile (fp); /* sorry, fprintf(read_only_file, "") returns EOF, not 0 */ diff --git a/newlib/libc/stdio/vfscanf.c b/newlib/libc/stdio/vfscanf.c index 7bf0aaf9a..c9808bb48 100644 --- a/newlib/libc/stdio/vfscanf.c +++ b/newlib/libc/stdio/vfscanf.c @@ -231,7 +231,7 @@ _DEFUN(VFSCANF, (fp, fmt, ap), _CONST char *fmt _AND va_list ap) { - CHECK_INIT(_REENT); + CHECK_INIT(_REENT, fp); return __SVFSCANF_R (_REENT, fp, fmt, ap); } @@ -253,7 +253,7 @@ _DEFUN(_VFSCANF_R, (data, fp, fmt, ap), _CONST char *fmt _AND va_list ap) { - CHECK_INIT(data); + CHECK_INIT(data, fp); return __SVFSCANF_R (data, fp, fmt, ap); } diff --git a/newlib/libc/stdio/wbuf.c b/newlib/libc/stdio/wbuf.c index 0d2b72ea1..5f1e85a27 100644 --- a/newlib/libc/stdio/wbuf.c +++ b/newlib/libc/stdio/wbuf.c @@ -42,7 +42,7 @@ _DEFUN(__swbuf_r, (ptr, c, fp), /* Ensure stdio has been initialized. */ - CHECK_INIT (ptr); + CHECK_INIT (ptr, fp); /* * In case we cannot write, or longjmp takes us out early, diff --git a/newlib/libc/stdio/wsetup.c b/newlib/libc/stdio/wsetup.c index cf56c2abc..ba98813b3 100644 --- a/newlib/libc/stdio/wsetup.c +++ b/newlib/libc/stdio/wsetup.c @@ -34,7 +34,7 @@ _DEFUN(__swsetup, (fp), { /* Make sure stdio is set up. */ - CHECK_INIT (_REENT); + CHECK_INIT (_REENT, fp); /* * If we are not writing, we had better be reading and writing. |