]>
diplodocus.org Git - nmh/blob - test/getfullname.c
ec83939f75ab537411194d269bc2ed98f26b406e
2 * getfullname.c - Extract a user's name out of the GECOS field in
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.
14 #include <sys/types.h>
17 extern void escape_display_name (char *);
20 main(int argc
, char *argv
[])
27 pwd
= getpwuid(getuid());
30 fprintf(stderr
, "Unable to retrieve user info for "
31 "userid %ld\n", (long) getuid());
35 strncpy(buf
, pwd
->pw_gecos
, sizeof(buf
));
36 buf
[sizeof(buf
) - 1] = '\0';
37 } else if (argc
== 2) {
39 } else if (argc
> 2) {
40 fprintf (stderr
, "usage: %s [name]\n", argv
[0]);
45 * Perform the same processing that getuserinfo() does.
49 * Stop at the first comma.
51 if ((p
= strchr(name
, ',')))
55 * Quote the entire string if it has a special character in it.
57 escape_display_name (name
);