[+] AuMemmem (bc it was copy/pasted twice around the two different codebases and MSVC doesnt have a native memmem routine)

This commit is contained in:
Reece Wilson 2022-09-04 04:13:16 +01:00
parent af438c8c17
commit 6daa8ef078

View File

@ -44,4 +44,44 @@ static auline void *AuMemcpy(void *dest, const void *src, size_t n)
static auline void *AuMemmove(void *dest, const void *src, size_t n)
{
return AURORA_RUNTIME_MEMMOVE(dest, src, n);
}
static auline void *AuMemmem(const void *haystack, size_t haystackLen,
const void *const needle, const size_t needleLen)
{
#if defined(AURORA_IS_LINUX_DERIVED)
return ::memmem(haystack, heystackLen, needle, needleLen);
#else
if (!haystack)
{
return {};
}
if (!haystackLen)
{
return {};
}
if (!needle)
{
return {};
}
if (!needleLen)
{
return {};
}
for (const char *h = (const char *)haystack;
haystackLen >= needleLen;
++h, --haystackLen)
{
if (!AuMemcmp(h, needle, needleLen))
{
return (void *)h;
}
}
return {};
#endif
}