]> git.ozlabs.org Git - ccan/blobdiff - ccan/str/str.c
str: strcount
[ccan] / ccan / str / str.c
diff --git a/ccan/str/str.c b/ccan/str/str.c
new file mode 100644 (file)
index 0000000..fa9809f
--- /dev/null
@@ -0,0 +1,12 @@
+#include <ccan/str/str.h>
+
+size_t strcount(const char *haystack, const char *needle)
+{
+       size_t i = 0, nlen = strlen(needle);
+
+       while ((haystack = strstr(haystack, needle)) != NULL) {
+               i++;
+               haystack += nlen;
+       }
+       return i;
+}