|
|
1.1 ! root 1: /* @(#)getgrent.c 4.1 (Berkeley) 12/21/80 */ ! 2: #include <stdio.h> ! 3: #include <grp.h> ! 4: ! 5: #define CL ':' ! 6: #define CM ',' ! 7: #define NL '\n' ! 8: #define MAXGRP 100 ! 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,CL); ! 53: group.gr_gid = atoi( p = grskip(p,CL) ); ! 54: group.gr_mem = gr_mem; ! 55: p = grskip(p,CL); ! 56: grskip(p,NL); ! 57: q = gr_mem; ! 58: while( *p ){ ! 59: *q++ = p; ! 60: p = grskip(p,CM); ! 61: } ! 62: *q = NULL; ! 63: return( &group ); ! 64: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.