X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fbytestring%2Fbytestring.h;fp=ccan%2Fbytestring%2Fbytestring.h;h=62141bea41149a30bd61214e8804d50c23e4c971;hp=042b1843220192bd1c4d2614cdd75df303812bc0;hb=f1e31c66572ef5997e08a1ecadf2e45b2fb04532;hpb=d584928758cb995a60e8264b73da46bcd8c410ca diff --git a/ccan/bytestring/bytestring.h b/ccan/bytestring/bytestring.h index 042b1843..62141bea 100644 --- a/ccan/bytestring/bytestring.h +++ b/ccan/bytestring/bytestring.h @@ -181,4 +181,23 @@ static inline const char *bytestring_rindex(struct bytestring haystack, return memrchr(haystack.ptr, needle, haystack.len); } +/* + * bytestring_bytestring - search for a bytestring in another bytestring + * @haystack, @needle: bytestrings + * + * Returns a bytestring corresponding to the first occurrence of + * @needle in @haystack, or bytestring_NULL if @needle is not found + * within @haystack. + */ +static inline struct bytestring bytestring_bytestring(struct bytestring haystack, + struct bytestring needle) +{ + const char *p = memmem(haystack.ptr, haystack.len, + needle.ptr, needle.len); + if (p) + return bytestring(p, needle.len); + else + return bytestring_NULL; +} + #endif /* CCAN_BYTESTRING_H_ */