-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memmove.c
53 lines (48 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ebassi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/11 17:04:52 by ebassi #+# #+# */
/* Updated: 2022/01/13 11:59:31 by ebassi ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static char *ft_ret(char *fin_dest, char *fin_src, int i, int len);
void *ft_memmove(void *dst, const void *src, size_t len)
{
char *fin_src;
char *fin_dest;
int i;
if (dst == src)
return (dst);
fin_src = (char *) src;
fin_dest = (char *) dst;
i = 0;
ft_ret(fin_dest, fin_src, i, len);
return (dst);
}
static char *ft_ret(char *fin_dest, char *fin_src, int i, int len)
{
if (fin_dest > fin_src)
{
i = (int)len - 1;
while (i >= 0)
{
fin_dest[i] = fin_src[i];
i--;
}
}
else
{
i = 0;
while (i < (int)len)
{
fin_dest[i] = fin_src[i];
i++;
}
}
return (fin_dest);
}