- !get_tty_settings(STDIN_FILENO, tty_settings) &&
- !get_tty_settings(open("/dev/tty", O_RDWR), tty_settings)) {
- failed("terminal attributes");
+ !get_tty_settings(STDIN_FILENO, tty_settings)) {
+ if (need_tty) {
+ int fd = open("/dev/tty", O_RDWR);
+ if (!get_tty_settings(fd, tty_settings)) {
+ failed("terminal attributes");
+ }
+ } else {
+ my_fd = fileno(stdout);
+ }
+ } else {
+ can_restore = TRUE;
+ original_settings = *tty_settings;