42_libft/ft_memmove.c

38 lines
1.2 KiB
C
Raw Normal View History

2022-09-27 10:29:23 -04:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/27 11:44:12 by cchauvet #+# #+# */
2022-10-04 08:21:55 -04:00
/* Updated: 2022/09/28 16:40:24 by cchauvet ### ########.fr */
2022-09-27 10:29:23 -04:00
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memmove(void *dest, const void *src, size_t n)
{
size_t i;
char *tab1;
char *tab2;
2022-10-04 08:21:55 -04:00
if (dest == NULL && src == NULL)
return (dest);
2022-09-27 10:29:23 -04:00
tab1 = dest;
tab2 = (void *) src;
if (tab1 < tab2)
ft_memcpy(dest, src, n);
else
{
i = n;
while (0 < i)
{
i--;
tab1[i] = tab2[i];
}
}
return (dest);
}