7 char *getpass(const char *prompt)
12 static char password[128];
14 if ((fd = open("/dev/tty", O_RDONLY|O_NOCTTY)) < 0) fd = 0;
18 t.c_lflag &= ~(ECHO|ISIG);
20 t.c_iflag &= ~(INLCR|IGNCR);
22 tcsetattr(fd, TCSAFLUSH, &t);
25 fputs(prompt, stderr);
28 l = read(fd, password, sizeof password);
30 if (l > 0 && password[l-1] == '\n') l--;
34 tcsetattr(fd, TCSAFLUSH, &s);
36 if (fd > 2) close(fd);