www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1999/04/06/06:43:39

Date: Tue, 6 Apr 1999 12:41:22 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Michel de Ruiter <Michel AT smr DOT nl>
cc: "'DJGPP workers'" <djgpp-workers AT delorie DOT com>
Subject: Re: setmode problem
In-Reply-To: <B0FEA00E82A7D1118BFB00A0CC990278213235@ARGON>
Message-ID: <Pine.SUN.3.91.990406122545.16726K-100000@is>
MIME-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Tue, 6 Apr 1999, Michel de Ruiter wrote:

> I know some programs first check isatty(stdin), but someone might want
> to be able to type binary data (C-z, C-c, C-m and such) on the
> terminal.
> 
> The computer freezes when getchar (or any other DOS input function) is
> called

And that's exactly the reason why programs which use DOS I/O *should* 
check isatty(stdin) and only switch stdin to binary mode if it is NOT the 
console device.

If the program actually *needs* to read binary data from the terminal, it 
should read it one character at a time, like so:

	read (0, &c, 1);

(or use `getch').  Using buffered stdio functions, like `getchar', won't 
return until the full 512-byte long request is satisfied, and until then 
you are parked inside a DOS call, so signals don't work, and Ctrl-Z 
doesn't work either, since it is not special in raw mode.  For all 
practical purposes, the machine appears to be wedged...

> Using 1 (stdout) or 2
> (stderr) instead of 0 (stdin) shows exactly the same behaviour, as DOS
> just changes the mode of the same `console' if no redirection is used.

Right.  See the complicated logic in the DJGPP port of Gzip 1.24a, which 
is meant to prevent people typing "gzip [Enter]" and getting the behavior 
you describe.  Seems like `zip' doesn't do that...

> I dug all the inner details out of libc, but at first it turned out to
> be a problem in DOS itself.

The library simply switches the device to raw mode; everything else is 
DOS behavior.

> All problems disappeared when I set stdin to _IONBF (not buffered)
> instead of _IOLBF (line buffered). At least, just one key press is
> enough to let the C-BREAK through.

I'm worried about the possible implications of turning off the buffering 
just because somebody reads in binary mode.  Can anybody think of any 
downside to this change?  If not, let's do it.

Also, I don't see how this would help, except that it enables SIGINT.  
You still cannot signal EOF with Ctrl-Z, so this is still a small 
disaster, and programs like zip still need to check isatty, no?

> Nothing is echoed, but should it?

No.  Binary mode doesn't echo.

- Raw text -


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