Controlling TERMINAL ECHO
To disable terminal echo in a C program, use the 'ioctl' (input/output
control) system function. Here are examples of functions that disable
and enable terminal echo, respectively:
For the Suns and SGIs (SVR4-based operating systems), you should use:
#include <sys/ioctl.h>
#include <termio.h>
int main(int argc, char **argv)
{
struct termio tty, oldtty;
/**
** Save the old tty settings, and get rid of echo
** for the new tty settings
**/
ioctl(0, TCGETA, &oldtty);
tty = oldtty;
tty.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL);
tty.c_cc[VMIN] = 1;
tty.c_cc[VTIME] = 0;
ioctl(0, TCSETA, &tty);
/**
** Now do whatever stuff you want non-echoed
**/
/**
** Now reset the old settings
**/
ioctl(0, TCSETA, &oldtty);
}
For BSD-based operating systems, you would use the below snippet
of code.
For the DECstations, you can use either the above or the below:
#include <sys/ioctl.h>
#include <sgtty.h>
int main(int argc, char **argv)
{
struct sgttyb tty, oldtty;
/**
** Save the old tty settings, and get rid of echo
** for the new tty settings
**/
ioctl(0, TIOCGETP, &oldtty);
tty = oldtty;
tty.sg_flags |= CBREAK;
tty.sg_flags &= ~ECHO;
ioctl(0, TIOCSETN, &tty);
/**
** Now do whatever stuff you want non-echoed
**/
/**
** Now reset the old settings
**/
ioctl(0, TIOCSETN, &oldtty);
}
If you are interested in learning more about the 'ioctl' function, you can
read the manual page by using the 'man' command:
man ioctl
Also, you may want to look at:
man termio
Last modified: Mar 9, 1996
|