1: #if defined(LIBC_SCCS) && !defined(lint)
2: static char sccsid[] = "@(#)getgrent.c 5.2 (Berkeley) 3/9/86";
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[256+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, sizeof(line)-1, 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: }
Defined functions
Defined variables
GROUP
defined in line
10; used 2 times
group
defined in line
13; used 5 times
line
defined in line
12; used 2 times
sccsid
defined in line
2;
never used
Defined macros
MAXGRP
defined in line
8; used 2 times