Mail Archives: djgpp/1997/05/04/07:28:03
On Sat, 3 May 1997, Orlando Andico wrote:
> In your open() call, add O_BINARY to the flags. Note that this is
> nonportable to UNIX, so you do something like:
>
> #include <fcntl.h>
> #include <sys/stat.h>
> #include <sys/types.h>
>
> #ifdef MSDOS
> i = open ("myfile", O_RDWR | O_BINARY);
> #else
> i = open ("myfile", O_RDWR);
> #endif
Since the call to `open' is bound to happen in more than one place in
any non-trivial program, a better way is this:
#include <fcntl.h>
#ifndef O_BINARY
#define O_BINARY 0
#endif
Then just go and change all of the calls to `open' to include
"| O_BINARY", it will now work on Unix also.
And btw, if your program should be able to read binary data from
redirected standard input, don't forget to switch stdin to binary mode
if it is not a console:
if (!isatty (file (stdin)))
setmode (fileno (stdin), O_BINARY);
- Raw text -