Disable line buffer and input echo of stdin

* Disable line buffer and input echo of stdin
*/
static int __getch()
{
char ch;
struct termios old, new;

(void) tcgetattr(STDIN_FILENO, &old);

memcpy(&new, &old, sizeof(struct termios));
new.c_lflag &= ~(ICANON | ECHO);

(void) tcsetattr(STDIN_FILENO, TCSANOW, &new);

ch = getchar();

(void) tcsetattr(STDIN_FILENO, TCSANOW, &old);

return ch;
}

原文地址:https://www.cnblogs.com/banwhui/p/4788312.html