shl: misc: add shl_ends_with() helper
authorDavid Herrmann <dh.herrmann@googlemail.com>
Sun, 30 Dec 2012 18:41:08 +0000 (19:41 +0100)
committerDavid Herrmann <dh.herrmann@googlemail.com>
Sun, 30 Dec 2012 18:41:08 +0000 (19:41 +0100)
This helper checks whether a string has the given suffix.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
src/shl_misc.h

index 954bab3..637e3be 100644 (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