This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libgcc/81415] New: termio ioctl returns incorrect value for some characters
- From: "steven at pemberton dot nl" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 12 Jul 2017 15:33:57 +0000
- Subject: [Bug libgcc/81415] New: termio ioctl returns incorrect value for some characters
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81415
Bug ID: 81415
Summary: termio ioctl returns incorrect value for some
characters
Product: gcc
Version: 5.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libgcc
Assignee: unassigned at gcc dot gnu.org
Reporter: steven at pemberton dot nl
Target Milestone: ---
Created attachment 41734
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41734&action=edit
termio.c calls ioctl to get erase, interrupt and suspend characters
When calling ioctl to request key bindings, it returns a random value for the
Suspend binding.
On my system, if I do a stty -a I get this:
$ stty -a
speed 38400 baud; rows 24; columns 80; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = M-^?; eol2 =
M-^?;
swtch = M-^?; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W;
lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 hupcl -cstopb cread -clocal -crtscts
-ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
-iuclc ixany imaxbel iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0
ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke
If I run the enclosed C program, which does an ioctl for TCGETA:
if (ioctl(0, TCGETA, (char*) &sgbuf) == 0) {
and then retrieves the key bindings for interrupt, erase, and suspend (^C, ^?,
and ^Z in the above output). It returns Interrupt and Erase correctly, but it
returns the wrong value for Suspend; each time I run the program it returns a
different value, though it consistently returns the same (wrong) value within
the program:
if ((int) sgbuf.c_cc[VSUSP] != 0377) {
printf("Suspend=%i\n", (int)sgbuf.c_cc[VSUSP]);
}
The program calls the ioctl three times to see if it always returns the same
value within the program. It does.
An example output:
Erase= 127, Interrupt=3, Suspend=31
Erase= 127, Interrupt=3, Suspend=31
Erase= 127, Interrupt=3, Suspend=31
but the next time I run it:
Erase= 127, Interrupt=3, Suspend=171
Erase= 127, Interrupt=3, Suspend=171
Erase= 127, Interrupt=3, Suspend=171
This is attachment termio.c
termios.h says there are 17 characters (0..16) in the c_cc buffer. If I print
them all out (here I've run it three times), it seems like 4 characters change
their value between calls: 8 (VSTART) 9 (VSTOP) 10 (VSUSP) 16 (VEOL2)
0:3 1:28 2:127 3:21 4:4 5:0 6:1 7:255 8: 18 9:122 10:99 11:255 12:127 13:0
14:0 15:0 16:134
0:3 1:28 2:127 3:21 4:4 5:0 6:1 7:255 8:215 9:152 10:145 11:255 12:127 13:0
14:0 15:0 16:129
0:3 1:28 2:127 3:21 4:4 5:0 6:1 7:255 8: 10 9:97 10:251 11:255 12:127 13:0
14:0 15:0 16:239
(This produced by attachment termio2.c)
The equivalent function from termios, namely tcgetattr, seems to give the right
results, consistently over calls.