ack/lang/cem/libcc/stdio/getpass.c

31 lines
601 B
C
Raw Normal View History

1987-03-31 10:45:53 +00:00
/* $Header$ */
1987-01-27 15:57:55 +00:00
#include <signal.h>
#include <sgtty.h>
char * getpass(prompt)
char *prompt;
{
int i = 0;
struct sgttyb tty, ttysave;
static char pwdbuf[9];
int fd;
1993-11-17 16:38:52 +00:00
void (*savesig)();
1987-01-27 15:57:55 +00:00
if ((fd = open("/dev/tty", 0)) < 0) fd = 0;
savesig = signal(SIGINT, SIG_IGN);
write(2, prompt, strlen(prompt));
gtty(fd, &tty);
ttysave = tty;
tty.sg_flags &= ~ECHO;
stty(fd, &tty);
i = read(fd, pwdbuf, 9);
while (pwdbuf[i - 1] != '\n')
read(fd, &pwdbuf[i - 1], 1);
pwdbuf[i - 1] = '\0';
stty(fd, &ttysave);
write(2, "\n", 1);
if (fd != 0) close(fd);
signal(SIGINT, savesig);
return(pwdbuf);
}