This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Non-canonical mode input via tcsetattr(), under mintty console


Hi all,

I was testing a program that uses non-canonical mode input via
tcsetattr().

The intent of the program is:
(1) have read() to wait if nothing has been entered;
(2) read() should not return until 1 character is read
    and put into the buffer.

The essence is this:

>       struct termios newtty;
>           .
>           .
>           .
>       tcgetattr (0, &newtty);
>       newtty.c_lflags &= (~ICANON);
>
>       newtty.c_cc[VMIN] = 1;
>       newtty.c_cc[VTIME] = 0;
>
>       tcsetattr (0, TCSANOW, &newtty);
>
>       unsigned char buf[100];
>       size_t n = read (0, buf, sizeof(buf));
>           .
>           .
>           .

I had no problem while entering an ASCII character. I also had success
if I entered a non-ASCII character under standard console, but not under
mintty.

Specifically, I entered the chinese character "ä" (which means "rule"
or "example"). It occupies 3 bytes in UTF-8 representation: E4, BE, 8B.

On standard console, the read() call returned THREE bytes (n == 3), and
(not surprisingly) E4, BE and 8B were returned to buf[].

On mintty console, the read() call returned ONE byte (n == 1), and only
E4 were returned to buf[]. I could grab the other two bytes if I did
additional calls to read().

I have attached a sample program for testing purpose. Basically it waits
for input, and when something is entered, prints it. Instruction is
included in the source.

I suspected this is a bug shown under mintty (but not standard
console). Is it the case?

Thanks,

Dave Lee.


      

Attachment: termex.c
Description: Binary data

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]