This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: freopen/fread/popen bug
- From: Achim Gratz <Stromeko at nexgo dot de>
- To: cygwin at cygwin dot com
- Date: Fri, 27 Feb 2015 20:05:58 +0100
- Subject: Re: freopen/fread/popen bug
- Authentication-results: sourceware.org; auth=none
- References: <54EFDEF4 dot 4060308 at cornell dot edu> <20150227084311 dot GF11124 at calimero dot vinschen dot de> <54F065A0 dot 9030608 at cornell dot edu> <54F098AA dot 9050503 at redhat dot com>
Eric Blake writes:
>> What's really happening is that we need to peek at the first few bytes
>> of f before deciding which program to call in popen. After peeking,
>> there's a call to fseek(f,0,0) before the popen, with the intention that
>> the child receives a file pointer set to the beginning of the file. (I
>> left this out of my STC because it didn't affect the outcome.) This
>> apparently works on Linux.
>
> Corinna is correct - you need to fflush() after the fseek() for it to
> affect the underlying offset. Or, just use read()/lseek() instead of
> fread()/fseek() in the parent, to avoid stdio buffering altogether.
> That way, you'll guarantee the offset the child process will inherit
> without having to worry about flushing buffered state.
Basically this is the same category of bug that was in rcs for a while.
It isn't easy to find out what is and isn't guaranteed about these
things across a fork and since things work slightly differently on Linux
that's something you can probably expect to show up more often.
Regards,
Achim.
--
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+
Samples for the Waldorf Blofeld:
http://Synth.Stromeko.net/Downloads.html#BlofeldSamplesExtra
--
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