1 #define _POSIX_C_SOURCE 200809L
9 char *readpass(char *prompt) {
11 struct termios saved, noecho;
12 char *termpath, *pass = 0;;
17 termpath = ctermid(0);
22 term = fopen(termpath, "r+");
29 if (tcgetattr(fd, &saved) != 0) {
33 noecho.c_lflag &= ~ECHO;
35 if (tcsetattr(fd, TCSAFLUSH, &noecho) != 0) {
40 fprintf(term, "%s", prompt);
44 /* Read the password. */
45 res = getline(&pass, &len, term);
56 /* should be impossible */
63 /* Restore terminal. */
64 tcsetattr(fd, TCSAFLUSH, &saved);