]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
libkmod: reuse strstartswith() whenever possible
authorEmil Velikov <emil.l.velikov@gmail.com>
Fri, 23 May 2025 13:15:36 +0000 (14:15 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Thu, 29 May 2025 22:10:16 +0000 (17:10 -0500)
Use our handy macro(s) for clarity and consistency sake.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/354
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
libkmod/libkmod-config.c
libkmod/libkmod-elf.c
libkmod/libkmod.c

index ee1cb94647ef45a9c6028f1055fadfa713c0630f..9e03f3c594724ad1a1d49771047cd5e11f8a5ce0 100644 (file)
@@ -617,7 +617,7 @@ static void kcmdline_parse_result(struct kmod_config *config, char *modname, cha
 
        DBG(config->ctx, "%s %s\n", modname, param);
 
-       if (streq(modname, "modprobe") && !strncmp(param, "blacklist=", 10)) {
+       if (streq(modname, "modprobe") && strstartswith(param, "blacklist=")) {
                for (;;) {
                        char *t = strsep(&value, ",");
                        if (t == NULL)
index 0fc95348d8c6dc4df6f24ab53afb98f86a410018..4775360d977e430b34ed36b1ae6666d0e764555c 100644 (file)
@@ -643,7 +643,7 @@ static int elf_strip_vermagic(const struct kmod_elf *elf, uint8_t *changed)
                len = sizeof("vermagic=") - 1;
                if (i + len >= size)
                        continue;
-               if (strncmp(s, "vermagic=", len) != 0) {
+               if (!strstartswith(s, "vermagic=")) {
                        i += strlen(s);
                        continue;
                }
@@ -873,7 +873,7 @@ int kmod_elf_get_symbols(const struct kmod_elf *elf, struct kmod_modversion **ar
 
                name = elf_get_mem(elf, str_off + name_off);
 
-               if (strncmp(name, crc_str, crc_strlen) != 0)
+               if (!strstartswith(name, crc_str))
                        continue;
                count++;
        }
@@ -914,7 +914,7 @@ int kmod_elf_get_symbols(const struct kmod_elf *elf, struct kmod_modversion **ar
                }
 #undef READV
                name = elf_get_mem(elf, str_off + name_off);
-               if (strncmp(name, crc_str, crc_strlen) != 0)
+               if (!strstartswith(name, crc_str))
                        continue;
                name += crc_strlen;
 
index f4510d0e8e0af1f10a4d5a8ac513da72fa8cee09..fceed93b10c2043031e1c7c1e4e6bba37c3bff42 100644 (file)
@@ -153,11 +153,11 @@ static int log_priority(const char *priority)
        prio = strtol(priority, &endptr, 10);
        if (endptr[0] == '\0' || isspace(endptr[0]))
                return prio;
-       if (strncmp(priority, "err", 3) == 0)
+       if (strstartswith(priority, "err"))
                return LOG_ERR;
-       if (strncmp(priority, "info", 4) == 0)
+       if (strstartswith(priority, "info"))
                return LOG_INFO;
-       if (strncmp(priority, "debug", 5) == 0)
+       if (strstartswith(priority, "debug"))
                return LOG_DEBUG;
        return 0;
 }