From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20242 invoked by alias); 29 Jun 2017 06:18:41 -0000 Mailing-List: contact newlib-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: newlib-owner@sourceware.org Received: (qmail 20042 invoked by uid 89); 29 Jun 2017 06:18:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.5 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: dedi548.your-server.de Received: from dedi548.your-server.de (HELO dedi548.your-server.de) (85.10.215.148) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 29 Jun 2017 06:18:34 +0000 Received: from [88.198.220.130] (helo=sslproxy01.your-server.de) by dedi548.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.85_2) (envelope-from ) id 1dQSme-0006Vy-6K for newlib@sourceware.org; Thu, 29 Jun 2017 08:18:32 +0200 Received: from [82.135.62.35] (helo=mail.embedded-brains.de) by sslproxy01.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dQSmd-0003Z2-Sr for newlib@sourceware.org; Thu, 29 Jun 2017 08:18:32 +0200 Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 0BACC2A167A for ; Thu, 29 Jun 2017 08:18:33 +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 mvMzZht8jq2c for ; Thu, 29 Jun 2017 08:18:32 +0200 (CEST) Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id A2FBD2A167C for ; Thu, 29 Jun 2017 08:18:32 +0200 (CEST) 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 5hXYzlieCN2a for ; Thu, 29 Jun 2017 08:18:32 +0200 (CEST) Received: from huber-linux.eb.localhost (unknown [192.168.96.129]) by mail.embedded-brains.de (Postfix) with ESMTP id 847D72A1677 for ; Thu, 29 Jun 2017 08:18:32 +0200 (CEST) From: Sebastian Huber To: newlib@sourceware.org Subject: [PATCH 2/5] Add stdin_init(), stdout_init() and stderr_init() Date: Thu, 29 Jun 2017 06:18:00 -0000 Message-Id: <20170629061830.6992-2-sebastian.huber@embedded-brains.de> In-Reply-To: <20170629061830.6992-1-sebastian.huber@embedded-brains.de> References: <20170629061830.6992-1-sebastian.huber@embedded-brains.de> X-IsSubscribed: yes X-SW-Source: 2017/txt/msg00502.txt.bz2 This simplifies further changes in this area. Signed-off-by: Sebastian Huber --- newlib/libc/stdio/findfp.c | 50 ++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c index ecc65d6d3..b40aa9240 100644 --- a/newlib/libc/stdio/findfp.c +++ b/newlib/libc/stdio/findfp.c @@ -84,6 +84,36 @@ _DEFUN(std, (ptr, flags, file), #endif } +static inline void +stdin_init(FILE *ptr) +{ + std (ptr, __SRD, 0); +} + +static inline void +stdout_init(FILE *ptr) +{ + /* On platforms that have true file system I/O, we can verify + whether stdout is an interactive terminal or not, as part of + __smakebuf on first use of the stream. For all other platforms, + we will default to line buffered mode here. Technically, POSIX + requires both stdin and stdout to be line-buffered, but tradition + leaves stdin alone on systems without fcntl. */ +#ifdef HAVE_FCNTL + std (ptr, __SWR, 1); +#else + std (ptr, __SWR | __SLBF, 1); +#endif +} + +static inline void +stderr_init(FILE *ptr) +{ + /* POSIX requires stderr to be opened for reading and writing, even + when the underlying fd 2 is write-only. */ + std (ptr, __SRW | __SNBF, 2); +} + struct glue_with_file { struct _glue glue; FILE file; @@ -235,23 +265,9 @@ _DEFUN(__sinit, (s), s->_stderr = __sfp(s); #endif - std (s->_stdin, __SRD, 0); - - /* On platforms that have true file system I/O, we can verify - whether stdout is an interactive terminal or not, as part of - __smakebuf on first use of the stream. For all other platforms, - we will default to line buffered mode here. Technically, POSIX - requires both stdin and stdout to be line-buffered, but tradition - leaves stdin alone on systems without fcntl. */ -#ifdef HAVE_FCNTL - std (s->_stdout, __SWR, 1); -#else - std (s->_stdout, __SWR | __SLBF, 1); -#endif - - /* POSIX requires stderr to be opened for reading and writing, even - when the underlying fd 2 is write-only. */ - std (s->_stderr, __SRW | __SNBF, 2); + stdin_init (s->_stdin); + stdout_init (s->_stdout); + stderr_init (s->_stderr); s->__sdidinit = 1; -- 2.12.3