Don't search for tty, open it directly.

This commit is contained in:
sw1tchbl4d3 2022-12-20 22:51:14 +01:00
parent 2f0bdc7712
commit b34d64fd5c

View file

@ -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)