# 2.11BSD#431 - /usr/src/lib/libc/gen/getgrent.c

##### Functions

    endgrent          X
    getgrent          X
    setgrent          X

##### Macros

    MAXGRP            X

       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

endgrent defined in line 24; used 13 times

- in /usr/src/lib/libc/gen/getgrgid.c line 16
- in /usr/src/lib/libc/gen/getgrnam.c line 16
- in /usr/src/lib/libc/gen/getgrouplist.c line 84
- in /usr/src/lib/libc/gen/initgroups.c line 44
- in /usr/src/libexec/identd/src/parse.c line 644, 661
- in /usr/src/libexec/tcpd/options.c line 254
- in /usr/src/new/notes/src/access.c line 216
- in /usr/src/old/dump/dumpoptr.c line 101
- in /usr/src/sbin/dump/dumpoptr.c line 105
- in /usr/src/usr.bin/find/find.c line 1002-1005(2)
- in /usr/src/usr.sbin/chown/chown.c line 76

getgrent defined in line 42; used 14 times

- in /usr/include/grp.h line 10
- in /usr/src/include/grp.h line 10
- in /usr/src/lib/libc/gen/getgrgid.c line 12-15(2)
- in /usr/src/lib/libc/gen/getgrnam.c line 12-15(2)
- in /usr/src/lib/libc/gen/getgrouplist.c line 70
- in /usr/src/lib/libc/gen/initgroups.c line 18, 31
- in /usr/src/libexec/identd/src/parse.c line 633, 650
- in /usr/src/usr.bin/find/find.c line 986, 997, 1010

grskip defined in line 32; used 5 times

- in line 52-61(5)

setgrent defined in line 16; used 8 times

- in /usr/src/lib/libc/gen/getgrgid.c line 14
- in /usr/src/lib/libc/gen/getgrnam.c line 14
- in /usr/src/lib/libc/gen/getgrouplist.c line 69
- in /usr/src/lib/libc/gen/initgroups.c line 30
- in /usr/src/libexec/identd/src/parse.c line 632, 649
- in /usr/src/usr.bin/find/find.c line 996, 1009

#### Defined variables

GROUP defined in line 10; used 2 times

- in line 19, 47

gr_mem defined in line 14; used 4 times

- in line 54-59(4)

group defined in line 13; used 5 times

- in line 51-54(4), 64

line defined in line 12; used 2 times

- in line 49(2)

sccsid defined in line 2; never used

#### Defined macros

MAXGRP defined in line 8; used 2 times

- in line 14, 59

Last modified: 1988-08-23 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 686 |