www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/08/27/18:38:46

Date: Thu, 27 Aug 1998 14:51:32 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: dejatv AT my-dejanews DOT com
cc: djgpp AT delorie DOT com
Subject: Re: how to write binary files to stdout?
In-Reply-To: <6s2lob$4cr$1@nnrp1.dejanews.com>
Message-ID: <Pine.SUN.3.91.980827145111.6326k-100000@is>
MIME-Version: 1.0

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019