diff --git a/readpassphrase.h b/readpassphrase.h index d4f8be7..328cd2a 100644 --- a/readpassphrase.h +++ b/readpassphrase.h @@ -6,8 +6,8 @@ char* readpassphrase(const char* prompt, char* buf, size_t bufsz, int read_pw_from_stdin) { int n; int is_tty = !read_pw_from_stdin; - int infd = -1; - int outfd = -1; + int infd; + int outfd; struct termios term; @@ -16,13 +16,9 @@ char* readpassphrase(const char* prompt, char* buf, size_t bufsz, int read_pw_fr outfd = 1; is_tty = tcgetattr(outfd, &term) == 0; } else { - for (int i = 0; i < 3; i++) { - if (tcgetattr(i, &term) == 0) { - infd = i; - outfd = i; - break; - } - } + infd = outfd = open("/dev/tty", O_RDWR); + if (!(infd >= 0 && tcgetattr(outfd, &term) == 0)) + return NULL; } if (infd < 0)