]> diplodocus.org Git - nmh/blobdiff - test/getfullname.c
getpass.c: Move interface to own file.
[nmh] / test / getfullname.c
index 0e12fe9389fde896a80b53a7cfb6ce0087254a7b..14f454238a78f412636f143635bdec3595b87346 100644 (file)
@@ -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);
 }