diff options
author | Karel Zak | 2015-01-06 10:57:09 +0100 |
---|---|---|
committer | Karel Zak | 2015-01-06 10:57:09 +0100 |
commit | 84705c8b89d6ae13610ef364bacf4342a90953ad (patch) | |
tree | 2180bc94579e416bb8e32fa47e0aaf7cb63a21e7 /login-utils/chsh.c | |
parent | newgrp: set function arguments read-only when possible (diff) | |
download | kernel-qcow2-util-linux-84705c8b89d6ae13610ef364bacf4342a90953ad.tar.gz kernel-qcow2-util-linux-84705c8b89d6ae13610ef364bacf4342a90953ad.tar.xz kernel-qcow2-util-linux-84705c8b89d6ae13610ef364bacf4342a90953ad.zip |
chsh: simplify get_shell_list()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'login-utils/chsh.c')
-rw-r--r-- | login-utils/chsh.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/login-utils/chsh.c b/login-utils/chsh.c index a84e3ff74..fd2893e95 100644 --- a/login-utils/chsh.c +++ b/login-utils/chsh.c @@ -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') |