Annotation of 3BSD/cmd/csh/getpwent.c, revision 1.1

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

unix.superglobalmegacorp.com

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