home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib32.zoo / getpass.c < prev    next >
C/C++ Source or Header  |  1993-02-17  |  771b  |  44 lines

  1. #include <ioctl.h>
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. #include <string.h>
  5. #include <limits.h>
  6.  
  7. extern int __mint;
  8.  
  9. char *
  10. getpass(prompt)
  11.     const char *prompt;
  12. {
  13.     static char buf[PASS_MAX + 1];
  14.         char *ret;
  15.     struct sgttyb oldsb, newsb;
  16.     FILE *tty;
  17.     int ttyfd = 0;
  18.  
  19.     fflush(stdin);
  20.     tty = stdin;
  21.     if (__mint) {
  22.         if ((tty = fopen("U:\\DEV\\TTY", "r")) == NULL)
  23.             return NULL;
  24.     }
  25.     ttyfd = fileno(tty);
  26.     fflush(tty);
  27.     gtty(ttyfd, &oldsb);
  28.     newsb = oldsb;
  29.     newsb.sg_flags &= ~ECHO;
  30.     stty(ttyfd, &newsb);
  31.     fputs(prompt, stderr);
  32.     fflush(stderr);
  33.     if ((ret = fgets(buf, PASS_MAX + 1, tty)) != 0)
  34.     {
  35.       /* zap the newline */
  36.       if (buf[strlen(buf) - 1] == '\n')
  37.         buf[strlen(buf) - 1] = 0;
  38.     }
  39.     stty(ttyfd, &oldsb);
  40.     if (__mint)
  41.         (void) fclose(tty);
  42.     return ret;
  43. }
  44.