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.
A few trivial whitespace changes are squashed in.
Signed-off-by: Andrea Bolognani <abologna(a)redhat.com>
---
src/conf/virdomainobjlist.c | 2 +-
src/conf/virnetworkobj.c | 4 ++--
src/conf/virnwfilterbindingobjlist.c | 2 +-
src/conf/virnwfilterobj.c | 2 +-
src/conf/virstorageobj.c | 2 +-
src/libvirt_private.syms | 2 +-
src/util/virfile.c | 18 ------------------
src/util/virfile.h | 3 ---
src/util/virstring.c | 18 ++++++++++++++++++
src/util/virstring.h | 2 ++
tests/testutilsqemu.c | 2 +-
11 files changed, 28 insertions(+), 29 deletions(-)
diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c
index 0e943d0a6c..7742de94f2 100644
--- a/src/conf/virdomainobjlist.c
+++ b/src/conf/virdomainobjlist.c
@@ -597,7 +597,7 @@ virDomainObjListLoadAllConfigs(virDomainObjListPtr doms,
while ((ret = virDirRead(dir, &entry, configDir)) > 0) {
virDomainObjPtr dom;
- if (!virFileStripSuffix(entry->d_name, ".xml"))
+ if (!virStringStripSuffix(entry->d_name, ".xml"))
continue;
/* NB: ignoring errors, so one malformed config doesn't
diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c
index ae1264325a..c9336e0472 100644
--- a/src/conf/virnetworkobj.c
+++ b/src/conf/virnetworkobj.c
@@ -1068,7 +1068,7 @@ virNetworkObjLoadAllState(virNetworkObjListPtr nets,
while ((ret = virDirRead(dir, &entry, stateDir)) > 0) {
virNetworkObjPtr obj;
- if (!virFileStripSuffix(entry->d_name, ".xml"))
+ if (!virStringStripSuffix(entry->d_name, ".xml"))
continue;
obj = virNetworkLoadState(nets, stateDir, entry->d_name);
@@ -1096,7 +1096,7 @@ virNetworkObjLoadAllConfigs(virNetworkObjListPtr nets,
while ((ret = virDirRead(dir, &entry, configDir)) > 0) {
virNetworkObjPtr obj;
- if (!virFileStripSuffix(entry->d_name, ".xml"))
+ if (!virStringStripSuffix(entry->d_name, ".xml"))
continue;
/* NB: ignoring errors, so one malformed config doesn't
diff --git a/src/conf/virnwfilterbindingobjlist.c b/src/conf/virnwfilterbindingobjlist.c
index 887c7c7b09..06ccbf53af 100644
--- a/src/conf/virnwfilterbindingobjlist.c
+++ b/src/conf/virnwfilterbindingobjlist.c
@@ -304,7 +304,7 @@ virNWFilterBindingObjListLoadAllConfigs(virNWFilterBindingObjListPtr
bindings,
while ((ret = virDirRead(dir, &entry, configDir)) > 0) {
virNWFilterBindingObjPtr binding;
- if (!virFileStripSuffix(entry->d_name, ".xml"))
+ if (!virStringStripSuffix(entry->d_name, ".xml"))
continue;
/* NB: ignoring errors, so one malformed config doesn't
diff --git a/src/conf/virnwfilterobj.c b/src/conf/virnwfilterobj.c
index 0136a0d56c..d2d957a1cc 100644
--- a/src/conf/virnwfilterobj.c
+++ b/src/conf/virnwfilterobj.c
@@ -547,7 +547,7 @@ virNWFilterObjListLoadAllConfigs(virNWFilterObjListPtr nwfilters,
while ((ret = virDirRead(dir, &entry, configDir)) > 0) {
virNWFilterObjPtr obj;
- if (!virFileStripSuffix(entry->d_name, ".xml"))
+ if (!virStringStripSuffix(entry->d_name, ".xml"))
continue;
obj = virNWFilterObjListLoadConfig(nwfilters, configDir, entry->d_name);
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c
index 68c89bd9a9..85b6dd3695 100644
--- a/src/conf/virstorageobj.c
+++ b/src/conf/virstorageobj.c
@@ -1688,7 +1688,7 @@ virStoragePoolObjLoadAllState(virStoragePoolObjListPtr pools,
while ((ret = virDirRead(dir, &entry, stateDir)) > 0) {
virStoragePoolObjPtr obj;
- if (!virFileStripSuffix(entry->d_name, ".xml"))
+ if (!virStringStripSuffix(entry->d_name, ".xml"))
continue;
if (!(obj = virStoragePoolObjLoadState(pools, stateDir, entry->d_name)))
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index e4ed1def33..f94a8fdc3d 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1882,7 +1882,6 @@ virFileSetACLs;
virFileSetupDev;
virFileSetXAttr;
virFileSkipRoot;
-virFileStripSuffix;
virFileTouch;
virFileUnlock;
virFileUpdatePerm;
@@ -2982,6 +2981,7 @@ virStringSplit;
virStringSplitCount;
virStringStripControlChars;
virStringStripIPv6Brackets;
+virStringStripSuffix;
virStringToUpper;
virStringTrimOptionalNewline;
virStrncpy;
diff --git a/src/util/virfile.c b/src/util/virfile.c
index 21f7dc1ac3..c0f3f56293 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -1044,24 +1044,6 @@ int virFileDeleteTree(const char *dir)
return ret;
}
-int
-virFileStripSuffix(char *str, const char *suffix)
-{
- int len = strlen(str);
- int suffixlen = strlen(suffix);
-
- if (len < suffixlen)
- return 0;
-
- if (STRNEQ(str + len - suffixlen, suffix))
- return 0;
-
- str[len-suffixlen] = '\0';
-
- return 1;
-}
-
-
/* Like read(), but restarts after EINTR. Doesn't play
* nicely with nonblocking FD and EAGAIN, in which case
* you want to use bare read(). Or even use virSocket()
diff --git a/src/util/virfile.h b/src/util/virfile.h
index 5a43d57181..0079e234f8 100644
--- a/src/util/virfile.h
+++ b/src/util/virfile.h
@@ -166,9 +166,6 @@ int virFileMatchesNameSuffix(const char *file,
const char *name,
const char *suffix);
-int virFileStripSuffix(char *str,
- const char *suffix) ATTRIBUTE_RETURN_CHECK;
-
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 399b9468e6..60b4167af4 100644
--- a/src/util/virstring.c
+++ b/src/util/virstring.c
@@ -1248,6 +1248,24 @@ virStringHasCaseSuffix(const char *str,
return STRCASEEQ(str + len - suffixlen, suffix);
}
+int
+virStringStripSuffix(char *str,
+ const char *suffix)
+{
+ int len = strlen(str);
+ int suffixlen = strlen(suffix);
+
+ if (len < suffixlen)
+ return 0;
+
+ if (STRNEQ(str + len - suffixlen, suffix))
+ return 0;
+
+ str[len - suffixlen] = '\0';
+
+ return 1;
+}
+
/**
* virStringStripIPv6Brackets:
* @str: the string to strip
diff --git a/src/util/virstring.h b/src/util/virstring.h
index b2ba97a8d1..580e4da9b9 100644
--- a/src/util/virstring.h
+++ b/src/util/virstring.h
@@ -290,6 +290,8 @@ char *virStringReplace(const char *haystack,
int virStringHasCaseSuffix(const char *str,
const char *suffix);
+int virStringStripSuffix(char *str,
+ const char *suffix) ATTRIBUTE_RETURN_CHECK;
void virStringStripIPv6Brackets(char *str);
bool virStringHasChars(const char *str,
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index 1736bad032..61bf67d5ad 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -834,7 +834,7 @@ testQemuGetLatestCapsForArch(const char *dirname,
if (rc == 0)
continue;
- if (virFileStripSuffix(tmp, fullsuffix) != 1)
+ if (virStringStripSuffix(tmp, fullsuffix) != 1)
continue;
if (virParseVersionString(tmp, &ver, false) < 0) {
--
2.20.1