Message-ID: <002001bf091c$af7e7da0$119cd2d4@utente.telsa.it> From: "Antonio Bonifati" To: "Eli Zaretskii" Cc: Subject: R: open console into binary mode ? Date: Mon, 27 Sep 1999 21:14:37 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 4.72.3110.5 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Reply-To: djgpp AT delorie DOT com hi, what i wanted to do is a filter program which can work with binary files and can also work with console if redirection of input and/or output to a file isn't used. thank you a lot for having explained me the difference between binary and text mode (that wasn't clear in my mind!). After that i realized that i need to call isatty(), to avoid to set console into binary mode if there isn't redirection to a file, so i put this two ifs before calling setmode: if (!isatty(STDIN_FILENO)) setmode(STDIN_FILENO, O_BINARY); if (!isatty(STDOUT_FILENO)) setmode(STDOUT_FILENO, O_BINARY); and now it's all okay! thank again. also thank you for your wonderful DJGPP FAQ Antonio - italian student -----Messaggio originale----- Da: Eli Zaretskii A: Bonifati Cc: djgpp AT delorie DOT com Data: luned́ 27 settembre 1999 11.59 Oggetto: Re: open console into binary mode ? > >On Sun, 26 Sep 1999, Bonifati wrote: > >> i have to write some filter programs which must work for binary files, not >> only for text ones. >> >> i tried to open console into binary mode, but my program crashes when the >> input isn't redirect from a file. > >It doesn't crash, see below. But I don't understand why did you need >to switch the console device into binary mode when what you need is to >process binary files. Specifically, what does processing binary files >have to do with the text/binary mode of the console? > >> C:\> test >> the program hangs! >> nothing appears if i press some keys and CTRL-Break doesn't work! > >This is all explained in the library docs, under the `setmode' >function. Switching the console into binary mode has the side effect >of switching the CON device into the so-called raw (as opposed to >cooked) mode. In raw mode, characters are read one by one with no >echo, and Ctrl-BREAK and Ctrl-C are by default disabled. So your >program actually is alive and cicking, it just appears to hang because >you don't see any characters being echoed, and because you cannot >terminate the program by any means (Ctrl-Z is also ignored in raw >mode, so you cannot signal EOF). > >Please be sure to read the docs for `setmode' and `signal' for more >details. > >As I said above, I don't understand why did you need to switch the >console to binary mode in the first place. My guess is that this is >not needed for your application. Please explain what you are trying >to accomplish and why do you think the default text mode of the >console is not good enough for that.