[libvirt] [PATCH 5/5] Use virStringHasSuffix() where possible

Andrea Bolognani abologna at redhat.com
Wed Mar 6 16:54:04 UTC 2019


When dealing with internal paths we don't need to worry about
whether or not suffixes are lowercase since we have full control
over them, which means we can avoid performing case-insensitive
string comparisons.

Signed-off-by: Andrea Bolognani <abologna at redhat.com>
---
 src/conf/virsecretobj.c  | 2 +-
 src/conf/virstorageobj.c | 2 +-
 src/libvirt_private.syms | 1 +
 src/vmx/vmx.c            | 2 +-
 tests/testutils.c        | 4 ++--
 tests/virschematest.c    | 4 ++--
 tools/nss/libvirt_nss.c  | 4 ++--
 7 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c
index b01dc7cc70..7800912bff 100644
--- a/src/conf/virsecretobj.c
+++ b/src/conf/virsecretobj.c
@@ -949,7 +949,7 @@ virSecretLoadAllConfigs(virSecretObjListPtr secrets,
         char *path;
         virSecretObjPtr obj;
 
-        if (!virStringHasCaseSuffix(de->d_name, ".xml"))
+        if (!virStringHasSuffix(de->d_name, ".xml"))
             continue;
 
         if (!(path = virFileBuildPath(configDir, de->d_name, NULL)))
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c
index a30d86d070..1d6c9d1937 100644
--- a/src/conf/virstorageobj.c
+++ b/src/conf/virstorageobj.c
@@ -1719,7 +1719,7 @@ virStoragePoolObjLoadAllConfigs(virStoragePoolObjListPtr pools,
         char *autostartLink;
         virStoragePoolObjPtr obj;
 
-        if (!virStringHasCaseSuffix(entry->d_name, ".xml"))
+        if (!virStringHasSuffix(entry->d_name, ".xml"))
             continue;
 
         if (!(path = virFileBuildPath(configDir, entry->d_name, NULL)))
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index d7ccd509e9..1eab68622d 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2958,6 +2958,7 @@ virStringFilterChars;
 virStringHasCaseSuffix;
 virStringHasChars;
 virStringHasControlChars;
+virStringHasSuffix;
 virStringIsEmpty;
 virStringIsPrintable;
 virStringListAdd;
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index bbf8e55c3f..8ffd5ff088 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -1600,7 +1600,7 @@ virVMXParseConfig(virVMXContext *ctx,
     if (virVMXGetConfigString(conf, "guestOS", &guestOS, true) < 0)
         goto cleanup;
 
-    if (guestOS != NULL && virStringHasCaseSuffix(guestOS, "-64")) {
+    if (guestOS != NULL && virStringHasSuffix(guestOS, "-64")) {
         def->os.arch = VIR_ARCH_X86_64;
     } else {
         def->os.arch = VIR_ARCH_I686;
diff --git a/tests/testutils.c b/tests/testutils.c
index cfdf122ae0..d2aa4e5d49 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -525,8 +525,8 @@ virTestRewrapFile(const char *filename)
     char *script = NULL;
     virCommandPtr cmd = NULL;
 
-    if (!(virStringHasCaseSuffix(filename, ".args") ||
-          virStringHasCaseSuffix(filename, ".ldargs")))
+    if (!(virStringHasSuffix(filename, ".args") ||
+          virStringHasSuffix(filename, ".ldargs")))
         return 0;
 
     if (!perl) {
diff --git a/tests/virschematest.c b/tests/virschematest.c
index 46c67760a7..4e4f912699 100644
--- a/tests/virschematest.c
+++ b/tests/virschematest.c
@@ -41,7 +41,7 @@ static int
 testSchemaFile(const void *args)
 {
     const struct testSchemaData *data = args;
-    bool shouldFail = virStringHasCaseSuffix(data->xml_path, "-invalid.xml");
+    bool shouldFail = virStringHasSuffix(data->xml_path, "-invalid.xml");
     xmlDocPtr xml = NULL;
     int ret = -1;
 
@@ -82,7 +82,7 @@ testSchemaDir(const char *schema,
         return -1;
 
     while ((rc = virDirRead(dir, &ent, dir_path)) > 0) {
-        if (!virStringHasCaseSuffix(ent->d_name, ".xml"))
+        if (!virStringHasSuffix(ent->d_name, ".xml"))
             continue;
         if (ent->d_name[0] == '.')
             continue;
diff --git a/tools/nss/libvirt_nss.c b/tools/nss/libvirt_nss.c
index 4d86f8e6ce..3ff1bada31 100644
--- a/tools/nss/libvirt_nss.c
+++ b/tools/nss/libvirt_nss.c
@@ -274,7 +274,7 @@ findLease(const char *name,
     while ((ret = virDirRead(dir, &entry, leaseDir)) > 0) {
         char *path;
 
-        if (virStringHasCaseSuffix(entry->d_name, ".status")) {
+        if (virStringHasSuffix(entry->d_name, ".status")) {
             if (!(path = virFileBuildPath(leaseDir, entry->d_name, NULL)))
                 goto cleanup;
 
@@ -285,7 +285,7 @@ findLease(const char *name,
                 goto cleanup;
             }
             VIR_FREE(path);
-        } else if (virStringHasCaseSuffix(entry->d_name, ".macs")) {
+        } else if (virStringHasSuffix(entry->d_name, ".macs")) {
             if (!(path = virFileBuildPath(leaseDir, entry->d_name, NULL)))
                 goto cleanup;
 
-- 
2.20.1




More information about the libvir-list mailing list