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