Annotation of researchv9/libc/gen/ttyslot.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Return the number of the slot in the utmp file
        !             3:  * corresponding to the current user.
        !             4:  * Definition is the line number in the /etc/ttys file.
        !             5:  */
        !             6: 
        !             7: char   *cttyname();
        !             8: char   *strcpy();
        !             9: char   *getttys();
        !            10: 
        !            11: ttyslot()
        !            12: {
        !            13:        register char *cp, *tp;
        !            14:        register int s, tf;
        !            15: 
        !            16:        if ((cp = cttyname()) == 0)
        !            17:                return(0);
        !            18:        if (strncmp(cp, "/dev/", 5) == 0)
        !            19:                cp += 5;
        !            20:        if ((tf=open("/etc/ttys", 0)) < 0)
        !            21:                return(0);
        !            22:        s = 0;
        !            23:        while (tp = getttys(tf)) {
        !            24:                s++;
        !            25:                if (strcmp(cp, tp)==0) {
        !            26:                        close(tf);
        !            27:                        return(s);
        !            28:                }
        !            29:        }
        !            30:        close(tf);
        !            31:        return(0);
        !            32: }
        !            33: 
        !            34: static char *
        !            35: getttys(f)
        !            36: {
        !            37:        static char line[32];
        !            38:        register char *lp;
        !            39: 
        !            40:        lp = line;
        !            41:        for (;;) {
        !            42:                if (read(f, lp, 1) != 1)
        !            43:                        return(0);
        !            44:                if (*lp =='\n') {
        !            45:                        *lp = '\0';
        !            46:                        return(line+2);
        !            47:                }
        !            48:                if (lp >= &line[32])
        !            49:                        return(line+2);
        !            50:                lp++;
        !            51:        }
        !            52: }

unix.superglobalmegacorp.com

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