X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-1.0 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Message-ID: <513288.14252.qm@web19014.mail.hk2.yahoo.com> Date: Sun, 28 Feb 2010 11:13:32 +0800 (HKT) From: Dave Lee Subject: Non-canonical mode input via tcsetattr(), under mintty console To: cygwin AT cygwin DOT com MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="0-1596871430-1267326812=:14252" X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com --0-1596871430-1267326812=:14252 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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 &=3D (~ICANON); > > newtty.c_cc[VMIN] =3D 1; > newtty.c_cc[VTIME] =3D 0; > > tcsetattr (0, TCSANOW, &newtty); > > unsigned char buf[100]; > size_t n =3D 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 "=E4=BE=8B" (which means "rul= e" or "example"). It occupies 3 bytes in UTF-8 representation: E4, BE, 8B. On standard console, the read() call returned THREE bytes (n =3D=3D 3), and (not surprisingly) E4, BE and 8B were returned to buf[]. On mintty console, the read() call returned ONE byte (n =3D=3D 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. =20=20=20=20=20=20 --0-1596871430-1267326812=:14252 Content-Type: application/octet-stream; name="termex.c" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="termex.c" I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDx0ZXJtaW8uaD4KI2luY2x1 ZGUgPHVuaXN0ZC5oPgoKLyogUGxlYXNlIGNvbXBpbGUgd2l0aDoKICoKICog Z2NjIC1XIC1XYWxsIC1vIHRlcm1leCB0ZXJtZXguYwogKgogKiBUaGUgcHJv Z3JhbSB3aWxsIHdhaXQgZm9yIHlvdSB0byBlbnRlciBzb21ldGhpbmcsCiAq IGFuZCBkdW1wIGJhY2sgd2hhdCB5b3UgaGF2ZSBlbnRlcmVkLiBTbyBwbGVh c2UKICogaW5wdXQgc29tZSBhbmQgbGV0IHRoZSBwcm9ncmFtIHByaW50cy4K ICovCgppbnQKbWFpbiAodm9pZCkKewoJc3RydWN0IHRlcm1pb3Mgb2xkdHR5 LCBuZXd0dHk7CgoJLyogYmFja3VwICovCgl0Y2dldGF0dHIgKDAsICZvbGR0 dHkpOwoKCS8qIGNoYW5nZSB0byBub24tY2Fub25pY2FsIG1vZGUgKi8KCXRj Z2V0YXR0ciAoMCwgJm5ld3R0eSk7CgluZXd0dHkuY19sZmxhZyAmPSAofklD QU5PTik7CgoJLyogYmxvY2sgdW50aWwgb25lIGNoYXJhY3RlciBpcyByZWFk ICovCgluZXd0dHkuY19jY1tWTUlOXSA9IDE7CgluZXd0dHkuY19jY1tWVElN RV0gPSAwOwoKCXRjc2V0YXR0ciAoMCwgVENTQU5PVywgJm5ld3R0eSk7CgoJ LyogcmVhZCBzb21ldGhpbmcgKi8KCXVuc2lnbmVkIGNoYXIgYnVmWzEwMF07 CglzaXplX3QgbiA9IHJlYWQgKDAsIGJ1Ziwgc2l6ZW9mKGJ1ZikpOwoKCS8q IGR1bXAgd2hhdCBpcyBlbnRlcmVkICovCglwcmludGYgKCJcbnJlYWQgJWQg Ynl0ZXM6ICIsIG4pOwoKCXNpemVfdCBpOwoJZm9yIChpPTA7IGk8bjsgaSsr KQoJewoJCWZvciAoaT0wOyBpPG47IGkrKykKCQkJcHJpbnRmICgiJVggIiwg YnVmW2ldKTsKCQlwcmludGYgKCJcbiIpOwoJfQoKCS8qIHJldmVydCAqLwoJ dGNzZXRhdHRyICgwLCBUQ1NBTk9XLCAmb2xkdHR5KTsKCglyZXR1cm4gMDsK fQoK --0-1596871430-1267326812=:14252 Content-Type: text/plain; charset=us-ascii -- 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 --0-1596871430-1267326812=:14252--