-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memmove.c
40 lines (37 loc) · 1.27 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: telias-p <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/13 18:29:15 by telias-p #+# #+# */
/* Updated: 2021/04/05 20:26:30 by telias-p ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memmove(void *dest, const void *src, size_t n)
{
size_t i;
if (!dest && !src)
return (0);
i = 0;
if ((size_t)dest - (size_t)src < n)
{
i = n - 1;
while (i >= 0 && i < n)
{
((unsigned char *)dest)[i] = ((unsigned char *)src)[i];
i--;
}
}
else
{
while (i < n)
{
((unsigned char *)dest)[i] = ((unsigned char *)src)[i];
i++;
}
}
return (dest);
}