42 lines
1.3 KiB
C
42 lines
1.3 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_memmove.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: rzy <ry@student.42angouleme.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2026/08/23 22:44:14 by rzy #+# #+# */
|
|
/* Updated: 2026/08/23 22:56:01 by rzy ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
#include "libft.h"
|
|
|
|
void *ft_memmove(void *dest, const void *src, size_t n)
|
|
{
|
|
unsigned char *dest_ptr;
|
|
unsigned char *src_ptr;
|
|
int i;
|
|
|
|
dest_ptr = (unsigned char *)dest;
|
|
src_ptr = (unsigned char *)src;
|
|
if (src > dest)
|
|
{
|
|
i = 0;
|
|
while ((size_t)i < n)
|
|
{
|
|
dest_ptr[i] = src_ptr[i];
|
|
++i;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
i = n - 1;
|
|
while (i >= 0)
|
|
{
|
|
dest_ptr[i] = src_ptr[i];
|
|
--i;
|
|
}
|
|
}
|
|
return (dest);
|
|
}
|