Annotation of 40BSD/libc/stdio/getpass.c, revision 1.1

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

unix.superglobalmegacorp.com

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