home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / updates / update14.zoo / lib / getpass.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-15  |  491 b   |  29 lines

  1. #include <ioctl.h>
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. #include <string.h>
  5.  
  6. char *
  7. getpass(prompt)
  8.     const char *prompt;
  9. {
  10.     static char buf[81];
  11.         char *ret;
  12.     struct sgttyb oldsb, newsb;
  13.  
  14.     fflush(stdin);
  15.     gtty(0, &oldsb);
  16.     newsb = oldsb;
  17.     newsb.sg_flags &= ~ECHO;
  18.     stty(0, &newsb);
  19.     fputs(prompt, stderr); fflush(stderr);
  20.     buf[0] = buf[81] = 0;
  21.     if((ret = fgets(buf, 80, stdin)))
  22.     {
  23.         /* null terminate string */
  24.         buf[strlen(buf) - 1] = 0;
  25.     }
  26.     stty(0, &oldsb);
  27.     return ret;
  28. }
  29.