diff --git a/ft_memmove.c b/ft_memmove.c new file mode 100644 index 0000000..a0e3a60 --- /dev/null +++ b/ft_memmove.c @@ -0,0 +1,18 @@ +#include "libft.h" + +void *ft_memmove(void *dst, const void *src, size_t len) +{ + if (dst <= src) + { + ft_memcpy(dst, src, len); + } + else + { + while (len > 0) + { + len--; + ((char *)dst)[len] = ((char *)src)[len]; + } + } + return (dst); +} diff --git a/libft.h b/libft.h index 0e72e0f..4eea45d 100644 --- a/libft.h +++ b/libft.h @@ -71,4 +71,13 @@ void ft_bzero(void *s, size_t n); */ void *ft_memcpy(void *dst, const void *src, size_t n); +/* + The memmove() function copies len + bytes from string src to string dst. + The two strings may overlap; the + copy is always done in a non-destructive + manner. +*/ +void *ft_memmove(void *dst, const void *src, size_t n); + #endif