From d93b9e88293c95220078bcb5db930261c1b7a333 Mon Sep 17 00:00:00 2001 From: Andrea Bolognani Date: Wed, 6 Mar 2019 17:05:03 +0100 Subject: [PATCH] util: Add virStringHasSuffix() This is the case-sensitive counterpart of the existing virStringHasCaseSuffix() function. Signed-off-by: Andrea Bolognani ACKed-by: Peter Krempa --- src/libvirt_private.syms | 1 + src/util/virstring.c | 13 +++++++++++++ src/util/virstring.h | 2 ++ 3 files changed, 16 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b20100b30b..d2a240fc7a 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2966,6 +2966,7 @@ virStringFilterChars; virStringHasCaseSuffix; virStringHasChars; virStringHasControlChars; +virStringHasSuffix; virStringIsEmpty; virStringIsPrintable; virStringListAdd; diff --git a/src/util/virstring.c b/src/util/virstring.c index b4d10f9884..cf3d9c6f03 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -1235,6 +1235,19 @@ virStringReplace(const char *haystack, return virBufferContentAndReset(&buf); } +bool +virStringHasSuffix(const char *str, + const char *suffix) +{ + int len = strlen(str); + int suffixlen = strlen(suffix); + + if (len < suffixlen) + return false; + + 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..5b127cdba4 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); +bool virStringHasSuffix(const char *str, + const char *suffix); int virStringHasCaseSuffix(const char *str, const char *suffix); int virStringStripSuffix(char *str, -- GitLab