[BZ #531]
[glibc.git] / manual / examples / db.c
blob1a1cb0c0d7be87f9e5c474fb01c309348021e46c
1 #include <grp.h>
2 #include <pwd.h>
3 #include <sys/types.h>
4 #include <unistd.h>
5 #include <stdlib.h>
7 int
8 main (void)
10 uid_t me;
11 struct passwd *my_passwd;
12 struct group *my_group;
13 char **members;
15 /* Get information about the user ID. */
16 me = getuid ();
17 my_passwd = getpwuid (me);
18 if (!my_passwd)
20 printf ("Couldn't find out about user %d.\n", (int) me);
21 exit (EXIT_FAILURE);
24 /* Print the information. */
25 printf ("I am %s.\n", my_passwd->pw_gecos);
26 printf ("My login name is %s.\n", my_passwd->pw_name);
27 printf ("My uid is %d.\n", (int) (my_passwd->pw_uid));
28 printf ("My home directory is %s.\n", my_passwd->pw_dir);
29 printf ("My default shell is %s.\n", my_passwd->pw_shell);
31 /* Get information about the default group ID. */
32 my_group = getgrgid (my_passwd->pw_gid);
33 if (!my_group)
35 printf ("Couldn't find out about group %d.\n",
36 (int) my_passwd->pw_gid);
37 exit (EXIT_FAILURE);
40 /* Print the information. */
41 printf ("My default group is %s (%d).\n",
42 my_group->gr_name, (int) (my_passwd->pw_gid));
43 printf ("The members of this group are:\n");
44 members = my_group->gr_mem;
45 while (*members)
47 printf (" %s\n", *(members));
48 members++;
51 return EXIT_SUCCESS;