mirror of
https://github.com/guezoloic/libft.git
synced 2026-01-25 00:34:15 +00:00
feat: add ft_memmove function
memmove: if the src pointer is higher than the dst pointer, the function copies each caracter backwards.
This commit is contained in:
18
ft_memmove.c
Normal file
18
ft_memmove.c
Normal file
@@ -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);
|
||||
}
|
||||
9
libft.h
9
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
|
||||
|
||||
Reference in New Issue
Block a user