9fans archive / 1997 / 10 / 55 /    prev next

From: Boyd Roberts boyd@fra...
Subject: [9fans] netkey on unix
Date: Wed, 22 Oct 1997 10:16:18 +0200

here's some posix code for mangling tty echo (for those who feel
that way inclined):

/*
 * Horrible system dependent tty routines.
 */

#include	<termios.h>

/*
 * Is echo on?
 */
int
ttyechoing(int fd)
{
	struct termios	t;

	if (tcgetattr(fd, &t) == -1)
		return -1;

	return (t.c_lflag & ECHO) != 0;
}

/*
 * Turn echo off/on?
 */
int
ttyecho(int fd, int on)
{
	struct termios	t;

	if (tcgetattr(fd, &t) == -1)
		return -1;

	if (on)
		t.c_lflag |= ECHO;
	else
		t.c_lflag &= ~ECHO;
		
	return tcsetattr(fd, TCSADRAIN, &t);
}