util: Rename virFileStripSuffix() to virStringStripSuffix()

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@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Andrea Bolognani 2019-03-06 15:30:04 +01:00
parent 2de7dcba7e
commit 9c5fa79fd7
11 changed files with 28 additions and 29 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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)))

View File

@ -1890,7 +1890,6 @@ virFileSetACLs;
virFileSetupDev;
virFileSetXAttr;
virFileSkipRoot;
virFileStripSuffix;
virFileTouch;
virFileUnlock;
virFileUpdatePerm;
@ -2990,6 +2989,7 @@ virStringSplit;
virStringSplitCount;
virStringStripControlChars;
virStringStripIPv6Brackets;
virStringStripSuffix;
virStringToUpper;
virStringTrimOptionalNewline;
virStrncpy;

View File

@ -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()

View File

@ -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);

View File

@ -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

View File

@ -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,

View File

@ -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) {