Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2022-05-17 12:52:24 +0300
committerSebastian Huber <sebastian.huber@embedded-brains.de>2022-05-17 16:04:12 +0300
commite826fbb2ae884257479165476acbc8d8be7d0081 (patch)
tree21bb938a72f674b21a522e8dc34e8822219c3c9c /newlib/libc/stdio
parent93bea9f5387921ec40f35c0c45ff240a433db603 (diff)
Fix stdio exit handling
Make sure that the stdio exit handler is set in all stdio initialization paths. The bug was introduced by commit 26747c47bc0a1137e02e0377306d721cc3478855.
Diffstat (limited to 'newlib/libc/stdio')
-rw-r--r--newlib/libc/stdio/findfp.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c
index 19952d4e0..118637a18 100644
--- a/newlib/libc/stdio/findfp.c
+++ b/newlib/libc/stdio/findfp.c
@@ -168,6 +168,19 @@ stdio_exit_handler (void)
(void) _fwalk_sglue (_GLOBAL_REENT, CLEANUP_FILE, &__sglue);
}
+static void
+global_stdio_init (void)
+{
+ if (__stdio_exit_handler == NULL) {
+ __stdio_exit_handler = stdio_exit_handler;
+#ifdef _REENT_GLOBAL_STDIO_STREAMS
+ stdin_init (&__sf[0]);
+ stdout_init (&__sf[1]);
+ stderr_init (&__sf[2]);
+#endif
+ }
+}
+
/*
* Find a free FILE for fopen et al.
*/
@@ -180,11 +193,7 @@ __sfp (struct _reent *d)
struct _glue *g;
_newlib_sfp_lock_start ();
-
- if (__stdio_exit_handler == NULL) {
- __sinit (_GLOBAL_REENT);
- __stdio_exit_handler = stdio_exit_handler;
- }
+ global_stdio_init ();
for (g = &__sglue;; g = g->_next)
{
@@ -273,13 +282,9 @@ __sinit (struct _reent *s)
# endif /* _REENT_GLOBAL_STDIO_STREAMS */
#endif
-#ifdef _REENT_GLOBAL_STDIO_STREAMS
- if (__sf[0]._cookie == NULL) {
- stdin_init (&__sf[0]);
- stdout_init (&__sf[1]);
- stderr_init (&__sf[2]);
- }
-#else /* _REENT_GLOBAL_STDIO_STREAMS */
+ global_stdio_init ();
+
+#ifndef _REENT_GLOBAL_STDIO_STREAMS
stdin_init (s->_stdin);
stdout_init (s->_stdout);
stderr_init (s->_stderr);