delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2015/02/27/11:21:37

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:mime-version:from:date:message-id:subject:to
:content-type; q=dns; s=default; b=qddJnJGrpBmUY2DF+mMpUMU1K3Z9m
GJ/yK854nCLx482PmXzTrK72hgeLAy55GmBumb21RgUJV4biNNJO7fxpGNB/ka8E
bzCKyXy7dUQwdPjD7a8LN1OufM178FGNBfne75V/CiIgQmRUgZFOwjNJxNZZDudk
FpGXJ59b7+gU74=
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:mime-version:from:date:message-id:subject:to
:content-type; s=default; bh=TfhHvJ5OD87XATNep8Xx4LxsBmk=; b=M8p
55oGHI1cWVNWGP1C35Ljyr3QK2OlQbg96Yo/qAoXqYYNTct6cI3NWr4lsb+ifSm2
jcfcYpYJZ8WQdXm/SrgxWh1gR7plVGhaEfQ6njvpy0A3tOa4WxCZOai1LUl+TtGk
oP6sEvaGOHO46Gpc/rt0FZIP2vj9ZEohqixBI7tg=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=3.7 required=5.0 tests=AWL,BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,KAM_FROM_URIBL_PCCC,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=no version=3.3.2
X-HELO: mail-lb0-f179.google.com
X-Received: by 10.152.8.33 with SMTP id o1mr13700501laa.56.1425054076091; Fri, 27 Feb 2015 08:21:16 -0800 (PST)
MIME-Version: 1.0
From: A L <al20878 AT gmail DOT com>
Date: Fri, 27 Feb 2015 11:20:55 -0500
Message-ID: <CAKVG1_qobJxAZSeZDozsGb7pb3ugYk_AgmEJXU-wRt+ifhf-QA@mail.gmail.com>
Subject: Re: freopen/fread/popen bug
To: cygwin AT cygwin DOT com

> I think that would create an unacceptable performance penalty for the child process.

The child process would not be affected at all!  FILE* will be
unbuffered only in your
application, yet "cat" will read from a file descriptor "1" (and may
or may not apply any
buffering on top of it, such as FILE*, on its own).  Since you are
going to read only a few
bytes out of "f" and leave the rest to "cat" (per your example), there
is no performance
penalty;  in fact there will be some gain not to pre-fill a buffer for
"f" (which you don't need
anyways).

Also, you can just use basic unix IO (read() vs. fread()), and call
lseek(1,0,SEEK_SET)
prior to popen().  This way, there's no user-level buffering and file
position is consistent with
your actions and expectations.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019