"Fossies" - the Fresh Open Source Software Archive 
Member "nss_ldap-265/tests/testgr.c" (6 Nov 2009, 1007 Bytes) of package /linux/privat/old/nss_ldap-265.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 #include <stdio.h>
2 #include <grp.h>
3 #include <signal.h>
4
5 void
6 main (int argc, char **argv)
7 {
8 #if 0
9 struct group
10 { /* see getgrent(3) */
11 char *gr_name;
12 char *gr_passwd;
13 gid_t gr_gid;
14 char **gr_mem;
15 };
16 #endif
17
18 scan_group ();
19 exit (0);
20 }
21
22 void
23 dump (struct group *g)
24 {
25 char mem[2048];
26 char **p;
27
28 int doit = (g->gr_mem && *(g->gr_mem));
29 p = g->gr_mem;
30 strcpy (mem, "");
31 while (doit)
32 {
33 if (p != g->gr_mem)
34 strcat (mem, ",");
35 strcat (mem, *p);
36 if (*(++p) == NULL)
37 break;
38 }
39 printf ("%s:%s:%d:%s\n", g->gr_name, g->gr_passwd, g->gr_gid, mem);
40
41 }
42
43 scan_group ()
44 {
45 struct group *g;
46
47 signal(SIGPIPE, SIG_IGN);
48
49 setgrent ();
50
51 while ((g = getgrent ()) != NULL)
52 {
53 dump (g);
54 }
55
56 endgrent ();
57
58 sleep(10);
59
60 printf ("==> getgrnam(qmail)\n");
61 g = getgrnam ("qmail");
62 if (g != NULL)
63 dump (g);
64 #if 0
65 printf ("==> getgrnam(testgroup)\n");
66 g = getgrnam ("testgroup");
67 if (g != NULL)
68 dump (g);
69 #endif
70
71 }