1: /*
   2:  * Copyright (c) 1985 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  */
   6: 
   7: #ifndef lint
   8: static char sccsid[] = "@(#)getpass.c	5.4 (Berkeley) 3/7/86";
   9: #endif not lint
  10: 
  11: #include <stdio.h>
  12: #include <signal.h>
  13: #include <sgtty.h>
  14: 
  15: static  struct sgttyb ttyb;
  16: static  int flags;
  17: static  FILE *fi;
  18: 
  19: static intfix()
  20: {
  21:     ttyb.sg_flags = flags;
  22:     if (fi != NULL)
  23:         (void) stty(fileno(fi), &ttyb);
  24:     exit(SIGINT);
  25: }
  26: 
  27: char *
  28: mygetpass(prompt)
  29: char *prompt;
  30: {
  31:     register char *p;
  32:     register c;
  33:     static char pbuf[50+1];
  34:     int (*signal())();
  35:     int (*sig)();
  36: 
  37:     if ((fi = fopen("/dev/tty", "r")) == NULL)
  38:         fi = stdin;
  39:     else
  40:         setbuf(fi, (char *)NULL);
  41:     sig = signal(SIGINT, intfix);
  42:     (void) gtty(fileno(fi), &ttyb);
  43:     flags = ttyb.sg_flags;
  44:     ttyb.sg_flags &= ~ECHO;
  45:     (void) stty(fileno(fi), &ttyb);
  46:     fprintf(stderr, "%s", prompt); (void) fflush(stderr);
  47:     for (p=pbuf; (c = getc(fi))!='\n' && c!=EOF;) {
  48:         if (p < &pbuf[sizeof(pbuf)-1])
  49:             *p++ = c;
  50:     }
  51:     *p = '\0';
  52:     fprintf(stderr, "\n"); (void) fflush(stderr);
  53:     ttyb.sg_flags = flags;
  54:     (void) stty(fileno(fi), &ttyb);
  55:     (void) signal(SIGINT, sig);
  56:     if (fi != stdin)
  57:         (void) fclose(fi);
  58:     return(pbuf);
  59: }

Defined functions

intfix defined in line 19; used 1 times
  • in line 41
mygetpass defined in line 27; used 7 times

Defined variables

flags defined in line 16; used 3 times
sccsid defined in line 8; never used
ttyb defined in line 15; used 8 times
Last modified: 1986-03-07
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1038
Valid CSS Valid XHTML 1.0 Strict