feat: added memchr, memcmp, memmv and realloc

This commit is contained in:
Zoëy Noort 2025-05-31 19:37:00 +02:00
parent 3287cd402f
commit 0f35f48c25
4 changed files with 129 additions and 0 deletions

28
srcs/ft_memcmp.c Normal file
View file

@ -0,0 +1,28 @@
#include <stddef.h>
#include <stdint.h>
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
const unsigned char *p1 = s1, *p2 = s2;
while (n >= sizeof(size_t)) {
size_t w1 = *(const size_t *)p1;
size_t w2 = *(const size_t *)p2;
if (w1 != w2) {
for (size_t i = 0; i < sizeof(size_t); ++i) {
if (p1[i] != p2[i])
return (p1[i] - p2[i]);
}
}
p1 += sizeof(size_t);
p2 += sizeof(size_t);
n -= sizeof(size_t);
}
while (n--) {
if (*p1 != *p2)
return (*p1 - *p2);
++p1;
++p2;
}
return (0);
}