OSDN Git Service

0e9c4a0133a8aba84f16204108d03015f3b04b1a
[uclinux-h8/uclibc-ng.git] / test / pwd_grp / test_grp.c
1 /*
2  * test_grp.c - This file is part of the libc-8086/grp package for ELKS,
3  * Copyright (C) 1995, 1996 Nat Friedman <ndf@linux.mit.edu>.
4  * 
5  *  This library is free software; you can redistribute it and/or
6  *  modify it under the terms of the GNU Library General Public
7  *  License as published by the Free Software Foundation; either
8  *  version 2 of the License, or (at your option) any later version.
9  *
10  *  This library is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  *  Library General Public License for more details.
14  *
15  *  You should have received a copy of the GNU Library General Public
16  *  License along with this library; if not, write to the Free
17  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  */
20
21 #include <unistd.h>
22 #include <stdio.h>
23 #include <fcntl.h>
24 #include <grp.h>
25
26 int main(int argc, char **argv)
27 {
28         struct group *group;
29         char **tmp_mem;
30         int test_gid;
31
32         fprintf(stdout, "Beginning test of libc/grp...\n");
33
34         fprintf(stdout, "=> Testing setgrent(), getgrent(), endgrent()...\n");
35         fprintf(stdout, "-> setgrent()...\n");
36         setgrent();
37         fprintf(stdout, "-> getgrent()...\n");
38         printf
39                 ("********************************************************************************\n");
40         while ((group = getgrent()) != NULL) {
41                 printf("gr_name\t\t: %s\n", group->gr_name);
42                 printf("gr_passwd\t: %s\n", group->gr_passwd);
43                 printf("gr_gid\t\t: %d\n", (int) group->gr_gid);
44                 printf("gr_mem\t\t: ");
45                 fflush(stdout);
46                 tmp_mem = group->gr_mem;
47                 while (*tmp_mem != NULL) {
48                         printf("%s, ", *tmp_mem);
49                         tmp_mem++;
50                 }
51                 printf
52                         ("\n********************************************************************************\n");
53         }
54         fprintf(stdout, "-> endgrent()...\n");
55         endgrent();
56         fprintf(stdout,
57                         "=> Test of setgrent(), getgrent(), endgrent() complete.\n");
58         fprintf(stdout, "=> Testing getgrid(), getgrnam()...\n");
59         fprintf(stdout, "-> getgrgid()...\n");
60         printf
61                 ("********************************************************************************\n");
62         for (test_gid = 0; test_gid < 100; test_gid++) {
63                 fprintf(stdout, "-> getgrgid(%d)...\n", test_gid);
64                 group = getgrgid((gid_t) test_gid);
65                 if (group != NULL) {
66                         printf("gr_name\t: %s\n", group->gr_name);
67                         printf("gr_passwd\t: %s\n", group->gr_passwd);
68                         printf("gr_gid\t: %d\n", (int) group->gr_gid);
69                         printf("gr_mem\t\t: ");
70                         fflush(stdout);
71                         tmp_mem = group->gr_mem;
72                         while (*tmp_mem != NULL) {
73                                 printf("%s, ", *tmp_mem);
74                                 tmp_mem++;
75                         }
76                 }
77                 printf
78                         ("\n********************************************************************************\n");
79         }
80         fprintf(stdout, "-> getgrnam()...\n");
81         group = getgrnam("root");
82         if (group == NULL) {
83                 printf(">NULL<\n");
84         } else {
85                 printf("gr_name\t: %s\n", group->gr_name);
86                 printf("gr_passwd\t: %s\n", group->gr_passwd);
87                 printf("gr_gid\t: %d\n", (int) group->gr_gid);
88                 printf("gr_mem\t\t: ");
89                 fflush(stdout);
90                 tmp_mem = group->gr_mem;
91                 while (*tmp_mem != NULL) {
92                         printf("%s, ", *tmp_mem);
93                         tmp_mem++;
94                 }
95                 printf("\n");
96         }
97
98
99         return 0;
100 }