Annotation of 42BSD/ucb/ftp/getpass.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char sccsid[] = "@(#)getpass.c  4.1 (Berkeley) 5/26/83";
                      3: #endif
                      4: 
                      5: #include <stdio.h>
                      6: #include <signal.h>
                      7: #include <sgtty.h>
                      8: 
                      9: char *
                     10: getpass(prompt)
                     11: char *prompt;
                     12: {
                     13:        struct sgttyb ttyb;
                     14:        int flags;
                     15:        register char *p;
                     16:        register c;
                     17:        FILE *fi;
                     18:        static char pbuf[9];
                     19:        int (*signal())();
                     20:        int (*sig)();
                     21: 
                     22:        if ((fi = fdopen(open("/dev/tty", 2), "r")) == NULL)
                     23:                fi = stdin;
                     24:        else
                     25:                setbuf(fi, (char *)NULL);
                     26:        sig = signal(SIGINT, SIG_IGN);
                     27:        gtty(fileno(fi), &ttyb);
                     28:        flags = ttyb.sg_flags;
                     29:        ttyb.sg_flags &= ~ECHO;
                     30:        stty(fileno(fi), &ttyb);
                     31:        fprintf(stderr, "%s", prompt); fflush(stderr);
                     32:        for (p=pbuf; (c = getc(fi))!='\n' && c!=EOF;) {
                     33:                if (p < &pbuf[8])
                     34:                        *p++ = c;
                     35:        }
                     36:        *p = '\0';
                     37:        fprintf(stderr, "\n"); fflush(stderr);
                     38:        ttyb.sg_flags = flags;
                     39:        stty(fileno(fi), &ttyb);
                     40:        signal(SIGINT, sig);
                     41:        if (fi != stdin)
                     42:                fclose(fi);
                     43:        return(pbuf);
                     44: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.