X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/c4e3a0c3f0c72c6932d132974e268f0c0a54afbc..0d6615596f998269754a1861f030ebc22092a84c:/test/getfullname.c diff --git a/test/getfullname.c b/test/getfullname.c index 0e12fe93..14f45423 100644 --- a/test/getfullname.c +++ b/test/getfullname.c @@ -1,5 +1,4 @@ -/* - * getfullname.c - Extract a user's name out of the GECOS field in +/* getfullname.c - Extract a user's name out of the GECOS field in * the password file. * * This code is Copyright (c) 2012, by the authors of nmh. See the @@ -22,9 +21,12 @@ main(int argc, char *argv[]) struct passwd *pwd; char buf[BUFSIZ], *p; + if (argc > 2) { + fprintf (stderr, "usage: %s [name]\n", argv[0]); + return 1; + } if (argc < 2) { pwd = getpwuid(getuid()); - if (! pwd) { fprintf(stderr, "Unable to retrieve user info for " "userid %ld\n", (long) getuid()); @@ -33,12 +35,8 @@ main(int argc, char *argv[]) strncpy(buf, pwd->pw_gecos, sizeof(buf)); buf[sizeof(buf) - 1] = '\0'; - } else if (argc == 2) { + } else strncpy(buf, argv[1], sizeof(buf)); - } else if (argc > 2) { - fprintf (stderr, "usage: %s [name]\n", argv[0]); - return 1; - } /* * Perform the same processing that getuserinfo() does. @@ -54,8 +52,7 @@ main(int argc, char *argv[]) * Quote the entire string if it has a special character in it. */ escape_display_name (buf, sizeof(buf)); - - printf("%s\n", buf); + puts(buf); exit(0); }