Annotation of 42BSD/bin/csh/getpwent.c, revision 1.1

1.1     ! root        1: static char *sccsid = "@(#)getpwent.c 4.1 10/9/80";
        !             2: 
        !             3: #include <pwd.h>
        !             4: 
        !             5: #define        BUFSIZ  160
        !             6: 
        !             7: static int pwf = -1;
        !             8: static char line[BUFSIZ+1];
        !             9: static struct passwd passwd;
        !            10: 
        !            11: setpwent()
        !            12: {
        !            13:        if( pwf == -1 )
        !            14:                pwf = open( "/etc/passwd", 0 );
        !            15:        else
        !            16:                lseek(pwf, 0l, 0);
        !            17: }
        !            18: 
        !            19: endpwent()
        !            20: {
        !            21:        if( pwf != -1 ){
        !            22:                close( pwf );
        !            23:                pwf = -1;
        !            24:        }
        !            25: }
        !            26: 
        !            27: static char *
        !            28: pwskip(p)
        !            29: register char *p;
        !            30: {
        !            31:        while( *p && *p != ':' )
        !            32:                ++p;
        !            33:        if( *p ) *p++ = 0;
        !            34:        return(p);
        !            35: }
        !            36: 
        !            37: struct passwd *
        !            38: getpwent()
        !            39: {
        !            40:        register char *p, *q;
        !            41:        register int i, j;
        !            42: 
        !            43:        if (pwf == -1) {
        !            44:                if( (pwf = open( "/etc/passwd", 0 )) == -1 )
        !            45:                        return(0);
        !            46:        }
        !            47:        i = read(pwf, line, BUFSIZ);
        !            48:        for (j = 0; j < i; j++)
        !            49:                if (line[j] == '\n')
        !            50:                        break;
        !            51:        if (j >= i)
        !            52:                return(0);
        !            53:        line[++j] = 0;
        !            54:        lseek(pwf, (long) (j - i), 1);
        !            55:        p = line;
        !            56:        passwd.pw_name = p;
        !            57:        p = pwskip(p);
        !            58: /*     passwd.pw_passwd = p; */
        !            59:        p = q = pwskip(p);
        !            60: /*     passwd.pw_uid = atoi(p); */
        !            61:        p = pwskip(p);
        !            62:        p[-1] = 0;
        !            63:        passwd.pw_uid = atou(q);
        !            64: /*     passwd.pw_gid = atoi(p); */
        !            65: /*     passwd.pw_quota = 0; */
        !            66: /*     passwd.pw_comment = ""; */
        !            67:        q = p;
        !            68:        p = pwskip(p);
        !            69:        p[-1] = 0;
        !            70:        passwd.pw_gid = atou(q);
        !            71: /*     passwd.pw_gecos = p; */
        !            72:        p = pwskip(p);
        !            73:        passwd.pw_dir = p;
        !            74:        p = pwskip(p);
        !            75: /*     passwd.pw_shell = p; */
        !            76: /*     while(*p && *p != '\n') p++; */
        !            77:        *p = '\0';
        !            78:        return(&passwd);
        !            79: }
        !            80: 
        !            81: atou(p)
        !            82:        register char *p;
        !            83: {
        !            84:        register int i = 0;
        !            85: 
        !            86:        if (p != 0)
        !            87:                while (*p)
        !            88:                        i = i * 10 + *p++ - '0';
        !            89:        return (i);
        !            90: }

unix.superglobalmegacorp.com

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