Annotation of 41BSD/libc/stdio/getgrent.c, revision 1.1

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

unix.superglobalmegacorp.com

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