]> diplodocus.org Git - nmh/blob - test/getfullname.c
Fix a segfault that happens when using the -file option.
[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 if (argc > 1) {
20 fprintf (stderr, "usage: %s\n", argv[0]);
21 }
22
23 struct passwd *pwd;
24
25 pwd = getpwuid(getuid());
26
27 if (! pwd) {
28 fprintf(stderr, "Unable to retrieve user info for "
29 "userid %d\n", getuid());
30 exit(1);
31 }
32
33 printf("%s\n", pwd->pw_gecos);
34
35 exit(0);
36 }