-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memmove.c
51 lines (44 loc) · 1.51 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jeshin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/05 19:16:11 by jeshin #+# #+# */
/* Updated: 2023/10/21 18:21:17 by jeshin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void move_from_front(void *dst, const void *src, size_t *len)
{
size_t prv;
while (*len)
{
*(unsigned char *)dst++ = *(unsigned char *)src++;
prv = (*len)--;
if (*len > prv)
break ;
}
}
void move_from_back(void *dst, const void *src, size_t *len)
{
size_t prv;
while (*len)
{
*(unsigned char *)(dst + *len - 1) = *(unsigned char *)(src + *len - 1);
prv = (*len)--;
if (*len > prv)
break ;
}
}
void *ft_memmove(void *dst, const void *src, size_t len)
{
void *ret;
ret = dst;
if (dst < src)
move_from_front(dst, src, &len);
else if (dst > src)
move_from_back(dst, src, &len);
return (dst);
}