提交 9c5fa79f 编写于 作者: A Andrea Bolognani

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: NAndrea Bolognani <abologna@redhat.com>
ACKed-by: NPeter Krempa <pkrempa@redhat.com>
上级 2de7dcba
...@@ -597,7 +597,7 @@ virDomainObjListLoadAllConfigs(virDomainObjListPtr doms, ...@@ -597,7 +597,7 @@ virDomainObjListLoadAllConfigs(virDomainObjListPtr doms,
while ((ret = virDirRead(dir, &entry, configDir)) > 0) { while ((ret = virDirRead(dir, &entry, configDir)) > 0) {
virDomainObjPtr dom; virDomainObjPtr dom;
if (!virFileStripSuffix(entry->d_name, ".xml")) if (!virStringStripSuffix(entry->d_name, ".xml"))
continue; continue;
/* NB: ignoring errors, so one malformed config doesn't /* NB: ignoring errors, so one malformed config doesn't
......
...@@ -1068,7 +1068,7 @@ virNetworkObjLoadAllState(virNetworkObjListPtr nets, ...@@ -1068,7 +1068,7 @@ virNetworkObjLoadAllState(virNetworkObjListPtr nets,
while ((ret = virDirRead(dir, &entry, stateDir)) > 0) { while ((ret = virDirRead(dir, &entry, stateDir)) > 0) {
virNetworkObjPtr obj; virNetworkObjPtr obj;
if (!virFileStripSuffix(entry->d_name, ".xml")) if (!virStringStripSuffix(entry->d_name, ".xml"))
continue; continue;
obj = virNetworkLoadState(nets, stateDir, entry->d_name); obj = virNetworkLoadState(nets, stateDir, entry->d_name);
...@@ -1096,7 +1096,7 @@ virNetworkObjLoadAllConfigs(virNetworkObjListPtr nets, ...@@ -1096,7 +1096,7 @@ virNetworkObjLoadAllConfigs(virNetworkObjListPtr nets,
while ((ret = virDirRead(dir, &entry, configDir)) > 0) { while ((ret = virDirRead(dir, &entry, configDir)) > 0) {
virNetworkObjPtr obj; virNetworkObjPtr obj;
if (!virFileStripSuffix(entry->d_name, ".xml")) if (!virStringStripSuffix(entry->d_name, ".xml"))
continue; continue;
/* NB: ignoring errors, so one malformed config doesn't /* NB: ignoring errors, so one malformed config doesn't
......
...@@ -304,7 +304,7 @@ virNWFilterBindingObjListLoadAllConfigs(virNWFilterBindingObjListPtr bindings, ...@@ -304,7 +304,7 @@ virNWFilterBindingObjListLoadAllConfigs(virNWFilterBindingObjListPtr bindings,
while ((ret = virDirRead(dir, &entry, configDir)) > 0) { while ((ret = virDirRead(dir, &entry, configDir)) > 0) {
virNWFilterBindingObjPtr binding; virNWFilterBindingObjPtr binding;
if (!virFileStripSuffix(entry->d_name, ".xml")) if (!virStringStripSuffix(entry->d_name, ".xml"))
continue; continue;
/* NB: ignoring errors, so one malformed config doesn't /* NB: ignoring errors, so one malformed config doesn't
......
...@@ -547,7 +547,7 @@ virNWFilterObjListLoadAllConfigs(virNWFilterObjListPtr nwfilters, ...@@ -547,7 +547,7 @@ virNWFilterObjListLoadAllConfigs(virNWFilterObjListPtr nwfilters,
while ((ret = virDirRead(dir, &entry, configDir)) > 0) { while ((ret = virDirRead(dir, &entry, configDir)) > 0) {
virNWFilterObjPtr obj; virNWFilterObjPtr obj;
if (!virFileStripSuffix(entry->d_name, ".xml")) if (!virStringStripSuffix(entry->d_name, ".xml"))
continue; continue;
obj = virNWFilterObjListLoadConfig(nwfilters, configDir, entry->d_name); obj = virNWFilterObjListLoadConfig(nwfilters, configDir, entry->d_name);
......
...@@ -1688,7 +1688,7 @@ virStoragePoolObjLoadAllState(virStoragePoolObjListPtr pools, ...@@ -1688,7 +1688,7 @@ virStoragePoolObjLoadAllState(virStoragePoolObjListPtr pools,
while ((ret = virDirRead(dir, &entry, stateDir)) > 0) { while ((ret = virDirRead(dir, &entry, stateDir)) > 0) {
virStoragePoolObjPtr obj; virStoragePoolObjPtr obj;
if (!virFileStripSuffix(entry->d_name, ".xml")) if (!virStringStripSuffix(entry->d_name, ".xml"))
continue; continue;
if (!(obj = virStoragePoolObjLoadState(pools, stateDir, entry->d_name))) if (!(obj = virStoragePoolObjLoadState(pools, stateDir, entry->d_name)))
......
...@@ -1890,7 +1890,6 @@ virFileSetACLs; ...@@ -1890,7 +1890,6 @@ virFileSetACLs;
virFileSetupDev; virFileSetupDev;
virFileSetXAttr; virFileSetXAttr;
virFileSkipRoot; virFileSkipRoot;
virFileStripSuffix;
virFileTouch; virFileTouch;
virFileUnlock; virFileUnlock;
virFileUpdatePerm; virFileUpdatePerm;
...@@ -2990,6 +2989,7 @@ virStringSplit; ...@@ -2990,6 +2989,7 @@ virStringSplit;
virStringSplitCount; virStringSplitCount;
virStringStripControlChars; virStringStripControlChars;
virStringStripIPv6Brackets; virStringStripIPv6Brackets;
virStringStripSuffix;
virStringToUpper; virStringToUpper;
virStringTrimOptionalNewline; virStringTrimOptionalNewline;
virStrncpy; virStrncpy;
......
...@@ -1044,24 +1044,6 @@ int virFileDeleteTree(const char *dir) ...@@ -1044,24 +1044,6 @@ int virFileDeleteTree(const char *dir)
return ret; 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 /* Like read(), but restarts after EINTR. Doesn't play
* nicely with nonblocking FD and EAGAIN, in which case * nicely with nonblocking FD and EAGAIN, in which case
* you want to use bare read(). Or even use virSocket() * you want to use bare read(). Or even use virSocket()
......
...@@ -166,9 +166,6 @@ int virFileMatchesNameSuffix(const char *file, ...@@ -166,9 +166,6 @@ int virFileMatchesNameSuffix(const char *file,
const char *name, const char *name,
const char *suffix); const char *suffix);
int virFileStripSuffix(char *str,
const char *suffix) ATTRIBUTE_RETURN_CHECK;
int virFileLinkPointsTo(const char *checkLink, int virFileLinkPointsTo(const char *checkLink,
const char *checkDest) const char *checkDest)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
......
...@@ -1248,6 +1248,24 @@ virStringHasCaseSuffix(const char *str, ...@@ -1248,6 +1248,24 @@ virStringHasCaseSuffix(const char *str,
return STRCASEEQ(str + len - suffixlen, suffix); 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: * virStringStripIPv6Brackets:
* @str: the string to strip * @str: the string to strip
......
...@@ -290,6 +290,8 @@ char *virStringReplace(const char *haystack, ...@@ -290,6 +290,8 @@ char *virStringReplace(const char *haystack,
int virStringHasCaseSuffix(const char *str, int virStringHasCaseSuffix(const char *str,
const char *suffix); const char *suffix);
int virStringStripSuffix(char *str,
const char *suffix) ATTRIBUTE_RETURN_CHECK;
void virStringStripIPv6Brackets(char *str); void virStringStripIPv6Brackets(char *str);
bool virStringHasChars(const char *str, bool virStringHasChars(const char *str,
......
...@@ -834,7 +834,7 @@ testQemuGetLatestCapsForArch(const char *dirname, ...@@ -834,7 +834,7 @@ testQemuGetLatestCapsForArch(const char *dirname,
if (rc == 0) if (rc == 0)
continue; continue;
if (virFileStripSuffix(tmp, fullsuffix) != 1) if (virStringStripSuffix(tmp, fullsuffix) != 1)
continue; continue;
if (virParseVersionString(tmp, &ver, false) < 0) { if (virParseVersionString(tmp, &ver, false) < 0) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册