feat: added memchr, memcmp, memmv and realloc
This commit is contained in:
parent
3287cd402f
commit
0f35f48c25
4 changed files with 129 additions and 0 deletions
28
srcs/ft_memcmp.c
Normal file
28
srcs/ft_memcmp.c
Normal 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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue