From: Emil Velikov Date: Fri, 23 May 2025 13:15:36 +0000 (+0100) Subject: libkmod: reuse strstartswith() whenever possible X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a3f9ae2826ab66da51dbafcfd436c35382b83316;p=thirdparty%2Fkmod.git libkmod: reuse strstartswith() whenever possible Use our handy macro(s) for clarity and consistency sake. Signed-off-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/354 Signed-off-by: Lucas De Marchi --- diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c index ee1cb946..9e03f3c5 100644 --- a/libkmod/libkmod-config.c +++ b/libkmod/libkmod-config.c @@ -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) diff --git a/libkmod/libkmod-elf.c b/libkmod/libkmod-elf.c index 0fc95348..4775360d 100644 --- a/libkmod/libkmod-elf.c +++ b/libkmod/libkmod-elf.c @@ -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; diff --git a/libkmod/libkmod.c b/libkmod/libkmod.c index f4510d0e..fceed93b 100644 --- a/libkmod/libkmod.c +++ b/libkmod/libkmod.c @@ -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; }