delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/20/10:44:13

Date: Sun, 20 Apr 1997 17:27:48 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Stefano Brozzi <brozzis AT mag00 DOT cedi DOT unipr DOT it>
cc: djgpp AT delorie DOT com
Subject: Re: Was: JPEG. <STDIN> Probs
In-Reply-To: <33575C14.33CE@mag00.cedi.unipr.it>
Message-ID: <Pine.SUN.3.91.970420172711.578S-100000@is>
MIME-Version: 1.0

On Fri, 18 Apr 1997, Stefano Brozzi wrote:

> But my programs still freeze up expecting something at STDIN.
> BCC works fine with Ctrl-C, Ctrl-Z.

It's all explained in the on-line library reference, where `setmode'
is described (maybe you have an old v2.0 docs?):

    When called to put FILE that refers to the console into binary mode,
    `setmode' will disable the generation of `SIGINT' when you press
    `Ctrl-C' (`Ctrl-Break' will still cause `SIGINT'), because many
    programs that use binary reads from the console will also want to get
    the `^C' characters.  You can use the `__djgpp_set_ctrl_c' library
    function if you want `Ctrl-C' to generate interrupts while console
    is read in binary mode.

And, of course, Ctrl-Z doesn't work because in binary mode it is just
another character, and doesn't cause an EOF.

Switching console to binary mode is generally a bad idea.  Most
programs that can read STDIN will be fine if you say something like
so:
	if (!isatty (fileno (stdin)))
	  setmode (fileno (stdin), O_BINARY);

This only switches stdin to binary if it is NOT a console, i.e. when
it was redirected to a file or a pipe.  Is there any real reason for
your program to read the console in binary mode?

> In info page of setmode() there's no hint about where O_BINARY is
> defined.
> It is in fcntl.h not in io.h where setmode() is declared, shouldn't be
> adviced the poor programmer ? ;)

Yes, it should.

> I've the K&R at a couple of meters from here, should I move it closer ?

It's always a good idea.  However, in this case it won't help at all,
since neither K nor R know anything about text/binary mode hassles.

- Raw text -


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