-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memmove.c
44 lines (41 loc) · 1.49 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ldulling <ldulling@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/24 16:08:23 by ldulling #+# #+# */
/* Updated: 2023/09/25 16:10:29 by ldulling ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/* Checks if dest is before or after src in memory,
** then starts copying from the beginning or the end respectively */
void *ft_memmove(void *dest, const void *src, size_t n)
{
unsigned char *casted_ptr_dest;
unsigned char *casted_ptr_src;
size_t i;
if (dest || src)
{
casted_ptr_dest = (unsigned char *) dest;
casted_ptr_src = (unsigned char *) src;
if (casted_ptr_dest <= casted_ptr_src)
{
i = 0;
while (i < n)
{
casted_ptr_dest[i] = casted_ptr_src[i];
i++;
}
}
else
{
i = n;
while (i-- > 0)
casted_ptr_dest[i] = casted_ptr_src[i];
}
}
return (dest);
}