axl_memcmp

This commit is contained in:
NukeBird 2025-11-27 20:42:39 +03:00
parent 9e9901a3bb
commit 574edcd4c5
3 changed files with 19 additions and 0 deletions

View file

@ -194,6 +194,22 @@ void* axl_realloc(void* ptr, u32 size)
return new;
}
i32 axl_memcmp(const void* s1, const void* s2, u32 n)
{
const u8* a = (u8*)s1;
const u8* b = (u8*)s2;
for(u32 i = 0; i < n; i++)
{
if(a[i] != b[i])
{
return a[i] - b[i]; //checked: will do negative values too
}
}
return 0;
}
void axl_free(void* ptr)
{
if(!ptr)

View file

@ -12,6 +12,7 @@ void* axl_malloc(u32 size);
void* axl_realloc(void* ptr, u32 size);
void* axl_memset(void* ptr, i8 c, u32 n);
void* axl_memcpy(void* dst, const void* src, u32 count);
i32 axl_memcmp(const void* s1, const void* s2, u32 n);
void axl_free(void* ptr);
#endif

2
main.c
View file

@ -8,6 +8,8 @@ int _start(void)
int* f = axl_malloc(sizeof(int));
*f = 4;
*(int*)(fds) = 4;
(void)axl_memcmp(f, fds, 4);
axl_free(fds);
axl_free(f);