diff options
Diffstat (limited to 'newlib/libc/stdio')
27 files changed, 135 insertions, 72 deletions
diff --git a/newlib/libc/stdio/fgetc.c b/newlib/libc/stdio/fgetc.c index 99d8330fe..20492d24b 100644 --- a/newlib/libc/stdio/fgetc.c +++ b/newlib/libc/stdio/fgetc.c @@ -92,9 +92,11 @@ _DEFUN(fgetc, (fp), { #if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) int result; - CHECK_INIT(_REENT, fp); + struct _reent *reent = _REENT; + + CHECK_INIT(reent, fp); _newlib_flockfile_start (fp); - result = __sgetc_r (_REENT, fp); + result = __sgetc_r (reent, fp); _newlib_flockfile_end (fp); return result; #else diff --git a/newlib/libc/stdio/fgetwc.c b/newlib/libc/stdio/fgetwc.c index 0eaaecb2f..14c554786 100644 --- a/newlib/libc/stdio/fgetwc.c +++ b/newlib/libc/stdio/fgetwc.c @@ -175,6 +175,8 @@ wint_t _DEFUN(fgetwc, (fp), FILE *fp) { - CHECK_INIT(_REENT, fp); - return _fgetwc_r (_REENT, fp); + struct _reent *reent = _REENT; + + CHECK_INIT(reent, fp); + return _fgetwc_r (reent, fp); } diff --git a/newlib/libc/stdio/fgetws.c b/newlib/libc/stdio/fgetws.c index 3cf45a976..b5d8851e1 100644 --- a/newlib/libc/stdio/fgetws.c +++ b/newlib/libc/stdio/fgetws.c @@ -160,6 +160,8 @@ _DEFUN(fgetws, (ws, n, fp), int n _AND FILE *fp) { - CHECK_INIT (_REENT, fp); - return _fgetws_r (_REENT, ws, n, fp); + struct _reent *reent = _REENT; + + CHECK_INIT (reent, fp); + return _fgetws_r (reent, ws, n, fp); } diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c index 7ab3bdba5..e40500a07 100644 --- a/newlib/libc/stdio/findfp.c +++ b/newlib/libc/stdio/findfp.c @@ -62,7 +62,11 @@ _DEFUN(std, (ptr, flags, file, data), ptr->_flags |= __SL64; #endif /* __LARGE64_FILES */ ptr->_seek = __sseek; +#ifdef _STDIO_CLOSE_PER_REENT_STD_STREAMS ptr->_close = __sclose; +#else /* _STDIO_CLOSE_STD_STREAMS */ + ptr->_close = NULL; +#endif /* _STDIO_CLOSE_STD_STREAMS */ #if !defined(__SINGLE_THREAD__) && !defined(_REENT_SMALL) __lock_init_recursive (ptr->_lock); /* diff --git a/newlib/libc/stdio/fputc.c b/newlib/libc/stdio/fputc.c index 6af79d470..f380717d1 100644 --- a/newlib/libc/stdio/fputc.c +++ b/newlib/libc/stdio/fputc.c @@ -97,9 +97,11 @@ _DEFUN(fputc, (ch, file), { #if !defined(__OPTIMIZE_SIZE__) && !defined(PREFER_SIZE_OVER_SPEED) int result; - CHECK_INIT(_REENT, file); + struct _reent *reent = _REENT; + + CHECK_INIT(reent, file); _newlib_flockfile_start (file); - result = _putc_r (_REENT, ch, file); + result = _putc_r (reent, ch, file); _newlib_flockfile_end (file); return result; #else diff --git a/newlib/libc/stdio/fputwc.c b/newlib/libc/stdio/fputwc.c index 74e7a452c..5ec85d1ab 100644 --- a/newlib/libc/stdio/fputwc.c +++ b/newlib/libc/stdio/fputwc.c @@ -172,6 +172,8 @@ _DEFUN(fputwc, (wc, fp), wchar_t wc _AND FILE *fp) { - CHECK_INIT(_REENT, fp); - return _fputwc_r (_REENT, wc, fp); + struct _reent *reent = _REENT; + + CHECK_INIT(reent, fp); + return _fputwc_r (reent, wc, fp); } diff --git a/newlib/libc/stdio/fputws.c b/newlib/libc/stdio/fputws.c index 0893b3c33..a28a5551b 100644 --- a/newlib/libc/stdio/fputws.c +++ b/newlib/libc/stdio/fputws.c @@ -145,6 +145,8 @@ _DEFUN(fputws, (ws, fp), const wchar_t *ws _AND FILE *fp) { - CHECK_INIT (_REENT, fp); - return _fputws_r (_REENT, ws, fp); + struct _reent *reent = _REENT; + + CHECK_INIT (reent, fp); + return _fputws_r (reent, ws, fp); } diff --git a/newlib/libc/stdio/fwalk.c b/newlib/libc/stdio/fwalk.c index df92d1d81..975e4b001 100644 --- a/newlib/libc/stdio/fwalk.c +++ b/newlib/libc/stdio/fwalk.c @@ -46,11 +46,8 @@ _DEFUN(_fwalk, (ptr, function), */ for (g = &ptr->__sglue; g != NULL; g = g->_next) for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++) - if (fp->_flags != 0) - { - if (fp->_flags != 0 && fp->_flags != 1 && fp->_file != -1) - ret |= (*function) (fp); - } + if (fp->_flags != 0 && fp->_flags != 1 && fp->_file != -1) + ret |= (*function) (fp); return ret; } diff --git a/newlib/libc/stdio/getc.c b/newlib/libc/stdio/getc.c index 355b19131..7951cdc93 100644 --- a/newlib/libc/stdio/getc.c +++ b/newlib/libc/stdio/getc.c @@ -105,9 +105,11 @@ _DEFUN(getc, (fp), register FILE *fp) { int result; - CHECK_INIT (_REENT, fp); + struct _reent *reent = _REENT; + + CHECK_INIT (reent, fp); _newlib_flockfile_start (fp); - result = __sgetc_r (_REENT, fp); + result = __sgetc_r (reent, fp); _newlib_flockfile_end (fp); return result; } diff --git a/newlib/libc/stdio/getchar.c b/newlib/libc/stdio/getchar.c index da2f5dfaf..7f3ceac62 100644 --- a/newlib/libc/stdio/getchar.c +++ b/newlib/libc/stdio/getchar.c @@ -91,9 +91,11 @@ _DEFUN(_getchar_r, (reent), int _DEFUN_VOID(getchar) { + struct _reent *reent = _REENT; + /* CHECK_INIT is called (eventually) by __srefill_r. */ - _REENT_SMALL_CHECK_INIT (_REENT); - return _getc_r (_REENT, _stdin_r (_REENT)); + _REENT_SMALL_CHECK_INIT (reent); + return _getc_r (reent, _stdin_r (reent)); } #endif diff --git a/newlib/libc/stdio/local.h b/newlib/libc/stdio/local.h index cbfeac77d..54854b49d 100644 --- a/newlib/libc/stdio/local.h +++ b/newlib/libc/stdio/local.h @@ -32,6 +32,16 @@ # include <io.h> #endif +/* The following define determines if the per-reent stdin, stdout and stderr + streams are closed during _reclaim_reent(). The stdin, stdout and stderr + streams are initialized to use file descriptors 0, 1 and 2 respectively. In + case _STDIO_CLOSE_PER_REENT_STD_STREAMS is defined these file descriptors + will be closed via close() provided the owner of the reent structure + triggerd the on demand reent initilization, see CHECK_INIT(). */ +#ifndef __rtems__ +#define _STDIO_CLOSE_PER_REENT_STD_STREAMS +#endif + /* The following macros are supposed to replace calls to _flockfile/_funlockfile and __sfp_lock_acquire/__sfp_lock_release. In case of multi-threaded environments using pthreads, it's not sufficient to lock the stdio functions @@ -165,34 +175,37 @@ extern _READ_WRITE_RETURN_TYPE _EXFUN(__swrite64,(struct _reent *, void *, #ifdef _REENT_SMALL #define CHECK_INIT(ptr, fp) \ - do \ - { \ - if ((ptr) && !(ptr)->__sdidinit) \ - __sinit (ptr); \ - if ((fp) == (FILE *)&__sf_fake_stdin) \ - (fp) = _stdin_r(ptr); \ - else if ((fp) == (FILE *)&__sf_fake_stdout) \ - (fp) = _stdout_r(ptr); \ - else if ((fp) == (FILE *)&__sf_fake_stderr) \ - (fp) = _stderr_r(ptr); \ - } \ + do \ + { \ + struct _reent *_check_init_ptr = (ptr); \ + if ((_check_init_ptr) && !(_check_init_ptr)->__sdidinit) \ + __sinit (_check_init_ptr); \ + if ((fp) == (FILE *)&__sf_fake_stdin) \ + (fp) = _stdin_r(_check_init_ptr); \ + else if ((fp) == (FILE *)&__sf_fake_stdout) \ + (fp) = _stdout_r(_check_init_ptr); \ + else if ((fp) == (FILE *)&__sf_fake_stderr) \ + (fp) = _stderr_r(_check_init_ptr); \ + } \ while (0) #else /* !_REENT_SMALL */ #define CHECK_INIT(ptr, fp) \ - do \ - { \ - if ((ptr) && !(ptr)->__sdidinit) \ - __sinit (ptr); \ - } \ + do \ + { \ + struct _reent *_check_init_ptr = (ptr); \ + if ((_check_init_ptr) && !(_check_init_ptr)->__sdidinit) \ + __sinit (_check_init_ptr); \ + } \ while (0) #endif /* !_REENT_SMALL */ #define CHECK_STD_INIT(ptr) \ - do \ - { \ - if ((ptr) && !(ptr)->__sdidinit) \ - __sinit (ptr); \ - } \ + do \ + { \ + struct _reent *_check_init_ptr = (ptr); \ + if ((_check_init_ptr) && !(_check_init_ptr)->__sdidinit) \ + __sinit (_check_init_ptr); \ + } \ while (0) /* Return true and set errno and stream error flag iff the given FILE diff --git a/newlib/libc/stdio/putc.c b/newlib/libc/stdio/putc.c index 1115bf40d..2b1fd1bf3 100644 --- a/newlib/libc/stdio/putc.c +++ b/newlib/libc/stdio/putc.c @@ -111,9 +111,11 @@ _DEFUN(putc, (c, fp), { #if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) int result; - CHECK_INIT (_REENT, fp); + struct _reent *reent = _REENT; + + CHECK_INIT (reent, fp); _newlib_flockfile_start (fp); - result = __sputc_r (_REENT, c, fp); + result = __sputc_r (reent, c, fp); _newlib_flockfile_end (fp); return result; #else diff --git a/newlib/libc/stdio/putchar.c b/newlib/libc/stdio/putchar.c index 06bcbb46e..bb27dc4e6 100644 --- a/newlib/libc/stdio/putchar.c +++ b/newlib/libc/stdio/putchar.c @@ -90,8 +90,10 @@ int _DEFUN(putchar, (c), int c) { - _REENT_SMALL_CHECK_INIT (_REENT); - return _putc_r (_REENT, c, _stdout_r (_REENT)); + struct _reent *reent = _REENT; + + _REENT_SMALL_CHECK_INIT (reent); + return _putc_r (reent, c, _stdout_r (reent)); } #endif diff --git a/newlib/libc/stdio/scanf.c b/newlib/libc/stdio/scanf.c index 68fd8fb65..19c85be4f 100644 --- a/newlib/libc/stdio/scanf.c +++ b/newlib/libc/stdio/scanf.c @@ -38,14 +38,15 @@ scanf(fmt, va_alist) { int ret; va_list ap; + struct _reent *reent = _REENT; - _REENT_SMALL_CHECK_INIT (_REENT); + _REENT_SMALL_CHECK_INIT (reent); #ifdef _HAVE_STDC va_start (ap, fmt); #else va_start (ap); #endif - ret = _vfscanf_r (_REENT, _stdin_r (_REENT), fmt, ap); + ret = _vfscanf_r (reent, _stdin_r (reent), fmt, ap); va_end (ap); return ret; } diff --git a/newlib/libc/stdio/setvbuf.c b/newlib/libc/stdio/setvbuf.c index 63f1f80db..41bdff6b6 100644 --- a/newlib/libc/stdio/setvbuf.c +++ b/newlib/libc/stdio/setvbuf.c @@ -103,8 +103,9 @@ _DEFUN(setvbuf, (fp, buf, mode, size), register size_t size) { int ret = 0; + struct _reent *reent = _REENT; - CHECK_INIT (_REENT, fp); + CHECK_INIT (reent, fp); _newlib_flockfile_start (fp); @@ -126,11 +127,11 @@ _DEFUN(setvbuf, (fp, buf, mode, size), * non buffer flags, and clear malloc flag. */ - _fflush_r (_REENT, fp); + _fflush_r (reent, fp); fp->_r = 0; fp->_lbfsize = 0; if (fp->_flags & __SMBF) - _free_r (_REENT, (_PTR) fp->_bf._base); + _free_r (reent, (_PTR) fp->_bf._base); fp->_flags &= ~(__SLBF | __SNBF | __SMBF); if (mode == _IONBF) @@ -180,7 +181,7 @@ nbf: case _IOFBF: /* no flag */ - _REENT->__cleanup = _cleanup_r; + reent->__cleanup = _cleanup_r; fp->_bf._base = fp->_p = (unsigned char *) buf; fp->_bf._size = size; break; diff --git a/newlib/libc/stdio/ungetwc.c b/newlib/libc/stdio/ungetwc.c index ee0d7fc75..a69449eb2 100644 --- a/newlib/libc/stdio/ungetwc.c +++ b/newlib/libc/stdio/ungetwc.c @@ -110,6 +110,8 @@ _DEFUN(ungetwc, (wint_t wc, FILE *fp), wint_t wc _AND FILE *fp) { - CHECK_INIT (_REENT, fp); - return _ungetwc_r (_REENT, wc, fp); + struct _reent *reent = _REENT; + + CHECK_INIT (reent, fp); + return _ungetwc_r (reent, wc, fp); } diff --git a/newlib/libc/stdio/vfprintf.c b/newlib/libc/stdio/vfprintf.c index e5fcb0331..dd9c22a6d 100644 --- a/newlib/libc/stdio/vfprintf.c +++ b/newlib/libc/stdio/vfprintf.c @@ -447,6 +447,7 @@ int __sfputs_r (struct _reent *, FILE *, _CONST char *buf, size_t); int __sprint_r (struct _reent *, FILE *, register struct __suio *); #endif /* !INTEGER_ONLY */ +#ifdef _UNBUF_STREAM_OPT /* * Helper function for `fprintf to unbuffered unix file': creates a * temporary buffer. We only work on write-only files; this avoids @@ -492,6 +493,7 @@ _DEFUN(__sbprintf, (rptr, fp, fmt, ap), #endif return (ret); } +#endif /* _UNBUF_STREAM_OPT */ #endif /* !STRING_ONLY */ @@ -865,12 +867,14 @@ _DEFUN(_VFPRINTF_R, (data, fp, fmt0, ap), return (EOF); } +#ifdef _UNBUF_STREAM_OPT /* optimise fprintf(stderr) (and other unbuffered Unix files) */ if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) && fp->_file >= 0) { _newlib_flockfile_exit (fp); return (__sbprintf (data, fp, fmt0, ap)); } +#endif #else /* STRING_ONLY */ /* Create initial buffer if we are called by asprintf family. */ if (fp->_flags & __SMBF && !fp->_bf._base) diff --git a/newlib/libc/stdio/vfscanf.c b/newlib/libc/stdio/vfscanf.c index e967719b7..ae94cea3f 100644 --- a/newlib/libc/stdio/vfscanf.c +++ b/newlib/libc/stdio/vfscanf.c @@ -266,8 +266,10 @@ _DEFUN(VFSCANF, (fp, fmt, ap), _CONST char *fmt _AND va_list ap) { - CHECK_INIT(_REENT, fp); - return __SVFSCANF_R (_REENT, fp, fmt, ap); + struct _reent *reent = _REENT; + + CHECK_INIT(reent, fp); + return __SVFSCANF_R (reent, fp, fmt, ap); } int diff --git a/newlib/libc/stdio/vfwprintf.c b/newlib/libc/stdio/vfwprintf.c index 5860147ec..4788add23 100644 --- a/newlib/libc/stdio/vfwprintf.c +++ b/newlib/libc/stdio/vfwprintf.c @@ -166,6 +166,7 @@ int _EXFUN(__SPRINT, (struct _reent *, FILE *, register struct __suio *)); int _EXFUN(__SPRINT, (struct _reent *, FILE *, _CONST char *, size_t)); #endif #ifndef STRING_ONLY +#ifdef _UNBUF_STREAM_OPT /* * Helper function for `fprintf to unbuffered unix file': creates a * temporary buffer. We only work on write-only files; this avoids @@ -209,6 +210,7 @@ _DEFUN(__sbwprintf, (rptr, fp, fmt, ap), #endif return (ret); } +#endif /* _UNBUF_STREAM_OPT */ #endif /* !STRING_ONLY */ @@ -599,12 +601,14 @@ _DEFUN(_VFWPRINTF_R, (data, fp, fmt0, ap), return (EOF); } +#ifdef _UNBUF_STREAM_OPT /* optimise fwprintf(stderr) (and other unbuffered Unix files) */ if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) && fp->_file >= 0) { _newlib_flockfile_exit (fp); return (__sbwprintf (data, fp, fmt0, ap)); } +#endif #else /* STRING_ONLY */ /* Create initial buffer if we are called by asprintf family. */ if (fp->_flags & __SMBF && !fp->_bf._base) diff --git a/newlib/libc/stdio/vfwscanf.c b/newlib/libc/stdio/vfwscanf.c index 5d2388df8..3379b5e19 100644 --- a/newlib/libc/stdio/vfwscanf.c +++ b/newlib/libc/stdio/vfwscanf.c @@ -258,8 +258,10 @@ _DEFUN(VFWSCANF, (fp, fmt, ap), _CONST wchar_t *fmt _AND va_list ap) { - CHECK_INIT(_REENT, fp); - return __SVFWSCANF_R (_REENT, fp, fmt, ap); + struct _reent *reent = _REENT; + + CHECK_INIT(reent, fp); + return __SVFWSCANF_R (reent, fp, fmt, ap); } int diff --git a/newlib/libc/stdio/viprintf.c b/newlib/libc/stdio/viprintf.c index 3717f3a08..fec92fa8a 100644 --- a/newlib/libc/stdio/viprintf.c +++ b/newlib/libc/stdio/viprintf.c @@ -109,8 +109,10 @@ _DEFUN(viprintf, (fmt, ap), _CONST char *fmt _AND va_list ap) { - _REENT_SMALL_CHECK_INIT (_REENT); - return _vfiprintf_r (_REENT, _stdout_r (_REENT), fmt, ap); + struct _reent *reent = _REENT; + + _REENT_SMALL_CHECK_INIT (reent); + return _vfiprintf_r (reent, _stdout_r (reent), fmt, ap); } #endif /* !_REENT_ONLY */ diff --git a/newlib/libc/stdio/viscanf.c b/newlib/libc/stdio/viscanf.c index a60c32ff0..9a7d0c5f2 100644 --- a/newlib/libc/stdio/viscanf.c +++ b/newlib/libc/stdio/viscanf.c @@ -127,8 +127,10 @@ _DEFUN(viscanf, (fmt, ap), _CONST char *fmt _AND va_list ap) { - _REENT_SMALL_CHECK_INIT (_REENT); - return __svfiscanf_r (_REENT, _stdin_r (_REENT), fmt, ap); + struct _reent *reent = _REENT; + + _REENT_SMALL_CHECK_INIT (reent); + return __svfiscanf_r (reent, _stdin_r (reent), fmt, ap); } #endif /* !_REENT_ONLY */ diff --git a/newlib/libc/stdio/vprintf.c b/newlib/libc/stdio/vprintf.c index 69edc87ae..375656972 100644 --- a/newlib/libc/stdio/vprintf.c +++ b/newlib/libc/stdio/vprintf.c @@ -33,8 +33,10 @@ _DEFUN(vprintf, (fmt, ap), _CONST char *fmt _AND va_list ap) { - _REENT_SMALL_CHECK_INIT (_REENT); - return _vfprintf_r (_REENT, _stdout_r (_REENT), fmt, ap); + struct _reent *reent = _REENT; + + _REENT_SMALL_CHECK_INIT (reent); + return _vfprintf_r (reent, _stdout_r (reent), fmt, ap); } #endif /* !_REENT_ONLY */ diff --git a/newlib/libc/stdio/vscanf.c b/newlib/libc/stdio/vscanf.c index e559b77a8..210774b05 100644 --- a/newlib/libc/stdio/vscanf.c +++ b/newlib/libc/stdio/vscanf.c @@ -34,8 +34,10 @@ _DEFUN(vscanf, (fmt, ap), _CONST char *fmt _AND va_list ap) { - _REENT_SMALL_CHECK_INIT (_REENT); - return __svfscanf_r (_REENT, _stdin_r (_REENT), fmt, ap); + struct _reent *reent = _REENT; + + _REENT_SMALL_CHECK_INIT (reent); + return __svfscanf_r (reent, _stdin_r (reent), fmt, ap); } #endif /* !_REENT_ONLY */ diff --git a/newlib/libc/stdio/vwprintf.c b/newlib/libc/stdio/vwprintf.c index ce28fdabb..de95346a0 100644 --- a/newlib/libc/stdio/vwprintf.c +++ b/newlib/libc/stdio/vwprintf.c @@ -30,8 +30,10 @@ _DEFUN(vwprintf, (fmt, ap), _CONST wchar_t *fmt _AND va_list ap) { - _REENT_SMALL_CHECK_INIT (_REENT); - return _vfwprintf_r (_REENT, _stdout_r (_REENT), fmt, ap); + struct _reent *reent = _REENT; + + _REENT_SMALL_CHECK_INIT (reent); + return _vfwprintf_r (reent, _stdout_r (reent), fmt, ap); } #endif /* !_REENT_ONLY */ diff --git a/newlib/libc/stdio/vwscanf.c b/newlib/libc/stdio/vwscanf.c index 3c60fbb73..d0b535170 100644 --- a/newlib/libc/stdio/vwscanf.c +++ b/newlib/libc/stdio/vwscanf.c @@ -33,8 +33,10 @@ int vwscanf (_CONST wchar_t *fmt, va_list ap) { - _REENT_SMALL_CHECK_INIT (_REENT); - return __svfwscanf_r (_REENT, _stdin_r (_REENT), fmt, ap); + struct _reent *reent = _REENT; + + _REENT_SMALL_CHECK_INIT (reent); + return __svfwscanf_r (reent, _stdin_r (reent), fmt, ap); } #endif /* !_REENT_ONLY */ diff --git a/newlib/libc/stdio/wscanf.c b/newlib/libc/stdio/wscanf.c index abe8dc07a..9fee3c176 100644 --- a/newlib/libc/stdio/wscanf.c +++ b/newlib/libc/stdio/wscanf.c @@ -29,10 +29,11 @@ wscanf(_CONST wchar_t *fmt, ...) { int ret; va_list ap; + struct _reent *reent = _REENT; - _REENT_SMALL_CHECK_INIT (_REENT); + _REENT_SMALL_CHECK_INIT (reent); va_start (ap, fmt); - ret = _vfwscanf_r (_REENT, _stdin_r (_REENT), fmt, ap); + ret = _vfwscanf_r (reent, _stdin_r (reent), fmt, ap); va_end (ap); return ret; } |