ft_strace/libft/ft_memcmp.c

31 lines
1.2 KiB
C
Executable file

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/14 17:39:59 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:04:06 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
const unsigned char *st1;
const unsigned char *st2;
st1 = (const unsigned char *)s1;
st2 = (const unsigned char *)s2;
while (n && (*st1 == *st2))
{
st1++;
st2++;
n--;
}
if (n == 0)
return (0);
return (*st1 - *st2);
}