-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memmove.c
63 lines (55 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tpouget <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/05/14 17:04:37 by tpouget #+# #+# */
/* Updated: 2020/05/26 16:52:27 by tpouget ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
void *ft_memmove(void *dst, const void *src, size_t len)
{
size_t i;
char *d;
char *s;
d = (char *)dst;
s = (char *)src;
i = 0;
if (!dst && !src)
return (NULL);
if (s < d)
{
i++;
while (i <= len)
{
d[len - i] = s[len - i];
i++;
}
}
else
while (i < len)
{
d[i] = s[i];
i++;
}
return (dst);
}
/*
#include <unistd.h>
int main(void)
{
char a[] = "Hello World !";
ft_memmove(a + 2, a, 4);
write(1, a, sizeof a);
write(1, "\n", 1);
char b[] = "Hello world !";
ft_memcpy(b + 2, b, 4);
write(1, b, sizeof b);
write(1, "\n", 1);
return 0;
}
*/