From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1921) id 76D1F3858D3C; Tue, 17 May 2022 16:30:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 76D1F3858D3C Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Sebastian Huber To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] Fix stdio exit handling X-Act-Checkin: newlib-cygwin X-Git-Author: Sebastian Huber X-Git-Refname: refs/heads/master X-Git-Oldrev: 93bea9f5387921ec40f35c0c45ff240a433db603 X-Git-Newrev: e826fbb2ae884257479165476acbc8d8be7d0081 Message-Id: <20220517163048.76D1F3858D3C@sourceware.org> Date: Tue, 17 May 2022 16:30:48 +0000 (GMT) X-BeenThere: newlib-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib GIT logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 May 2022 16:30:48 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3De826fbb2ae8= 84257479165476acbc8d8be7d0081 commit e826fbb2ae884257479165476acbc8d8be7d0081 Author: Sebastian Huber Date: Tue May 17 11:52:24 2022 +0200 Fix stdio exit handling =20 Make sure that the stdio exit handler is set in all stdio initializatio= n paths. =20 The bug was introduced by commit 26747c47bc0a1137e02e0377306d721cc34788= 55. Diff: --- newlib/libc/stdio/findfp.c | 29 +++++++++++++++++------------ 1 file 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); } =20 +static void +global_stdio_init (void) +{ + if (__stdio_exit_handler =3D=3D NULL) { + __stdio_exit_handler =3D 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; =20 _newlib_sfp_lock_start (); - - if (__stdio_exit_handler =3D=3D NULL) { - __sinit (_GLOBAL_REENT); - __stdio_exit_handler =3D stdio_exit_handler; - } + global_stdio_init (); =20 for (g =3D &__sglue;; g =3D g->_next) { @@ -273,13 +282,9 @@ __sinit (struct _reent *s) # endif /* _REENT_GLOBAL_STDIO_STREAMS */ #endif =20 -#ifdef _REENT_GLOBAL_STDIO_STREAMS - if (__sf[0]._cookie =3D=3D 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);