freopen/fread/popen bug

A L al20878@gmail.com
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
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



More information about the Cygwin mailing list