X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fstr%2Fstr.h;h=770a40fd1f4dca3fe599cfdee109fe9fa581b861;hp=8cfd7f29a5626cb7ca3a3196e545f35c3a74c0be;hb=053f9398c5959d070b7092653ec8f222200ab463;hpb=d4929b8d2c8fc18ab16d2ef2bf7af11e87dac36d diff --git a/ccan/str/str.h b/ccan/str/str.h index 8cfd7f29..770a40fd 100644 --- a/ccan/str/str.h +++ b/ccan/str/str.h @@ -55,4 +55,16 @@ static inline bool strends(const char *str, const char *postfix) #define stringify(expr) stringify_1(expr) /* Double-indirection required to stringify expansions */ #define stringify_1(expr) #expr + +/** + * strcount - Count number of (non-overlapping) occurrences of a substring. + * @haystack: a C string + * @needle: a substring + * + * Example: + * #define PRINT_COND_IF_FALSE(cond) \ + * ((cond) || printf("%s is false!", stringify(cond))) + */ +size_t strcount(const char *haystack, const char *needle); + #endif /* CCAN_STR_H */