From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) by sourceware.org (Postfix) with ESMTPS id 2E522383D80A for ; Thu, 12 May 2022 12:11:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2E522383D80A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embedded-brains.de Received: from sslproxy06.your-server.de ([78.46.172.3]) by dedi548.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1np7fZ-0001O5-Oj for newlib@sourceware.org; Thu, 12 May 2022 14:11:50 +0200 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy06.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1np7fZ-0007A1-T3 for newlib@sourceware.org; Thu, 12 May 2022 14:11:49 +0200 Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 961394800BE for ; Thu, 12 May 2022 14:11:49 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id OGzw-WwBySxY; Thu, 12 May 2022 14:11:49 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 4B31C480180; Thu, 12 May 2022 14:11:49 +0200 (CEST) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Qt-6sjp8tRTK; Thu, 12 May 2022 14:11:49 +0200 (CEST) Received: from joyce-tux.eb.localhost (unknown [10.10.171.30]) by mail.embedded-brains.de (Postfix) with ESMTPSA id 1BB204800BE; Thu, 12 May 2022 14:11:49 +0200 (CEST) From: Matthew Joyce To: newlib@sourceware.org Subject: [PATCH v2 07/11] Add CLEANUP_FILE define Date: Thu, 12 May 2022 14:11:39 +0200 Message-Id: <20220512121143.21473-8-matthew.joyce@embedded-brains.de> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220512121143.21473-1-matthew.joyce@embedded-brains.de> References: <20220512121143.21473-1-matthew.joyce@embedded-brains.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.103.5/26539/Thu May 12 10:04:41 2022) X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 May 2022 12:11:56 -0000 From: Matt Joyce Define the configuration-dependent constant CLEANUP_FILE for use in cleanup_stdio(). This will reduce duplicate code during the addition of a dedicated stdio atexit handler in a follow-on patch. --- newlib/libc/stdio/findfp.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c index 7434c343c..5b0402ac1 100644 --- a/newlib/libc/stdio/findfp.c +++ b/newlib/libc/stdio/findfp.c @@ -39,6 +39,21 @@ const struct __sFILE_fake __sf_fake_stderr =3D __FILE __sf[3]; #endif =20 +#ifdef _STDIO_BSD_SEMANTICS + /* BSD and Glibc systems only flush streams which have been written to + at exit time. Calling flush rather than close for speed, as on + the aforementioned systems. */ +#define CLEANUP_FILE __sflushw_r +#else + /* Otherwise close files and flush read streams, too. + Note we call flush directly if "--enable-lite-exit" is in effect. = */ +#ifdef _LITE_EXIT +#define CLEANUP_FILE _fflush_r +#else +#define CLEANUP_FILE _fclose_r +#endif +#endif + #if (defined (__OPTIMIZE_SIZE__) || defined (PREFER_SIZE_OVER_SPEED)) _NOINLINE_STATIC void #else @@ -208,30 +223,15 @@ found: static void cleanup_stdio (struct _reent *ptr) { - int (*cleanup_func) (struct _reent *, FILE *); -#ifdef _STDIO_BSD_SEMANTICS - /* BSD and Glibc systems only flush streams which have been written to - at exit time. Calling flush rather than close for speed, as on - the aforementioned systems. */ - cleanup_func =3D __sflushw_r; -#else - /* Otherwise close files and flush read streams, too. - Note we call flush directly if "--enable-lite-exit" is in effect. = */ -#ifdef _LITE_EXIT - cleanup_func =3D _fflush_r; -#else - cleanup_func =3D _fclose_r; -#endif -#endif #ifdef _REENT_GLOBAL_STDIO_STREAMS if (ptr->_stdin !=3D &__sf[0]) - (*cleanup_func) (ptr, ptr->_stdin); + CLEANUP_FILE (ptr, ptr->_stdin); if (ptr->_stdout !=3D &__sf[1]) - (*cleanup_func) (ptr, ptr->_stdout); + CLEANUP_FILE (ptr, ptr->_stdout); if (ptr->_stderr !=3D &__sf[2]) - (*cleanup_func) (ptr, ptr->_stderr); + CLEANUP_FILE (ptr, ptr->_stderr); #endif - (void) _fwalk_reent (ptr, cleanup_func); + (void) _fwalk_reent (ptr, CLEANUP_FILE); } =20 /* --=20 2.31.1