From: Christian Goeschel Ndjomouo Date: Sun, 29 Mar 2026 17:35:35 +0000 (-0400) Subject: islocal: improve coding style X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6d5ff86c68938f4ea0011c11676da967c153194e;p=thirdparty%2Futil-linux.git islocal: improve coding style This patch improves the coding style in various places for better readability, semantic clarity and alignment with common best practices. Changes include the transposition of a variable assignment in a conditional statement to its own line for better readability, the removal of defensive programming techniques like 'yoda conditions' where constants are specified on the left of variables, which reduce natural readability and are not necessary as erroneous variable assignments will be indicated by the compiler anyways. Lastly, the 'u' suffix is extraneous for variable assignments to 'match' as it is a size_t. Signed-off-by: Christian Goeschel Ndjomouo --- diff --git a/login-utils/islocal.c b/login-utils/islocal.c index 7d5541fd1..1adddd7cd 100644 --- a/login-utils/islocal.c +++ b/login-utils/islocal.c @@ -34,22 +34,23 @@ static int is_local_in_file(const char *user, const char *filename) int chin, skip; FILE *f; - if (NULL == (f = fopen(filename, "r"))) + f = fopen(filename, "r"); + if (!f) return -1; - match = 0u; + match = 0; skip = 0; while ((chin = fgetc(f)) != EOF) { if (skip) { /* Looking for the start of the next line. */ - if ('\n' == chin) { + if (chin == '\n') { /* Start matching username at the next char. */ skip = 0; - match = 0u; + match = 0; } } else { - if (':' == chin) { - if (0 == user[match]) { + if (chin == ':') { + if (user[match] == '\0') { /* Success. */ local = 1; /* next line has no test coverage, @@ -61,11 +62,11 @@ static int is_local_in_file(const char *user, const char *filename) * is the wrong user. Skip to the * next line. */ skip = 1; - } else if ('\n' == chin) { + } else if (chin == '\n') { /* This line contains no colon; it's * malformed. No skip since we are already * at the start of the next line. */ - match = 0u; + match = 0U; } else if (chin != user[match]) { /* username does not match. */ skip = 1; @@ -82,7 +83,8 @@ int is_local(const char *user) { int rv; - if ((rv = is_local_in_file(user, _PATH_PASSWD)) < 0) + rv = is_local_in_file(user, _PATH_PASSWD); + if (rv < 0) err(EXIT_FAILURE, _("cannot open %s"), _PATH_PASSWD); return rv; }