libft/memory/ft_memmove.c

60 lines
1.6 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 16:51:35 by rparodi #+# #+# */
/* Updated: 2024/10/31 18:15:19 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_checks(char *s, char *d, size_t n)
{
size_t i;
i = 0;
if (d < s)
{
while (i < n)
{
d[i] = s[i];
i++;
}
}
else
{
i = n;
while (i > 0)
{
i--;
d[i] = s[i];
}
}
return (d);
}
/**
* @brief Copies memory with overlap handling
*
* @param dest Pointer to the destination memory area
* @param src Pointer to the source memory area
* @param n Number of bytes to copy from src to dest
*
* @return A pointer to the destination memory area dest
*/
void *ft_memmove(void *dest, const void *src, size_t n)
{
char *d;
char *s;
if (!dest && !src)
return (NULL);
d = (char *)dest;
s = (char *)src;
ft_checks(s, d, n);
return (dest);
}