- 论坛徽章:
- 0
|
请教一下passwd读取用户输入的原理
- #include "../my.h"
- static struct termios stored_settings;
- void set_keypress(void)
- {
- struct termios new_settings;
- tcgetattr(0,&stored_settings);
- new_settings = stored_settings;
- /* Disable canonical mode, and set buffer size to 1 byte */
- new_settings.c_lflag &= (~ICANON);
- new_settings.c_lflag &= (~ECHO);
- new_settings.c_cc[VTIME] = 0;
- new_settings.c_cc[VMIN] = 1;
- tcsetattr(0,TCSANOW,&new_settings);
- return;
- }
- void reset_keypress(void)
- {
- tcsetattr(0,TCSANOW,&stored_settings);
- return;
- }
- int main()
- {
- char buf[256] = "", *p = buf;
- set_keypress();
- while(1) {
- char c;
- read(0,&c,1);
- if (c == '\n')
- break;
- *p++ = c;
- }
- reset_keypress();
- printf("[%s]\n", buf);
- }
复制代码
可是这个程序还是可以和管道交互阿
是不是我写的有问题? |
|