1 /* User and Group Database Example
2 Copyright (C) 1991-2012 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, if not, see <http://www.gnu.org/licenses/>.
20 #include <sys/types.h>
28 struct passwd
*my_passwd
;
29 struct group
*my_group
;
32 /* Get information about the user ID. */
34 my_passwd
= getpwuid (me
);
37 printf ("Couldn't find out about user %d.\n", (int) me
);
41 /* Print the information. */
42 printf ("I am %s.\n", my_passwd
->pw_gecos
);
43 printf ("My login name is %s.\n", my_passwd
->pw_name
);
44 printf ("My uid is %d.\n", (int) (my_passwd
->pw_uid
));
45 printf ("My home directory is %s.\n", my_passwd
->pw_dir
);
46 printf ("My default shell is %s.\n", my_passwd
->pw_shell
);
48 /* Get information about the default group ID. */
49 my_group
= getgrgid (my_passwd
->pw_gid
);
52 printf ("Couldn't find out about group %d.\n",
53 (int) my_passwd
->pw_gid
);
57 /* Print the information. */
58 printf ("My default group is %s (%d).\n",
59 my_group
->gr_name
, (int) (my_passwd
->pw_gid
));
60 printf ("The members of this group are:\n");
61 members
= my_group
->gr_mem
;
64 printf (" %s\n", *(members
));