From: Alejandro Colomar Date: Tue, 10 Dec 2024 03:38:45 +0000 (+0100) Subject: lib/, src/: Use s=strprefix(s,p)?:s instead of its pattern X-Git-Tag: 4.18.0-rc1~79 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b6140635eb26db56e1e8d60ace09f77e1f85daad;p=thirdparty%2Fshadow.git lib/, src/: Use s=strprefix(s,p)?:s instead of its pattern This skips an optional prefix. Signed-off-by: Alejandro Colomar --- diff --git a/lib/console.c b/lib/console.c index 283893311..23d775de8 100644 --- a/lib/console.c +++ b/lib/console.c @@ -17,6 +17,7 @@ #include "getdef.h" #include "prototypes.h" #include "string/strcmp/streq.h" +#include "string/strcmp/strprefix.h" #include "string/strcpy/strtcpy.h" #include "string/strtok/stpsep.h" @@ -103,9 +104,7 @@ is_listed(const char *cfgin, const char *tty, bool def) bool console (const char *tty) { - if (strncmp (tty, "/dev/", 5) == 0) { - tty += 5; - } + tty = strprefix(tty, "/dev/") ?: tty; return is_listed ("CONSOLE", tty, true); } diff --git a/lib/limits.c b/lib/limits.c index dec33f5c4..451fdf1c5 100644 --- a/lib/limits.c +++ b/lib/limits.c @@ -37,6 +37,7 @@ #include "atoi/str2i/str2u.h" #include "string/memset/memzero.h" #include "string/strcmp/streq.h" +#include "string/strcmp/strprefix.h" #include "string/strspn/stpspn.h" #include "typetraits.h" @@ -473,9 +474,7 @@ void setup_limits (const struct passwd *info) } } for (cp = info->pw_gecos; cp != NULL; cp = strchr (cp, ',')) { - if (',' == *cp) { - cp++; - } + cp = strprefix(cp, ",") ?: cp; if (strncmp (cp, "pri=", 4) == 0) { int inc; diff --git a/lib/strtoday.c b/lib/strtoday.c index dc682b393..fb242bfbb 100644 --- a/lib/strtoday.c +++ b/lib/strtoday.c @@ -16,6 +16,7 @@ #include "prototypes.h" #include "string/ctype/strisascii/strisdigit.h" #include "string/strcmp/streq.h" +#include "string/strcmp/strprefix.h" #include "string/strspn/stpspn.h" @@ -37,9 +38,7 @@ long strtoday (const char *str) /* If a numerical value is provided, this is already a number of * days since EPOCH. */ - if ('-' == *s) { - s++; - } + s = strprefix(s, "-") ?: s; s = stpspn(s, " "); if (strisdigit(s)) { long retdate; diff --git a/lib/user_busy.c b/lib/user_busy.c index 73c380bcc..e4b19afe4 100644 --- a/lib/user_busy.c +++ b/lib/user_busy.c @@ -29,6 +29,7 @@ #include "shadowlog.h" #include "string/sprintf/snprintf.h" #include "string/strcmp/streq.h" +#include "string/strcmp/strprefix.h" #ifdef __linux__ @@ -204,9 +205,7 @@ static int user_busy_processes (const char *name, uid_t uid) || streq(tmp_d_name, "..")) { continue; } - if (*tmp_d_name == '.') { - tmp_d_name++; - } + tmp_d_name = strprefix(tmp_d_name, ".") ?: tmp_d_name; /* Check if this is a valid PID */ if (get_pid(tmp_d_name, &pid) == -1) { diff --git a/lib/utmp.c b/lib/utmp.c index 6dc1f5df2..09fc2c9eb 100644 --- a/lib/utmp.c +++ b/lib/utmp.c @@ -27,6 +27,7 @@ #include "alloc/x/xmalloc.h" #include "sizeof.h" #include "string/strcmp/streq.h" +#include "string/strcmp/strprefix.h" #include "string/strcpy/strncpy.h" #include "string/strcpy/strtcpy.h" #include "string/strdup/xstrdup.h" @@ -261,10 +262,7 @@ prepare_utmp(const char *name, const char *line, const char *host, hostname = XSTRNDUP(ut->ut_host); #endif - if (strncmp(line, "/dev/", 5) == 0) { - line += 5; - } - + line = strprefix(line, "/dev/") ?: line; utent = XCALLOC(1, struct utmpx); diff --git a/src/newgrp.c b/src/newgrp.c index 905ac2f4c..effd3d3f6 100644 --- a/src/newgrp.c +++ b/src/newgrp.c @@ -30,6 +30,7 @@ #include "shadowlog.h" #include "string/sprintf/snprintf.h" #include "string/strcmp/streq.h" +#include "string/strcmp/strprefix.h" #include "string/strdup/xstrdup.h" #include @@ -249,9 +250,9 @@ static void syslog_sg (const char *name, const char *group) } if (tty == NULL) { tty = "???"; - } else if (strncmp (tty, "/dev/", 5) == 0) { - tty += 5; } + tty = strprefix(tty, "/dev/") ?: tty; + SYSLOG ((LOG_INFO, "user '%s' (login '%s' on %s) switched to group '%s'", name, loginname, tty, group));