(Rouben Rostamian) wrote:
<snip>
>Question: Is it possible to close stdout then reopen it in binary
>mode in a platform-independent way?
Well, there are two problems:
1) stdout need not be a modifiable lvalue, so you can't just
use fopen - you cannot come up with a suitable filename anyway.
To solve this, one could come up with
reopen( NULL, "wb", stdout);
running into problem number
2) It is implementation defined which (if any) and under what
circumstances mode changes are permitted.
>If that were possible, then the binary-mode output of the program
>would be the same on all platforms.
That would be great, but unfortunately it's impossible. stdin,
stdout and stderr are text streams per definition, and there is
no portable way to switch them to binary mode.
>The purpose of my real program (not this demo,) is to act as a
>filter from stdin to stdout, therefore fopen(filename, "wb") is
>of not much help.
I cannot come up with a better solution, sorry.
Regards
--
Irrwahn
()