freopen/fread/popen bug

Ken Brown
Fri Feb 27 21:05:00 GMT 2015

On 2/27/2015 11:20 AM, A L wrote:
>> 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.

Thanks (and thanks to Corinna and Eric) for correcting my misconceptions.  We 
have several viable solutions now, and I'm working with the upstream maintainers 
to decide which one to use.


Problem reports:
Unsubscribe info:

More information about the Cygwin mailing list