Commit db41ce0a authored by Francois Cartegnie's avatar Francois Cartegnie

compat: fix strnstr

need to wake up sometimes :/
parent a140a685
......@@ -26,18 +26,22 @@
char * strnstr (const char *haystack, const char *needle, size_t len)
{
if(!needle || !*needle)
return (char*)haystack;
const size_t i = strlen(needle);
if( i < len )
if( len < i )
return NULL;
size_t count = len - i;
while(count)
do
{
if( memcmp(haystack, needle, i) )
return (char*) haystack;
count--;
haystack++;
}
while(count--);
return NULL;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment