shl: misc: add shl_ends_with() helper

This helper checks whether a string has the given suffix.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
David Herrmann 2012-12-30 19:41:08 +01:00
parent 0ec995601b
commit d96934c4a5

View File

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