For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > June 2007 > Echo on and off









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Echo on and off
keith@bytebrothers.co.uk

2007-06-26, 8:05 am


Hi all,

Is there some portable (OS-independent?) way of turning echo on and
off for a terminal device? At the moment I have something similar to
the following for Un*x, but of course I can't use this with DJGPP in a
'DOS' console program.

#include <termios.h>

static int setnoecho (struct termios *t)
{
if (isatty (STDIN_FILENO) == 0)
{
fprintf(stderr, "Device is not a TTY.\n");
return(-1);
}

if (tcgetattr (STDIN_FILENO, t) < 0)
{
fprintf(stderr, "tcgetattr() failed.\n");
return(-1);
}

t->c_lflag &= ~ECHO;
tcsetattr (STDIN_FILENO, TCSANOW, t);
return (0);
}

static void setecho (struct termios *t)
{
t->c_lflag |= ECHO;
tcsetattr (STDIN_FILENO, TCSANOW, t);
}

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com