Fix handling of one case, should be a good memmem() now.

git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@517 a31d4220-a93d-0410-bf67-fe4944624d44
This commit is contained in:
n-a-c-h 2008-05-20 01:54:20 +00:00
parent 4e8ab56781
commit 87fbce804c
1 changed files with 13 additions and 6 deletions

View File

@ -8,18 +8,25 @@
static uint8_t *memmem(const uint8_t *haystack, size_t haystacklen, const uint8_t *needle, size_t needlelen) static uint8_t *memmem(const uint8_t *haystack, size_t haystacklen, const uint8_t *needle, size_t needlelen)
{ {
if (needlelen <= haystacklen) if (needlelen)
{ {
haystacklen -= needlelen-1; if (needlelen <= haystacklen)
while (haystacklen--)
{ {
if (!memcmp(haystack, needle, needlelen)) haystacklen -= needlelen-1;
while (haystacklen--)
{ {
return((uint8_t *)haystack); if (!memcmp(haystack, needle, needlelen))
{
return((uint8_t *)haystack);
}
++haystack;
} }
++haystack;
} }
} }
else
{
return((uint8_t *)haystack);
}
return(0); return(0);
} }