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

Dave Lee mailtolky@yahoo.com.hk
Sun Feb 28 03:38:00 GMT 2010


Sorry for forgetting 3 things.
1. I was testing on cygwin 1.7.
2. I was running the latest version of mintty (0.5.8-1).
3. I have included an output from cygcheck here.

Thanks.

--- On Sun, 2/28/10, Dave Lee <mailtolky@yahoo.com.hk> wrote:

> 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.
> 
> 
>       --
> 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


      
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cygcheck.out
Type: application/octet-stream
Size: 23101 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20100228/96fab856/attachment.obj>
-------------- next part --------------
--
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


More information about the Cygwin mailing list