//---------------------------------------------------------------- // ttyinfo.cpp // // This program shows some information about how our Linux // system implemented the 'struct termios' data structure. // We need this information in order to write our assembly // language version of applications (such as 'noecho.cpp') // which inhibit the normal echoing of keyboard input. In // particular, we must know how much memory will be needed // to store an object of type 'struct termios'; and within // that object, we must know the location of the 'c_lflag' // field and which of its bits are the ECHO and the ECHONL // settings. We also need to know the value for TCSANOW. // // programmer: ALLAN CRUSE // written on: 18 SEP 2003 //---------------------------------------------------------------- #include #include struct termios tty; int main( void ) { printf( "\n\nSome details about objects of type " ); printf( "\'struct termios\' under Linux \n" ); // show the total size of a 'struct termios' object int nbytes = sizeof( tty ); printf( "\n\tsizeof( struct termios )=%d bytes: ", nbytes ); // initialize our 'tty' object and display it in hex tcgetattr( 0, &tty ); unsigned int *ttyp = (unsigned int*)&tty; for (int i = 0; i < nbytes/4; i++) { if ( ( i % 4 ) == 0 ) printf( "\n\t%08X: ", &ttyp[ i ] ); printf( "%08X ", ttyp[ i ] ); } printf( "\n" ); // show the size, address, and value of the 'c_lflag' field nbytes = sizeof( tty.c_lflag ); printf( "\n\tsizeof( c_lflag )=%d bytes ", nbytes ); printf( "\n\t&c_lflag=%08X ", &tty.c_lflag ); printf( "c_lflag=%08X \n", tty.c_lflag ); // show the values of some crucial manifest constants printf( "\n\tECHO = %08X ", ECHO ); printf( " ECHONL = %08X ", ECHONL ); printf( " TCSANOW = %08X ", TCSANOW ); printf( "\n\n" ); }