|
|
1.1 ! root 1: /* @(#)getpass.c 4.2 (Berkeley) 7/1/81 */ ! 2: #include <stdio.h> ! 3: #include <signal.h> ! 4: #include <sys/ttyio.h> ! 5: ! 6: char * ! 7: getpass(prompt) ! 8: char *prompt; ! 9: { ! 10: struct sgttyb ttyb; ! 11: int flags; ! 12: register char *p; ! 13: register c; ! 14: FILE *fi; ! 15: static char pbuf[9]; ! 16: int (*signal())(); ! 17: int (*sig)(); ! 18: ! 19: if ((fi = fopen("/dev/tty", "r")) == NULL) ! 20: fi = stdin; ! 21: else ! 22: setbuf(fi, (char *)NULL); ! 23: sig = signal(SIGINT, SIG_IGN); ! 24: ioctl(fileno(fi), TIOCGETP, &ttyb); ! 25: flags = ttyb.sg_flags; ! 26: ttyb.sg_flags &= ~ECHO; ! 27: ioctl(fileno(fi), TIOCSETP, &ttyb); ! 28: fprintf(stderr, "%s", prompt); fflush(stderr); ! 29: for (p=pbuf; (c = getc(fi))!='\n' && c!=EOF;) { ! 30: if (p < &pbuf[8]) ! 31: *p++ = c; ! 32: } ! 33: *p = '\0'; ! 34: fprintf(stderr, "\n"); fflush(stderr); ! 35: ttyb.sg_flags = flags; ! 36: ioctl(fileno(fi), TIOCSETP, &ttyb); ! 37: signal(SIGINT, sig); ! 38: if (fi != stdin) ! 39: fclose(fi); ! 40: return(pbuf); ! 41: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.