ft_memcmp - gabrielcoelhodacunha-old/42sp-libft GitHub Wiki
Description
Compares len
bytes of b1
and b2
.
Implementation
int ft_memcmp(const void *b1, const void *b2, size_t len)
{
size_t idx;
const unsigned char *s1;
const unsigned char *s2;
idx = -1;
s1 = b1;
s2 = b2;
while (++idx < len)
if (s1[idx] != s2[idx])
/* Possible returns:
1. positive value: `s1` is greater than `s2`
2. negative value: `s1` is lesser than `s2`
*/
return (s1[idx] - s2[idx]);
// Returns that `s1` is equal to `s2`
return (0);
}