www.delorie.com/archives/browse.cgi | search |
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:date:from:to:subject:message-id:reply-to | |
:references:mime-version:content-type:in-reply-to; q=dns; s= | |
default; b=yrTwpygIf30IZDdwbH3aSFE+V1J7Ql3gMRWKP9NOP5ldu0nHHrdDm | |
bxBBeR3Ue/zYdKmc/akryZPpf8DmhpGeWDwPNEWcYE25xCRO2iMyy38yJ8fx7Tn3 | |
t5+WF9I2wSeQPZxPIDaYrIFQIk+5lqocIckYN+z8U+a7IVNn+xah78= | |
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:date:from:to:subject:message-id:reply-to | |
:references:mime-version:content-type:in-reply-to; s=default; | |
bh=z3DF638TTai9T0pV01dh+SPzdv8=; b=b9uyrSbBXxiqBG7unx8f86seV0AR | |
s1GlGe24ewwR4mbjYThffqPe2x1E8+USIVLHVHziU3T65Ogbd3CyRpyytw+EYo7Y | |
gM5JjM+wCrJ3Gsh1scA5O1DVZb/apuG5GmjDzMxsGWcr45Z7WLPYLlW2OR0ILC6P | |
bZyoAriZe7K6MEM= | |
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=-5.9 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.2 |
X-HELO: | calimero.vinschen.de |
Date: | Fri, 27 Feb 2015 09:43:11 +0100 |
From: | Corinna Vinschen <corinna-cygwin AT cygwin DOT com> |
To: | cygwin AT cygwin DOT com |
Subject: | Re: freopen/fread/popen bug |
Message-ID: | <20150227084311.GF11124@calimero.vinschen.de> |
Reply-To: | cygwin AT cygwin DOT com |
Mail-Followup-To: | cygwin AT cygwin DOT com |
References: | <54EFDEF4 DOT 4060308 AT cornell DOT edu> |
MIME-Version: | 1.0 |
In-Reply-To: | <54EFDEF4.4060308@cornell.edu> |
User-Agent: | Mutt/1.5.23 (2014-03-12) |
--GLp9dJVi+aaipsRk Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Feb 26 22:05, Ken Brown wrote: > I'm not sure exactly where the bug is, but here's what happens (STC at th= e end): >=20 > 1. I use freopen to open a file "foo" and associate it with stdin. >=20 > 2. I use fread to read a byte from foo. >=20 > 3. I call popen, expecting the child process to have foo as its stdin, wi= th > the file-position indicator pointing to the second byte. But instead the > child sees an empty stdin. >=20 > If I omit step 2, the child process does indeed have foo as its stdin. A= re > my expectations wrong, or is this a bug? Wrong expectations. Keep in mind that the default read mode using stdio functions is buffered. So your fread fills the buffer in f. The buffer is typically something like 1K or 4K. If the file is shorter than that, the file pointer will be set to EOF when calling popen. Try this before calling fread: setvbuf(f, NULL, _IONBF, 0); Corinna --=20 Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Maintainer cygwin AT cygwin DOT com Red Hat --GLp9dJVi+aaipsRk Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBAgAGBQJU8C4fAAoJEPU2Bp2uRE+gnvsQAIjSppIBRxz5J5UugfUiV81W vXSGcriqTEkVPQyg43PrghWWk4rmFiQWp4ZK+svjPv1zGCqgSU9RvbPze7fod7Ou 5kZTfNn4fACdXLnbePTOOCns/vyfiUF4z0PDekrjhp1JxIX2u2N+ojAM+xxK3j/Q 4h1oo4a1FgkUUgB+c9gBIGff20yDiPUl9pF10im3WBFAcQYKG3TjpkWdrAxy7+Xx 23+Xlly/0WXLOZHL/bdRx724E6uSm2Wo4FnrB71dzvk0W71ZVKqdsxECpI/X070I /NTinQAI9rxoabkth9/QuV5ZBul8+9z1UuQaP/T4mn03RpM3CWxrRbVw0z5fuKA9 k9/BzrnUFySYWfUQ8qBMaPSJbasGbcvF029zW7wWYcMA8+YtCf8rbbCwwRxzk5t3 oSkb5mu10XVbAa1b983/YDka4xpo2irDLuqzws1OZEIK+c3HFgyEhe7ISfw1coFb N0pkFO72SCd6HYPtQLhT0Xmopw4P+2EkFIOdaEGJWEedsHTOGE5w7bQmvuO/+Sh+ LEvbqU/z7GeB79IKj8isVwsojXRUz/oCMHU9+om2sw3SxBgRSRIJjG8sdOWM0FOI BwfnVHImLD9afHXqzhuh5KTtYCrwxvGv4WqF7CV/f8PZurSYZAt1llnZyPw1nP6R UiIzRYSBDm5CwUtrOUst =RRdJ -----END PGP SIGNATURE----- --GLp9dJVi+aaipsRk--
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |