Next: , Previous: Passwd Functions, Up: Library Functions  10.6
Reading the Group Database  Much of the discussion presented in
Passwd Functions, applies to the group database as well.
Although there has traditionally been a well-known file
(/etc/group) in a well-known format, the POSIX standard only
provides a set of C library routines (<grp.h> and getgrent())
for accessing the information. Even though this file may exist,
it may not have complete information. Therefore, as with the
user database, it is necessary to have a small C program that
generates the group database as its output. grcat, a C program
that “cats” the group database, is as follows:        * grcat.c
* Generate a printable version of the group database
#include <stdio.h>      #include <grp.h>      main(int argc,
char **argv)          struct group *g;          int i;
while ((g = getgrent()) != NULL) {
printf("%s:%s:%ld:", g->gr_name, g->gr_passwd,
(long) g->gr_gid);