2 * getpass - ask for a password
4 /* $Id: getpass.c,v 1.3 1994/06/24 11:45:18 ceriel Exp $ */
11 int _open(const char *path, int flags);
12 int _write(int d, const char *buf, int nbytes);
13 int _read(int d, char *buf, int nbytes);
16 int _stty(int, struct sgttyb *);
17 int _gtty(int, struct sgttyb *);
20 getpass(const char *prompt)
23 struct sgttyb tty, ttysave;
24 static char pwdbuf[9];
28 if ((fd = _open("/dev/tty", O_RDONLY)) < 0) fd = 0;
29 savesig = signal(SIGINT, SIG_IGN);
30 _write(2, prompt, strlen(prompt));
33 tty.sg_flags &= ~ECHO;
35 i = _read(fd, pwdbuf, 9);
36 while (pwdbuf[i - 1] != '\n')
37 _read(fd, &pwdbuf[i - 1], 1);
41 if (fd != 0) _close(fd);
42 signal(SIGINT, savesig);