This is the case-sensitive counterpart of the existing
virStringHasCaseSuffix() function.
Signed-off-by: Andrea Bolognani <abologna(a)redhat.com>
---
src/util/virstring.c | 13 +++++++++++++
src/util/virstring.h | 2 ++
2 files changed, 15 insertions(+)
diff --git a/src/util/virstring.c b/src/util/virstring.c
index b4d10f9884..b9b33e3d1a 100644
--- a/src/util/virstring.c
+++ b/src/util/virstring.c
@@ -1235,6 +1235,19 @@ virStringReplace(const char *haystack,
return virBufferContentAndReset(&buf);
}
+int
+virStringHasSuffix(const char *str,
+ const char *suffix)
+{
+ int len = strlen(str);
+ int suffixlen = strlen(suffix);
+
+ if (len < suffixlen)
+ return 0;
+
+ return STREQ(str + len - suffixlen, suffix);
+}
+
int
virStringHasCaseSuffix(const char *str,
const char *suffix)
diff --git a/src/util/virstring.h b/src/util/virstring.h
index 69030566e9..dff21d9cf1 100644
--- a/src/util/virstring.h
+++ b/src/util/virstring.h
@@ -288,6 +288,8 @@ char *virStringReplace(const char *haystack,
const char *newneedle)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
+int virStringHasSuffix(const char *str,
+ const char *suffix);
int virStringHasCaseSuffix(const char *str,
const char *suffix);
int virStringStripSuffix(char *str,
--
2.20.1