-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memmove.c
42 lines (39 loc) · 1.32 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pmaryjo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/09/05 18:41:40 by pmaryjo #+# #+# */
/* Updated: 2021/09/05 18:41:41 by pmaryjo ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memmove(void *dst, const void *src, size_t len)
{
size_t c;
unsigned char *d;
unsigned char *s;
c = 0;
if (dst == (void *)src)
return (dst);
d = (unsigned char *)(dst + len - 1);
s = (unsigned char *)(src + len - 1);
if (src - dst < 0)
{
while (len-- > 0)
{
*(d--) = *(s--);
}
}
else
{
while (c < len)
{
*(unsigned char *)(dst + c) = *(const unsigned char *)(src + c);
c++;
}
}
return (dst);
}