axl_memcmp
This commit is contained in:
parent
9e9901a3bb
commit
574edcd4c5
3 changed files with 19 additions and 0 deletions
16
axl_memory.c
16
axl_memory.c
|
|
@ -194,6 +194,22 @@ void* axl_realloc(void* ptr, u32 size)
|
||||||
return new;
|
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)
|
void axl_free(void* ptr)
|
||||||
{
|
{
|
||||||
if(!ptr)
|
if(!ptr)
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ void* axl_malloc(u32 size);
|
||||||
void* axl_realloc(void* ptr, u32 size);
|
void* axl_realloc(void* ptr, u32 size);
|
||||||
void* axl_memset(void* ptr, i8 c, u32 n);
|
void* axl_memset(void* ptr, i8 c, u32 n);
|
||||||
void* axl_memcpy(void* dst, const void* src, u32 count);
|
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);
|
void axl_free(void* ptr);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
2
main.c
2
main.c
|
|
@ -8,6 +8,8 @@ int _start(void)
|
||||||
|
|
||||||
int* f = axl_malloc(sizeof(int));
|
int* f = axl_malloc(sizeof(int));
|
||||||
*f = 4;
|
*f = 4;
|
||||||
|
*(int*)(fds) = 4;
|
||||||
|
(void)axl_memcmp(f, fds, 4);
|
||||||
axl_free(fds);
|
axl_free(fds);
|
||||||
axl_free(f);
|
axl_free(f);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue