-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memmove.c
executable file
·55 lines (50 loc) · 1.49 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ngouy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/11/06 11:15:00 by ngouy #+# #+# */
/* Updated: 2015/11/04 16:38:05 by ngouy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** same as memcpy but can overlap
** :http://stackoverflow.com/questions/4415910/memcpy-vs-memmove
*/
#include "libft.h"
static void ft_annexe(char *dstc, char *srcc, size_t len)
{
srcc += (len - 1);
dstc += (len - 1);
while (len > 0)
{
*dstc = *srcc;
len--;
dstc--;
srcc--;
}
}
void *ft_memmove(void *dst, void const *src, size_t len)
{
char *dstc;
char *srcc;
if (!dst || !src || !len)
return (NULL);
dstc = (char *)dst;
srcc = (char *)src;
if (dst <= src)
{
while (len > 0)
{
*dstc = *srcc;
len--;
dstc++;
srcc++;
}
}
else
ft_annexe(dstc, srcc, len);
return (dst);
}