/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_memmove.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 13:57:12 by kcolin #+# #+# */ /* Updated: 2024/10/15 14:12:15 by kcolin ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" /* * case 1: dst overlaps at start of src. * src is before dst. * copy back to front * * case 2: dst overlaps at beginning of src. * src is after dst. * copy front to back. * * case 3: dst and src do not overlap * it doesn't matter how the data is copied * merge with case 2 */ void *ft_memmove(void *dst, const void *src, t_size len) { t_size i; if (dst >= src && dst <= (src + len)) { i = len; while (i > 0) { i--; ((char *)dst)[i] = ((char *)src)[i]; } } else { ft_memcpy(dst, src, len); } return (dst); }