-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memmove.c
43 lines (40 loc) · 1.29 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: mmita <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 14:22:05 by mmita #+# #+# */
/* Updated: 2022/10/08 15:55:00 by mmita ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <string.h>
void *ft_memmove(void *dst, const void *src, size_t len)
{
size_t i;
if (!dst && !src)
{
return (0);
}
i = 0;
if ((size_t)dst - (size_t)src < len)
{
i = len - 1;
while (i < len)
{
((unsigned char *)dst)[i] = ((unsigned char *)src)[i];
i--;
}
}
else
{
while (i < len)
{
((unsigned char *)dst)[i] = ((unsigned char *)src)[i];
i++;
}
}
return (dst);
}