delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/04/07:28:03

Date: Sun, 4 May 1997 14:08:52 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Orlando Andico <orly AT gibson DOT eee DOT upd DOT edu DOT ph>
cc: Ethan Rohrer <rer AT wlv DOT iipo DOT gtegsc DOT com>, djgpp AT delorie DOT com
Subject: Re: help: read()ing from files containing 0x1A
In-Reply-To: <Pine.SGI.3.93.970503174506.9169A-100000@gibson.eee.upd.edu.ph>
Message-ID: <Pine.SUN.3.91.970504140751.9215Z-100000@is>
MIME-Version: 1.0

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 -


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