www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/10/08/20:19:48

Date: Thu, 1 Oct 1998 21:29:04 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Graeme Fenwick <gfenwick AT primex DOT co DOT uk>
cc: djgpp AT delorie DOT com
Subject: Re: Strange problem reading/writing binary files.
In-Reply-To: <004801bdecbb$bb65eaa0$7c2f70c3@kgwujunl>
Message-ID: <Pine.SUN.3.91.981001212838.18395Z-100000@is>
MIME-Version: 1.0

On Wed, 30 Sep 1998, Graeme Fenwick wrote:

> Problem is, that regardless of whether the file is written in text ("w") or
> binary ("wb") mode, when it comes to displaying the file, it *always* stops
> at the CTRL-Z, regardless of mode.

This is a ``feature'' of DOS: when you write to the console device in
the default ``cooked'' mode, ^Z is interpreted as end-of-file.

To avoid this, switch the console device to binary mode, which has a
side effect of putting the console into so-called ``raw'' mode, like
this:

     setmode(1, O_BINARY);

WARNING: doing the above has some nasty side effects; for example, you
cannot interrupt the program with Ctrl-C if its console is in raw
mode.  So I suggest to call `setmode' immediately before you begin
writing to the console, and call "setmode(1, O_TEXT)" immediately
after you finish displaying the text.

> (Just a thought, but does this have anything to do with DJGPP's Unix-based
> origins, since UNIX doesn't have separate text and binary files?)

No, this is a gift straight from uncle Bill ;-).

- Raw text -


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