1: /* $Header$ */
   2: /* modified for XNS passwords, which may be of almost arbitrary length */
   3: 
   4: /* @(#)getpass.c	4.3 (Berkeley) 5/16/84 */
   5: #include <stdio.h>
   6: #include <signal.h>
   7: #include <sgtty.h>
   8: #define PASSLEN 80
   9: 
  10: char *
  11: getpass(prompt)
  12: char *prompt;
  13: {
  14:     struct sgttyb ttyb;
  15:     int flags;
  16:     register char *p;
  17:     register c;
  18:     FILE *fi;
  19:     static char pbuf[PASSLEN+1];
  20:     int (*signal())();
  21:     int (*sig)();
  22: 
  23:     if ((fi = fdopen(open("/dev/tty", 2), "r")) == NULL)
  24:         fi = stdin;
  25:     else
  26:         setbuf(fi, (char *)NULL);
  27:     sig = signal(SIGINT, SIG_IGN);
  28:     ioctl(fileno(fi), TIOCGETP, &ttyb);
  29:     flags = ttyb.sg_flags;
  30:     ttyb.sg_flags &= ~ECHO;
  31:     ioctl(fileno(fi), TIOCSETP, &ttyb);
  32:     fprintf(stderr, "%s", prompt); fflush(stderr);
  33:     for (p=pbuf; (c = getc(fi))!='\n' && c!=EOF;) {
  34:         if (p < &pbuf[PASSLEN])
  35:             *p++ = c;
  36:     }
  37:     *p = '\0';
  38:     fprintf(stderr, "\n"); fflush(stderr);
  39:     ttyb.sg_flags = flags;
  40:     ioctl(fileno(fi), TIOCSETP, &ttyb);
  41:     signal(SIGINT, sig);
  42:     if (fi != stdin)
  43:         fclose(fi);
  44:     return(pbuf);
  45: }

Defined functions

Defined macros

PASSLEN defined in line 8; used 2 times
Last modified: 1986-03-13
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 983
Valid CSS Valid XHTML 1.0 Strict