Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* Is termio broken.......?
@ 2001-01-09 18:11 Hankinson, Jeremy
  0 siblings, 0 replies; only message in thread
From: Hankinson, Jeremy @ 2001-01-09 18:11 UTC (permalink / raw)
  To: axp-list

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        <termios.h>
#include        <unistd.h>
#include        <sys/ioctl.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: jeremy.hankinson@ca.com
tel: +1 631 342 5086




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2001-01-09 18:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-01-09 18:11 Is termio broken.......? Hankinson, Jeremy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox