From patchwork Thu Mar 10 13:54:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 595790 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 498B4140271 for ; Fri, 11 Mar 2016 00:54:40 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b=cq8qWtjT; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:to:from:subject:message-id:date:mime-version :content-type; q=dns; s=default; b=ld9SSrKS767+pDadQ3pFe2XeMmIsM OPukoXs0RLn6twH2GZ0A/AdUrb7Rp2AjC4vYL0wCQyRen7pr9zxfoDVqI3D2m8B5 /iHHdwkeGyCrwJ4ZUfjSc+xZ5wwrmmczMx3slVYp98GOIpJSJn7umQiCrDViLfR8 t3XnSTX3CX3ErA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:to:from:subject:message-id:date:mime-version :content-type; s=default; bh=KrluEDrZkx+t8tEcQruLwbs7yKA=; b=cq8 qWtjTN4lFlSf0YbAz+GvDrllp/m1eZrZdVDvK4LqnW5LHIZ9q+3BI1KGBzwazz/k s0tsyeNKbCz+NLTKgWr8YGkb512hRFwAbIRKvc71HlDSEbJn4Ms0rPpO1Hg4+61Z kFq/mYro5hnTFfURgVuoFHGidlGr+A13GoL++8N4= Received: (qmail 54497 invoked by alias); 10 Mar 2016 13:54:30 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 53776 invoked by uid 89); 10 Mar 2016 13:54:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=no version=3.3.2 spammy=1991, streams, buffering, TTY X-HELO: mx1.redhat.com To: GNU C Library From: Florian Weimer Subject: [PATCH] libio: Always use _IO_BUFSIZE for stream buffers [BZ #4099] X-Enigmail-Draft-Status: N1110 Message-ID: <56E17C8E.1070209@redhat.com> Date: Thu, 10 Mar 2016 14:54:22 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 MIME-Version: 1.0 Separating this change, as requested by Roland. Thanks, Florian 2016-03-08 Florian Weimer [BZ #4099] * libio/filedoalloc.c (_IO_file_doallocate): Always use _IO_BUFSIZ as the buffer size. diff --git a/libio/filedoalloc.c b/libio/filedoalloc.c index 4f9d738..74ff79b 100644 --- a/libio/filedoalloc.c +++ b/libio/filedoalloc.c @@ -56,8 +56,6 @@ /* Modified for GNU iostream by Per Bothner 1991, 1992. */ #include "libioP.h" -#include -#include #include #include @@ -72,36 +70,17 @@ local_isatty (int fd) } /* Allocate a file buffer, or switch to unbuffered I/O. Streams for - TTY devices default to line buffered. */ + * TTY devices default to line buffered. */ int _IO_file_doallocate (_IO_FILE *fp) { - _IO_size_t size; - char *p; - struct stat64 st; - - size = _IO_BUFSIZ; - if (fp->_fileno >= 0 && __builtin_expect (_IO_SYSSTAT (fp, &st), 0) >= 0) - { - if (S_ISCHR (st.st_mode)) - { - /* Possibly a tty. */ - if ( -#ifdef DEV_TTY_P - DEV_TTY_P (&st) || -#endif - local_isatty (fp->_fileno)) - fp->_flags |= _IO_LINE_BUF; - } -#if _IO_HAVE_ST_BLKSIZE - if (st.st_blksize > 0) - size = st.st_blksize; -#endif - } - p = malloc (size); + /* Switch to line buffering for TTYs. */ + if (fp->_fileno >= 0 && local_isatty (fp->_fileno)) + fp->_flags |= _IO_LINE_BUF; + char *p = malloc (_IO_BUFSIZ); if (__glibc_unlikely (p == NULL)) return EOF; - _IO_setb (fp, p, p + size, 1); + _IO_setb (fp, p, p + _IO_BUFSIZ, 1); return 1; } libc_hidden_def (_IO_file_doallocate) -- 2.4.3