]>
diplodocus.org Git - nmh/blob - test/getfullname.c
1 /* getfullname.c - Extract a user's name out of the GECOS field in
4 * This code is Copyright (c) 2012, by the authors of nmh. See the
5 * COPYRIGHT file in the root directory of the nmh distribution for
6 * complete copyright information.
13 #include <sys/types.h>
16 extern void escape_display_name (char *, size_t);
19 main(int argc
, char *argv
[])
25 fprintf (stderr
, "usage: %s [name]\n", argv
[0]);
29 pwd
= getpwuid(getuid());
31 fprintf(stderr
, "Unable to retrieve user info for "
32 "userid %ld\n", (long) getuid());
36 strncpy(buf
, pwd
->pw_gecos
, sizeof(buf
));
37 buf
[sizeof(buf
) - 1] = '\0';
39 strncpy(buf
, argv
[1], sizeof(buf
));
42 * Perform the same processing that getuserinfo() does.
46 * Stop at the first comma.
48 if ((p
= strchr(buf
, ',')))
52 * Quote the entire string if it has a special character in it.
54 escape_display_name (buf
, sizeof(buf
));