Mail Archives: djgpp/1999/09/27/17:29:44
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 <eliz AT is DOT elta DOT co DOT il>
A: Bonifati <abonifati AT telsa DOT it>
Cc: djgpp AT delorie DOT com <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.
- Raw text -