From 6daa8ef078bd8a7ccf1d383cc76a84abc3e91ca7 Mon Sep 17 00:00:00 2001 From: Reece Wilson Date: Sun, 4 Sep 2022 04:13:16 +0100 Subject: [PATCH] [+] AuMemmem (bc it was copy/pasted twice around the two different codebases and MSVC doesnt have a native memmem routine) --- Include/auROXTL/auMemoryUtils.hpp | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/Include/auROXTL/auMemoryUtils.hpp b/Include/auROXTL/auMemoryUtils.hpp index fe65e38..760d963 100644 --- a/Include/auROXTL/auMemoryUtils.hpp +++ b/Include/auROXTL/auMemoryUtils.hpp @@ -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 } \ No newline at end of file