Disable terminal echo if needed */
| 381 | |
| 382 | /* Disable terminal echo if needed */ |
| 383 | static bool disable_echo(struct termios *saved_term) |
| 384 | { |
| 385 | if (!isatty(fileno(stdin))) |
| 386 | return false; |
| 387 | |
| 388 | if (tcgetattr(fileno(stdin), saved_term) != 0) |
| 389 | return false; |
| 390 | |
| 391 | struct termios tmp = *saved_term; |
| 392 | tmp.c_lflag &= ~ECHO; |
| 393 | |
| 394 | if (tcsetattr(fileno(stdin), TCSANOW, &tmp) != 0) |
| 395 | return false; |
| 396 | |
| 397 | return true; |
| 398 | } |
| 399 | |
| 400 | /* Restore terminal echo if it was disabled */ |
| 401 | static void restore_echo(const struct termios *saved_term) |