Discussion:
Console (tty01) ioctl() failure
(too old to reply)
CJ
2007-09-28 15:42:13 UTC
Permalink
I use the following to determine how many bytes are waiting in the
terminal input.

int ret = 0;
int bytes = 0;
errno = 0;
ret = ioctl(STDIN_FILENO,I_NREAD,&bytes);

fprintf(stderr,"errno = %d, ret = %d, bytes = %d\n",errno,ret,bytes);

It works find everywhere except on the /dev/tty01, or other physical
console "windows" on SCO. Even worse, the ioctl() call above puts the
video into 40 column mode.

Why is the above ioctl() call changing the video mode, and how can I
find out how many bytes are in STDIN_FILENO (fd 0) after using
select() or poll() to detect the handle is read ready?

cj
John DuBois
2007-09-28 17:13:14 UTC
Permalink
Post by CJ
I use the following to determine how many bytes are waiting in the
terminal input.
int ret = 0;
int bytes = 0;
errno = 0;
ret = ioctl(STDIN_FILENO,I_NREAD,&bytes);
fprintf(stderr,"errno = %d, ret = %d, bytes = %d\n",errno,ret,bytes);
It works find everywhere except on the /dev/tty01, or other physical
console "windows" on SCO. Even worse, the ioctl() call above puts the
video into 40 column mode.
Why is the above ioctl() call changing the video mode, and how can I
find out how many bytes are in STDIN_FILENO (fd 0) after using
select() or poll() to detect the handle is read ready?
This problem stems from a conflict between the numbering for STREAMS ioctls and
the OSR5 console mode switch ioctls. A fix for OSR5 is included in MP5; it
recognizes a STREAMS ioctl attempt by the fact that it has a valid pointer for
the 3rd argument, while a mode-switch ioctl should have 0. The ioctl will then
fail correctly (without switching the video mode), since the console is not a
STREAMS device.

Some variation on this also happens in OSR6, though it might only occur if you
are running an OSR5 ABI binary - I don't remember.

What to do about it depends on what release of the OS you're running.

John
--
John DuBois ***@armory.com KC6QKZ/AE http://www.armory.com/~spcecdt/
Loading...