]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
chsh: simplify get_shell_list()
authorKarel Zak <kzak@redhat.com>
Tue, 6 Jan 2015 09:57:09 +0000 (10:57 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 6 Jan 2015 09:57:09 +0000 (10:57 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/chsh.c

index a84e3ff745fc6fe3135e655bf75402f84737b4ba..fd2893e9554144583f5070c1832c22ac71f54f78 100644 (file)
@@ -88,7 +88,8 @@ static int get_shell_list(const char *shell_name)
        FILE *fp;
        int found = 0;
        char *buf = NULL;
-       size_t sz = 0, len;
+       size_t sz = 0;
+       ssize_t len;
 
        fp = fopen(_PATH_SHELLS, "r");
        if (!fp) {
@@ -96,13 +97,9 @@ static int get_shell_list(const char *shell_name)
                        warnx(_("No known shells."));
                return 0;
        }
-       while (getline(&buf, &sz, fp) != -1) {
-               len = strlen(buf);
-               /* ignore comments */
-               if (*buf == '#')
-                       continue;
-               /* skip blank lines*/
-               if (len < 2)
+       while ((len = getline(&buf, &sz, fp)) != -1) {
+               /* ignore comments and blank lines */
+               if (*buf == '#' || len < 2)
                        continue;
                /* strip the ending newline */
                if (buf[len - 1] == '\n')