home *** CD-ROM | disk | FTP | other *** search
- #include <ioctl.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <string.h>
-
- char *
- getpass(prompt)
- const char *prompt;
- {
- static char buf[81];
- char *ret;
- struct sgttyb oldsb, newsb;
-
- fflush(stdin);
- gtty(0, &oldsb);
- newsb = oldsb;
- newsb.sg_flags &= ~ECHO;
- stty(0, &newsb);
- fputs(prompt, stderr); fflush(stderr);
- buf[0] = buf[81] = 0;
- if((ret = fgets(buf, 80, stdin)) != 0)
- {
- /* null terminate string */
- buf[strlen(buf) - 1] = 0;
- }
- stty(0, &oldsb);
- return ret;
- }
-