Mail Archives: djgpp/1998/08/27/18:38:46
On Thu, 27 Aug 1998 dejatv AT my-dejanews DOT com wrote:
> Is it possible to change the mode of stdout to binary? I've tried
>
> setmode(stdout, O_BINARY);
>
> The functions returns an error (-1).
`setmode' needs a file handle, not a pointer to a FILE struct, which
is what `stdout' is. You need to say this:
setmode (fileno (stdout), O_BINARY);
However, please note that if `stdout' is connected to the screen, not
redirected to a file, switching it to binary mode has a side-effect of
making DOS use raw mode for screen writes, and also disables the
SIGINT generation by Ctrl-C (this is described in the library
reference). So, unless you have a good reason to use binary writes to
a screen, I suggest to do something like this:
if (!isatty (fileno (stdout)))
setmode (fileno (stdout), O_BINARY);
- Raw text -