2022-04-01 04:06:53 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: auMemoryUtils.hpp
|
|
|
|
Date: 2022-2-1
|
|
|
|
File: AuroraUtils.hpp
|
|
|
|
File: auROXTLUtils.hpp
|
|
|
|
Date: 2021-6-9
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#if !defined(AURORA_RUNTIME_MEMCMP)
|
|
|
|
#define AURORA_RUNTIME_MEMCMP std::memcmp
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static auline int AuMemcmp(const void *dest, const void *src, size_t n)
|
|
|
|
{
|
|
|
|
return AURORA_RUNTIME_MEMCMP(dest, src, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if !defined(AURORA_RUNTIME_MEMSET)
|
|
|
|
#define AURORA_RUNTIME_MEMSET std::memset
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static auline void *AuMemset(void *dest, AuUInt8 c, size_t n)
|
|
|
|
{
|
|
|
|
return AURORA_RUNTIME_MEMSET(dest, c, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if !defined(AURORA_RUNTIME_MEMCPY)
|
|
|
|
#define AURORA_RUNTIME_MEMCPY std::memcpy
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static auline void *AuMemcpy(void *dest, const void *src, size_t n)
|
|
|
|
{
|
|
|
|
return AURORA_RUNTIME_MEMCPY(dest, src, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if !defined(AURORA_RUNTIME_MEMMOVE)
|
|
|
|
#define AURORA_RUNTIME_MEMMOVE std::memmove
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static auline void *AuMemmove(void *dest, const void *src, size_t n)
|
|
|
|
{
|
|
|
|
return AURORA_RUNTIME_MEMMOVE(dest, src, n);
|
2022-09-04 03:13:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static auline void *AuMemmem(const void *haystack, size_t haystackLen,
|
|
|
|
const void *const needle, const size_t needleLen)
|
|
|
|
{
|
|
|
|
#if defined(AURORA_IS_LINUX_DERIVED)
|
2022-09-04 05:54:58 +00:00
|
|
|
return ::memmem(haystack, haystackLen, needle, needleLen);
|
2022-09-04 03:13:16 +00:00
|
|
|
#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
|
2022-04-01 04:06:53 +00:00
|
|
|
}
|