]> git.ozlabs.org Git - ccan/blobdiff - ccan/mem/mem.h
mem: add memends_str() helper for symmetry
[ccan] / ccan / mem / mem.h
index 8d6bba943c8eab31243cadfdec3998cc1ed809f2..1afe508b3a097beefdbf93660165c7146fdb3f25 100644 (file)
@@ -183,4 +183,21 @@ static inline bool memends(const void *s, size_t s_len, const void *suffix, size
                                                suffix, suffix_len) == 0);
 }
 
+/**
+ * memends_str - Does this byte array end with a string suffix?
+ * @a: byte array
+ * @al: length in bytes
+ * @s: string suffix
+ *
+ * Example:
+ *     if (memends_str(somebytes, bytes_len, "It")) {
+ *             printf("somebytes ends with with 'It'\n");
+ *     }
+ */
+PURE_FUNCTION
+static inline bool memends_str(const void *a, size_t al, const char *s)
+{
+       return memends(a, al, s, strlen(s));
+}
+
 #endif /* CCAN_MEM_H */