-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memmove.c
46 lines (43 loc) · 1.57 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
39
40
41
42
43
44
45
46
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: crea <crea@student.42roma.it> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/15 16:57:52 by crea #+# #+# */
/* Updated: 2024/02/05 14:42:07 by crea ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/* ft_memmove:
** Moves 'len' bytes from memory area 'src' to memory area 'dest'.
** Handles overlapping regions by copying from the end if 'dest' overlaps 'src'.
** If either 'dest' or 'src' is NULL, returns NULL.
** Returns a pointer to 'dest'.
*/
void *ft_memmove(void *dest, const void *src, size_t len)
{
size_t i;
if (!dest && !src)
return (0);
i = 0;
if (((size_t)dest - (size_t)src < len))
{
i = len -1;
while (i < len)
{
*(unsigned char *)(dest + i) = *(unsigned char *)(src + i);
i--;
}
}
else
{
while (i < len)
{
*(unsigned char *)(dest + i) = *(unsigned char *)(src + i);
i++;
}
}
return (dest);
}