Date: Thu, 27 Aug 1998 14:51:32 +0300 (IDT) From: Eli Zaretskii 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: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk 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);