Skip to content

Commit

Permalink
compat: fix strnstr
Browse files Browse the repository at this point in the history
need to wake up sometimes :/
  • Loading branch information
fcartegnie committed Oct 7, 2015
1 parent a140a68 commit db41ce0
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions compat/strnstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 comments on commit db41ce0

Please sign in to comment.