Mail Archives: djgpp-workers/1999/04/06/06:43:39
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 -