Date: Sun, 20 Apr 1997 17:27:48 +0300 (IDT) From: Eli Zaretskii To: Stefano Brozzi cc: djgpp AT delorie DOT com Subject: Re: Was: JPEG. Probs In-Reply-To: <33575C14.33CE@mag00.cedi.unipr.it> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk 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.