60 lines
1.6 KiB
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: 2025/09/01 16:41:47 by rparodi ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include <unistd.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);
|
|
}
|