]> diplodocus.org Git - nmh/blobdiff - test/getfullname.c
mhlsbr.c: Don't strchr(3) non-string NUL-less buffer.
[nmh] / test / getfullname.c
index 0e12fe9389fde896a80b53a7cfb6ce0087254a7b..9a342ca1a8f9a6ca6f23b33bc6064800da450807 100644 (file)
@@ -22,9 +22,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 +36,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 +53,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);
 }