/* * program to turn OFF echo behavior of the terminal driver * idea: * open the device file * read the termios struct * use and operation to turn it (echo flag) off to turn it on: use & with the complement mask #define ECHO 0000010 v M = 000 000 000 000 000 001 000 // the mask as bits FL = 110 011 100 110 101 100 111 &~M = 111 111 111 111 111 110 111 // the mask as bits 110 011 100 110 101 100 111 info.c_lflag = info.c_flag & ~ECHO // long version info.c_lflag &= ~ECHO // equiv short version x = x + 3 // long version x += 3; x = x / 7 x /= 7 y = y * r y *= r To turn a bit on: * write the struct to the driver: using tcsetattr * close the device file */ #include #include #include #include #include #include #include #include int main() { /// * open the device file // int fd = open( "/dev/tty", O_RDWR ); // connection to file int fd = 0; // the default stdin // * read the termios struct struct termios tty; // hold the settings // Q: do we need to open the file? int retval = tcgetattr( fd, &tty ); // get the settings if ( retval == -1 ){ // if error, then perror("getting settings"); exit(1); } // * use and operation to turn it (echo flag) off tty.c_lflag &= ~ECHO; // equiv short version // * write the struct to the driver: using tcsetattr retval = tcsetattr( fd, TCSANOW, &tty ); if ( retval != 0 ){ perror("Cannot update driver"); exit(1); } // * close the device file close( fd ); return 0; }