freopen/fread/popen bug

Fri Feb 27 18:17:00 GMT 2015

> 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

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

Problem reports:
Unsubscribe info:

More information about the Cygwin mailing list