1: /*	@(#)getgrent.c	2.1	SCCS id keyword	*/
   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: }

Defined functions

grskip defined in line 32; used 5 times

Defined variables

GROUP defined in line 10; used 2 times
gr_mem defined in line 14; used 3 times
group defined in line 13; used 5 times
line defined in line 12; used 1 times
  • in line 49

Defined macros

CL defined in line 5; used 3 times
CM defined in line 6; used 1 times
  • in line 60
MAXGRP defined in line 8; used 1 times
  • in line 14
NL defined in line 7; used 1 times
  • in line 56
Last modified: 1981-07-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 852
Valid CSS Valid XHTML 1.0 Strict