-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memmove.c
43 lines (40 loc) · 1.35 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: arepsa <arepsa@student.42porto.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/12 12:41:04 by arepsa #+# #+# */
/* Updated: 2023/04/12 12:44:02 by arepsa ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*copy n size block*/
/*doesn't take NUL char into account*/
/*copies in reverse overlapping blocks (src < dest)*/
void *ft_memmove(void *dest, const void *src, size_t n)
{
size_t i;
if (!src && !dest)
return (0);
if (src < dest)
{
i = n;
while (i > 0)
{
i--;
((unsigned char *)dest)[i] = ((unsigned char *)src)[i];
}
}
else
{
i = 0;
while (i < n)
{
((unsigned char *)dest)[i] = ((unsigned char *)src)[i];
i++;
}
}
return (dest);
}