-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memmove.c
66 lines (61 loc) · 1.59 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
54
55
56
57
58
59
60
61
62
63
64
65
66
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: masoares <masoares@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/02 19:59:37 by masoares #+# #+# */
/* Updated: 2023/10/08 20:03:41 by masoares ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memmove_rev(void *dest, const void *src, size_t n)
{
const char *s;
unsigned int i;
char *d;
s = src;
d = dest;
i = n - 1;
while (i >= 0)
{
*(d + i) = *(s + i);
if (i == 0)
break ;
i--;
}
return (d);
}
void *ft_memmove(void *dest, const void *src, size_t n)
{
const char *s;
unsigned int i;
char *d;
s = src;
d = dest;
i = 0;
if (src == NULL && dest == NULL)
return (NULL);
if (n == 0)
return (d);
if (s > d)
{
while (i < n)
{
*(d + i) = *(s + i);
i++;
}
}
else if (s < d)
d = ft_memmove_rev(dest, src, n);
return (d);
}
/*
int main ()
{
char str[] = "memmove can be very useful......";
ft_memmove (str+20,str+15,0);
puts (str);
return 0;
}*/