lavu: Add av_strnstr()

This is a length limited version of strstr()

Signed-off-by: Vladimir Pantelic <vladoman@gmail.com>
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
This commit is contained in:
Vladimir Pantelic
2013-01-24 14:09:48 +00:00
committed by Luca Barbato
parent a84fb6e06f
commit b85a5e87af
5 changed files with 37 additions and 1 deletions

View File

@@ -65,6 +65,20 @@ char *av_stristr(const char *s1, const char *s2)
return NULL;
}
char *av_strnstr(const char *haystack, const char *needle, size_t hay_length)
{
size_t needle_len = strlen(needle);
if (!needle_len)
return haystack;
while (hay_length >= needle_len) {
hay_length--;
if (!memcmp(haystack, needle, needle_len))
return haystack;
haystack++;
}
return NULL;
}
size_t av_strlcpy(char *dst, const char *src, size_t size)
{
size_t len = 0;