]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
lib: Substitute some STREQLEN with STRPREFIX
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 26 Jan 2021 16:06:50 +0000 (17:06 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 10 Feb 2021 10:51:59 +0000 (11:51 +0100)
There are few cases where STREQLEN() is called like this:

  STREQLEN(var, string, strlen(string))

which is the same as STRPREFIX(var, string). Use STRPREFIX()
because it is more obvious what the check is doing.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
src/libxl/xen_xl.c
src/util/vircgroupv2.c
tools/vsh.c

index 941832ce4eead2d61bccfa23082c1130e6ec1a7f..69b139354e070eeddc7d42b1ca7537eacdab8962 100644 (file)
@@ -950,7 +950,7 @@ xenParseXLUSBController(virConfPtr conf, virDomainDefPtr def)
                 else
                     usbctrl_type = VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB2;
             } else {
-                if (STREQLEN(type, "qusb", 4)) {
+                if (STRPREFIX(type, "qusb")) {
                     if (usbctrl_version == 1)
                         usbctrl_type = VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB1;
                     else
index 4a239f067a645b851b9da94f35a24988b9998887..49acd27714f82b9e19e1da064d2f2809905206fa 100644 (file)
@@ -938,7 +938,7 @@ virCgroupV2GetBlkioDeviceReadIops(virCgroupPtr group,
         }
         tmp += strlen(name);
 
-        if (STREQLEN(tmp, "max", 3)) {
+        if (STRPREFIX(tmp, "max")) {
             *riops = 0;
         } else if (virStrToLong_ui(tmp, &tmp, 10, riops) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -1007,7 +1007,7 @@ virCgroupV2GetBlkioDeviceWriteIops(virCgroupPtr group,
         }
         tmp += strlen(name);
 
-        if (STREQLEN(tmp, "max", 3)) {
+        if (STRPREFIX(tmp, "max")) {
             *wiops = 0;
         } else if (virStrToLong_ui(tmp, &tmp, 10, wiops) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -1076,7 +1076,7 @@ virCgroupV2GetBlkioDeviceReadBps(virCgroupPtr group,
         }
         tmp += strlen(name);
 
-        if (STREQLEN(tmp, "max", 3)) {
+        if (STRPREFIX(tmp, "max")) {
             *rbps = 0;
         } else if (virStrToLong_ull(tmp, &tmp, 10, rbps) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -1145,7 +1145,7 @@ virCgroupV2GetBlkioDeviceWriteBps(virCgroupPtr group,
         }
         tmp += strlen(name);
 
-        if (STREQLEN(tmp, "max", 3)) {
+        if (STRPREFIX(tmp, "max")) {
             *wbps = 0;
         } else if (virStrToLong_ull(tmp, &tmp, 10, wbps) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -1578,7 +1578,7 @@ virCgroupV2GetCpuCfsQuota(virCgroupPtr group,
         return -1;
     }
 
-    if (STREQLEN(str, "max", 3)) {
+    if (STRPREFIX(str, "max")) {
         *cfs_quota = VIR_CGROUP_CPU_QUOTA_MAX;
         return 0;
     }
index 202bd564f7c00c7261484040e4d28f0dc154d64e..289ed82dbed04372c1ed25a318d827e4a3e4e203 100644 (file)
@@ -2568,7 +2568,6 @@ static char **
 vshReadlineCommandGenerator(const char *text)
 {
     size_t grp_list_index = 0, cmd_list_index = 0;
-    size_t len = strlen(text);
     const char *name;
     const vshCmdGrp *grp;
     const vshCmdDef *cmds;
@@ -2588,7 +2587,7 @@ vshReadlineCommandGenerator(const char *text)
                 if (cmds[cmd_list_index++].flags & VSH_CMD_FLAG_ALIAS)
                     continue;
 
-                if (STREQLEN(name, text, len)) {
+                if (STRPREFIX(name, text)) {
                     if (VIR_REALLOC_N(ret, ret_size + 2) < 0) {
                         g_strfreev(ret);
                         return NULL;