libft/memory/ft_memmove.c
Raphael 42a2efb059
refactor: make ft_checks function static
BREAKING CHANGE: function my_function is no longer exported
2025-09-04 12:01:38 +02:00

60 lines
1.6 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 16:51:35 by rparodi #+# #+# */
/* Updated: 2025/09/04 11:56:02 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
static 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);
}