From d96934c4a5a18a3530f0565a6a71c166130579fb Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Sun, 30 Dec 2012 19:41:08 +0100 Subject: [PATCH] shl: misc: add shl_ends_with() helper This helper checks whether a string has the given suffix. Signed-off-by: David Herrmann --- src/shl_misc.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/shl_misc.h b/src/shl_misc.h index 954bab3..637e3be 100644 --- a/src/shl_misc.h +++ b/src/shl_misc.h @@ -95,6 +95,19 @@ static inline int shl_dup(void **out, const void *data, size_t size) return 0; } +static inline bool shl_ends_with(const char *str, const char *suffix) +{ + size_t len, slen; + + len = strlen(str); + slen = strlen(suffix); + + if (len < slen) + return false; + + return !memcmp(str + len - slen, suffix, slen); +} + /* This parses \arg and splits the string into a new allocated array. The array * is stored in \out and is NULL terminated. Empty entries are removed from the * array if \keep_empty is false. \out_num is the number of entries in the