]> diplodocus.org Git - nmh/blob - test/getfullname.c
3afa00f87ea685df8801a8e17a5eab60681da4bd
[nmh] / test / getfullname.c
1 /*
2 * getfullname.c - Extract a user's name out of the GECOS field in
3 * the password file.
4 *
5 * This code is Copyright (c) 2012, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
8 */
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <unistd.h>
13 #include <sys/types.h>
14 #include <pwd.h>
15
16 int
17 main(int argc, char *argv[])
18 {
19 struct passwd *pwd;
20
21 pwd = getpwuid(getuid());
22
23 if (! pwd) {
24 fprintf(stderr, "Unable to retrieve user info for "
25 "userid %d\n", getuid());
26 exit(1);
27 }
28
29 printf("%s\n", pwd->pw_gecos);
30
31 exit(0);
32 }