#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    16
    Rep Power
    0

    ioctl() and termios for "canonical" read


    Well, this app is giving me quite a headache :(
    I need to have a program read a char at a time and then process it, using read(). Therefore, I'll have to set the terminal to canonical mode (correct?), using ioctl() along with termios' flags. What I just can't get is what flag to use and wich values to set (I've already read ALL the man page...). My best bet is using the c_lflag and manipulating it's ICANON value. Can somebody point out a good solution for this problem? Some sample code would be usefull, I'm not very skilled...

    Thanx in advance!

    PS: I can't use getchar :rolleyes:
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    16
    Rep Power
    0

    Here's how to, if anyone ever needs it


    main(){

    struct termios oldT, newT;
    char c;

    ioctl(0,TCGETS,&oldT); /*get current mode

    newT=oldT;
    newT.c_lflag &= ~ECHO; /* echo off */
    newT.c_lflag &= ~ICANON; /*one char @ a time*/

    ioctl(0,TCSETS,&newT); /* set new terminal mode */

    read(0,&c,1); /*read 1 char @ a time from stdin*/

    ioctl(0,TCSETS,&oldT); /* restore previous terminal mode */

    }

    Detailed info on: http://www.unidata.ucar.edu/cgi-bin/man-cgi?termio+7

IMN logo majestic logo threadwatch logo seochat tools logo