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