Skip to content
Snippets Groups Projects
Commit db41ce0a authored by François Cartegnie's avatar François Cartegnie :fingers_crossed:
Browse files

compat: fix strnstr

need to wake up sometimes :/
parent a140a685
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment