-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memmove.c
38 lines (34 loc) · 1.38 KB
/
ft_memmove.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mlindenm <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/24 18:12:57 by mlindenm #+# #+# */
/* Updated: 2023/10/19 17:41:38 by mlindenm ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*This C function ft_memmove copies n bytes of data from the source src to the
destination dest, handling overlapping memory regions correctly.*/
void *ft_memmove(void *dest, const void *src, size_t n)
{
size_t i;
char *ptr_dest;
char *ptr_src;
i = 0;
if (dest == src)
return (dest);
ptr_dest = (char *)dest;
ptr_src = (char *)src;
while (i < n)
{
if ((void *)dest > (void *)src)
ptr_dest[n - i - 1] = ptr_src[n - i - 1];
else
ptr_dest[i] = ptr_src[i];
i++;
}
return (dest);
}