[PATCH 3/5] util: Rename virFileMatchesNameSuffix() to virStringMatchesNameSuffix()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Despite its name, this is really just a general-purpose string
manipulation function, so it should be moved to the virstring
module and renamed accordingly.

Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx>
---
 src/conf/virsecretobj.c  |  2 +-
 src/conf/virstorageobj.c |  2 +-
 src/libvirt_private.syms |  2 +-
 src/util/virfile.c       | 17 -----------------
 src/util/virfile.h       |  4 ----
 src/util/virstring.c     | 17 +++++++++++++++++
 src/util/virstring.h     |  3 +++
 7 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c
index 5cd36b8a40..b01dc7cc70 100644
--- a/src/conf/virsecretobj.c
+++ b/src/conf/virsecretobj.c
@@ -819,7 +819,7 @@ virSecretLoadValidateUUID(virSecretDefPtr def,
 
     virUUIDFormat(def->uuid, uuidstr);
 
-    if (!virFileMatchesNameSuffix(file, uuidstr, ".xml")) {
+    if (!virStringMatchesNameSuffix(file, uuidstr, ".xml")) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("<uuid> does not match secret file name '%s'"),
                        file);
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c
index 85b6dd3695..a30d86d070 100644
--- a/src/conf/virstorageobj.c
+++ b/src/conf/virstorageobj.c
@@ -1585,7 +1585,7 @@ virStoragePoolObjLoad(virStoragePoolObjListPtr pools,
     if (!(def = virStoragePoolDefParseFile(path)))
         return NULL;
 
-    if (!virFileMatchesNameSuffix(file, def->name, ".xml")) {
+    if (!virStringMatchesNameSuffix(file, def->name, ".xml")) {
         virReportError(VIR_ERR_XML_ERROR,
                        _("Storage pool config filename '%s' does "
                          "not match pool name '%s'"),
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index f94a8fdc3d..d7ccd509e9 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1851,7 +1851,6 @@ virFileLoopDeviceAssociate;
 virFileMakeParentPath;
 virFileMakePath;
 virFileMakePathWithMode;
-virFileMatchesNameSuffix;
 virFileMoveMount;
 virFileNBDDeviceAssociate;
 virFileOpenAs;
@@ -2972,6 +2971,7 @@ virStringListLength;
 virStringListMerge;
 virStringListRemove;
 virStringMatch;
+virStringMatchesNameSuffix;
 virStringParsePort;
 virStringReplace;
 virStringSearch;
diff --git a/src/util/virfile.c b/src/util/virfile.c
index c0f3f56293..a4c6d184af 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -1508,23 +1508,6 @@ virFileWriteStr(const char *path, const char *str, mode_t mode)
     return 0;
 }
 
-int
-virFileMatchesNameSuffix(const char *file,
-                         const char *name,
-                         const char *suffix)
-{
-    int filelen = strlen(file);
-    int namelen = strlen(name);
-    int suffixlen = strlen(suffix);
-
-    if (filelen == (namelen + suffixlen) &&
-        STREQLEN(file, name, namelen) &&
-        STREQLEN(file + namelen, suffix, suffixlen))
-        return 1;
-    else
-        return 0;
-}
-
 #define SAME_INODE(Stat_buf_1, Stat_buf_2) \
   ((Stat_buf_1).st_ino == (Stat_buf_2).st_ino \
    && (Stat_buf_1).st_dev == (Stat_buf_2).st_dev)
diff --git a/src/util/virfile.h b/src/util/virfile.h
index 0079e234f8..3dedb7666a 100644
--- a/src/util/virfile.h
+++ b/src/util/virfile.h
@@ -162,10 +162,6 @@ int virFileReadBufQuiet(const char *file, char *buf, int len)
 int virFileWriteStr(const char *path, const char *str, mode_t mode)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
 
-int virFileMatchesNameSuffix(const char *file,
-                             const char *name,
-                             const char *suffix);
-
 int virFileLinkPointsTo(const char *checkLink,
                         const char *checkDest)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
diff --git a/src/util/virstring.c b/src/util/virstring.c
index 60b4167af4..b4d10f9884 100644
--- a/src/util/virstring.c
+++ b/src/util/virstring.c
@@ -1266,6 +1266,23 @@ virStringStripSuffix(char *str,
     return 1;
 }
 
+int
+virStringMatchesNameSuffix(const char *file,
+                           const char *name,
+                           const char *suffix)
+{
+    int filelen = strlen(file);
+    int namelen = strlen(name);
+    int suffixlen = strlen(suffix);
+
+    if (filelen == (namelen + suffixlen) &&
+        STREQLEN(file, name, namelen) &&
+        STREQLEN(file + namelen, suffix, suffixlen))
+        return 1;
+    else
+        return 0;
+}
+
 /**
  * virStringStripIPv6Brackets:
  * @str: the string to strip
diff --git a/src/util/virstring.h b/src/util/virstring.h
index 580e4da9b9..69030566e9 100644
--- a/src/util/virstring.h
+++ b/src/util/virstring.h
@@ -292,6 +292,9 @@ int virStringHasCaseSuffix(const char *str,
                            const char *suffix);
 int virStringStripSuffix(char *str,
                          const char *suffix) ATTRIBUTE_RETURN_CHECK;
+int virStringMatchesNameSuffix(const char *file,
+                               const char *name,
+                               const char *suffix);
 
 void virStringStripIPv6Brackets(char *str);
 bool virStringHasChars(const char *str,
-- 
2.20.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux