]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/, src/: Use s=strprefix(s,p)?:s instead of its pattern
authorAlejandro Colomar <alx@kernel.org>
Tue, 10 Dec 2024 03:38:45 +0000 (04:38 +0100)
committerSerge Hallyn <serge@hallyn.com>
Mon, 26 May 2025 16:29:26 +0000 (11:29 -0500)
This skips an optional prefix.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/console.c
lib/limits.c
lib/strtoday.c
lib/user_busy.c
lib/utmp.c
src/newgrp.c

index 283893311e07c87947614d0da5d49c63d9fa71c0..23d775de8e4b6f279ac9bdc59709270352252d81 100644 (file)
@@ -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);
 }
index dec33f5c4f385bf4056816aed45f1236c98f3a81..451fdf1c580bee5938da7d21c569dd14d31f50ad 100644 (file)
@@ -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;
index dc682b3932b626cb7df42a0b6339f0f14b842c31..fb242bfbb6b6df0d8ff1f5a4adfac8f3adac6321 100644 (file)
@@ -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;
index 73c380bccab16d2c4b3322d3495ddd43486b3103..e4b19afe494be602b5e0fe686838de3578116167 100644 (file)
@@ -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) {
index 6dc1f5df29597601623c4ad6ef191fef04c53151..09fc2c9ebcb349dec89ce6771bf9d6d4088d1e53 100644 (file)
@@ -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);
 
index 905ac2f4c82c71967b66304db69c0982c6988f20..effd3d3f63cdb96e61200689829072cb7488b300 100644 (file)
@@ -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 <assert.h>
@@ -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));