Annotation of 43BSDTahoe/lib/libc/gen/getgrent.c, revision 1.1

1.1     ! root        1: #if defined(LIBC_SCCS) && !defined(lint)
        !             2: static char sccsid[] = "@(#)getgrent.c 5.3 (Berkeley) 11/5/87";
        !             3: #endif LIBC_SCCS and not lint
        !             4: 
        !             5: #include <stdio.h>
        !             6: #include <grp.h>
        !             7: 
        !             8: #define        MAXGRP  200
        !             9: 
        !            10: static char *GROUP = "/etc/group";
        !            11: static FILE *grf = NULL;
        !            12: static char line[BUFSIZ+1];
        !            13: static struct group group;
        !            14: static char *gr_mem[MAXGRP];
        !            15: 
        !            16: setgrent()
        !            17: {
        !            18:        if( !grf )
        !            19:                grf = fopen( GROUP, "r" );
        !            20:        else
        !            21:                rewind( grf );
        !            22: }
        !            23: 
        !            24: endgrent()
        !            25: {
        !            26:        if( grf ){
        !            27:                fclose( grf );
        !            28:                grf = NULL;
        !            29:        }
        !            30: }
        !            31: 
        !            32: static char *
        !            33: grskip(p,c)
        !            34: register char *p;
        !            35: register c;
        !            36: {
        !            37:        while( *p && *p != c ) ++p;
        !            38:        if( *p ) *p++ = 0;
        !            39:        return( p );
        !            40: }
        !            41: 
        !            42: struct group *
        !            43: getgrent()
        !            44: {
        !            45:        register char *p, **q;
        !            46: 
        !            47:        if( !grf && !(grf = fopen( GROUP, "r" )) )
        !            48:                return(NULL);
        !            49:        if( !(p = fgets( line, BUFSIZ, grf )) )
        !            50:                return(NULL);
        !            51:        group.gr_name = p;
        !            52:        group.gr_passwd = p = grskip(p,':');
        !            53:        group.gr_gid = atoi( p = grskip(p,':') );
        !            54:        group.gr_mem = gr_mem;
        !            55:        p = grskip(p,':');
        !            56:        grskip(p,'\n');
        !            57:        q = gr_mem;
        !            58:        while( *p ){
        !            59:                if (q < &gr_mem[MAXGRP-1])
        !            60:                        *q++ = p;
        !            61:                p = grskip(p,',');
        !            62:        }
        !            63:        *q = NULL;
        !            64:        return( &group );
        !            65: }
        !            66: 
        !            67: setgrfile(file)
        !            68:        char *file;
        !            69: {
        !            70:        GROUP = file;
        !            71: }

unix.superglobalmegacorp.com

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