diff --git a/readpassphrase.h b/readpassphrase.h index 13eac35..94a63d9 100644 --- a/readpassphrase.h +++ b/readpassphrase.h @@ -39,23 +39,25 @@ char* readpassphrase(const char* prompt, char* buf, size_t bufsz) { if (write(fd, prompt, strlen(prompt)) < 0) { tcsetattr(ttyfd, 0, &term); + close(fd); return NULL; } n = read(fd, buf, bufsz); if (n < 0) { tcsetattr(ttyfd, 0, &term); - printf("\n"); + n = write(fd, "\n", 1); + close(fd); return NULL; } buf[n-1] = '\0'; + // NOTE: As we disabled echo, the enter sent by the user isn't displayed, so we resend it. + n = write(fd, "\n", 1); + close(fd); tcsetattr(ttyfd, 0, &term); - // NOTE: As we disabled echo, the enter sent by the user isn't displayed. - printf("\n"); - return buf; }