-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memmove.c
42 lines (39 loc) · 1.33 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: coskelet <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/15 13:08:06 by coskelet #+# #+# */
/* Updated: 2021/11/09 12:42:21 by coskelet ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memmove(void *dst, const void *src, size_t n)
{
size_t i;
unsigned char *src_c;
unsigned char *dst_c;
if (!dst && !src)
return (dst);
src_c = (unsigned char *)src;
dst_c = (unsigned char *)dst;
if (src < dst && (src_c + n - 1) >= dst_c)
{
i = n;
while (i > 0)
{
*(dst_c + i - 1) = *(src_c + i - 1);
i--;
}
return (dst);
}
i = 0;
while (i < n)
{
*(dst_c + i) = *(src_c + i);
i++;
}
return (dst);
}