40 lines
1.3 KiB
C
40 lines
1.3 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_memmove.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2020/10/27 22:19:34 by pbonilla #+# #+# */
|
|
/* Updated: 2021/01/29 13:08:14 by pbonilla ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
void *ft_memmove(void *dest, const void *src, size_t n)
|
|
{
|
|
unsigned char *dest2;
|
|
unsigned char *src2;
|
|
unsigned int i;
|
|
|
|
dest2 = (unsigned char *)dest;
|
|
src2 = (unsigned char *)src;
|
|
i = -1;
|
|
if (!dest2 && !src2)
|
|
return (dest2);
|
|
if (src >= dest)
|
|
{
|
|
while (++i != n)
|
|
*(dest2 + i) = *(src2 + i);
|
|
}
|
|
else
|
|
{
|
|
src2 += n;
|
|
dest2 += n;
|
|
while (n--)
|
|
*--dest2 = *--src2;
|
|
}
|
|
return (dest2);
|
|
}
|