-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memmove.c
39 lines (36 loc) · 1.31 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: eel-orch <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/13 17:36:01 by eel-orch #+# #+# */
/* Updated: 2019/11/09 19:19:49 by eel-orch ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memmove(void *dst, const void *src, size_t len)
{
unsigned char *tmp;
unsigned char *ssrc;
tmp = (unsigned char *)dst;
ssrc = (unsigned char *)src;
if (dst == NULL && src == NULL)
return (NULL);
if (!len || tmp == ssrc)
return (dst);
if (tmp < ssrc)
{
while (len-- && ssrc != '\0')
*tmp++ = *ssrc++;
}
else
{
tmp += len - 1;
ssrc += len - 1;
while (len--)
*tmp-- = *ssrc--;
}
return (dst);
}