bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Is termio broken......?


From: Hankinson, Jeremy
Subject: Is termio broken......?
Date: Tue, 9 Jan 2001 14:42:24 -0500

When using the old style termio structure to control terminal behavior on 
RedHat 6.2, turning off ICANON (non canonical mode),  should mean that you can 
control how functions like read() behave, buy setting termio.c_cc[VMIN] and 
termio.c_cc[VTIME]. However, the following code does not behave as expected;

#include        <stdio.h>
#include        <stdlib.h>
#include        <termio.h>
#include        <unistd.h>
#define         RES printf("j_return = %d\n",j_return)
#define         STDOUTFD 1

int
ican_off()
{
    struct termio _tty; /* declare termio structure */

    if (ioctl(STDOUTFD,TCGETA,&_tty) != 0) /* load current settings into _tty */
    {
        exit(1);
    }


    _tty.c_lflag &= ~ICANON; /* switch to non-canonical mode */
    _tty.c_cc[VMIN] = 1;        /* set min no. chars to 1 */
    _tty.c_cc[VTIME] = 1;       /* timout = 0.1 secs */

    if (ioctl(STDOUTFD,TCSETAW,&_tty) != 0) /*write new settings back to 
terminal*/
   {
        exit(2);
   }

    return(0);

}

int
main()
{
    int         j_return = 0;
    int         j_buff_count;
    char        j_buffer[32];


    printf("Switching off ICANON BIT....\n");
    ican_off();
    j_buff_count = read(fileno(stdin), j_buffer, 32);
    printf( "Buffer: %s\nBuff_count %d\n",j_buffer,j_buff_count);
    exit(0);

}

According to the documentation, the read statement should return it's input to 
j_buffer as soon as VMIN is reached, which in this case is 1. In reality it 
only returns after 4 characters have been entered.

It turns out that this is because of the VMIN & VTIME are defined as 16 & 17 
which is correct if you are using the 'termios' structure, but not 'termio'. 
For termio, if ICANON is not set, then VMIN & VTIME should be defined as 4 & 5 
and sure enough if you replace VMIN and VTIME with 4 & 5 then the desired 
behavior is achieved.

This to me is a bug, if termio is available to use (which it is) then it should 
behave as it used to and as it does under Intel/Linux. (if you compile the 
above code under intel it works fine with VMIN and VTIME) There does seem to be 
a definition for handling this in asm/termios.h but it is not included by any 
of the other termios files.
If I am making a howling error please let me know, and before you ask, no I 
can't use termios because I'm porting old code that would be very difficult to 
change.

Any comment/solutions would be greatly appreciated.

 

Jeremy Hankinson
Ingres Dev - Linux
Computer Associates 
Islandia, NY
e-mail: address@hidden
tel: +1 631 342 5086



Jeremy Hankinson
Ingres Dev - Linux
Computer Associates 
Islandia, NY
e-mail: address@hidden
tel: +1 631 342 5086




reply via email to

[Prev in Thread] Current Thread [Next in Thread]