initial import
[platform/upstream/glibc.git] / grp / testgrp.c
1 #include <ansidecl.h>
2 #include <grp.h>
3 #include <pwd.h>
4 #include <sys/types.h>
5 #include <unistd.h>
6 #include <stdlib.h>
7 #include <stdio.h>
8
9 int
10 DEFUN_VOID(main)
11 {
12   uid_t me;
13   struct passwd *my_passwd;
14   struct group *my_group;
15   char **members;
16
17   me = getuid ();
18   my_passwd = getpwuid (me);
19   if (my_passwd == NULL)
20     perror ("getpwuid");
21   else
22     {
23       printf ("My login name is %s.\n", my_passwd->pw_name);
24       printf ("My uid is %d.\n", (int)(my_passwd->pw_uid));
25       printf ("My home directory is %s.\n", my_passwd->pw_dir);
26       printf ("My default shell is %s.\n", my_passwd->pw_shell);
27
28       my_group = getgrgid (my_passwd->pw_gid);
29       if (my_group == NULL)
30         perror ("getgrgid");
31       else
32         {
33           printf ("My default group is %s (%d).\n",
34                   my_group->gr_name, (int)(my_passwd->pw_gid));
35           printf ("The members of this group are:\n");
36           for (members = my_group->gr_mem; *members != NULL; ++members)
37             printf ("  %s\n", *members);
38         }
39     }
40
41   exit (my_passwd && my_group ? EXIT_SUCCESS : EXIT_FAILURE);
42 }
43
44
45