]>
diplodocus.org Git - nmh/blob - test/getfullname.c
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 *, size_t);
20 main(int argc
, char *argv
[])
26 fprintf (stderr
, "usage: %s [name]\n", argv
[0]);
30 pwd
= getpwuid(getuid());
32 fprintf(stderr
, "Unable to retrieve user info for "
33 "userid %ld\n", (long) getuid());
37 strncpy(buf
, pwd
->pw_gecos
, sizeof(buf
));
38 buf
[sizeof(buf
) - 1] = '\0';
40 strncpy(buf
, argv
[1], sizeof(buf
));
43 * Perform the same processing that getuserinfo() does.
47 * Stop at the first comma.
49 if ((p
= strchr(buf
, ',')))
53 * Quote the entire string if it has a special character in it.
55 escape_display_name (buf
, sizeof(buf
));