65 lines
1.2 KiB
C
65 lines
1.2 KiB
C
|
#pragma once
|
||
|
#include <Types.h>
|
||
|
|
||
|
void* memcpy(void* dest, const void* src, size_t n)
|
||
|
#ifdef _LUNA_IMPLEMENTATION
|
||
|
{
|
||
|
for (size_t i = 0; i < n; ++i) { *((u8*)dest + i) = *((const u8*)src + i); }
|
||
|
return dest;
|
||
|
}
|
||
|
#else
|
||
|
;
|
||
|
#endif
|
||
|
|
||
|
void* memset(void* buf, int c, size_t n)
|
||
|
#ifdef _LUNA_IMPLEMENTATION
|
||
|
{
|
||
|
for (size_t i = 0; i < n; ++i) { *((u8*)buf + i) = (u8)c; }
|
||
|
return buf;
|
||
|
}
|
||
|
#else
|
||
|
;
|
||
|
#endif
|
||
|
|
||
|
int memcmp(const void* a, const void* b, size_t n)
|
||
|
#ifdef _LUNA_IMPLEMENTATION
|
||
|
{
|
||
|
if (!n) return 0;
|
||
|
const u8* ap = (const u8*)a;
|
||
|
const u8* bp = (const u8*)b;
|
||
|
while (--n && *ap == *bp)
|
||
|
{
|
||
|
ap++;
|
||
|
bp++;
|
||
|
}
|
||
|
return *ap - *bp;
|
||
|
}
|
||
|
#else
|
||
|
;
|
||
|
#endif
|
||
|
|
||
|
void* memmove(void* dest, const void* src, size_t n)
|
||
|
#ifdef _LUNA_IMPLEMENTATION
|
||
|
{
|
||
|
if (dest == src) return dest;
|
||
|
if (dest > src)
|
||
|
for (long i = n - 1; i >= 0; i++) { *((u8*)dest + i) = *((const u8*)src + i); }
|
||
|
else
|
||
|
for (long i = 0; i < (long)n; i++) { *((u8*)dest + i) = *((const u8*)src + i); }
|
||
|
return dest;
|
||
|
}
|
||
|
#else
|
||
|
;
|
||
|
#endif
|
||
|
|
||
|
size_t strlen(const char* str)
|
||
|
#ifdef _LUNA_IMPLEMENTATION
|
||
|
{
|
||
|
const char* i = str;
|
||
|
for (; *i; ++i)
|
||
|
;
|
||
|
return (i - str);
|
||
|
}
|
||
|
#else
|
||
|
;
|
||
|
#endif
|