-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathft_memmove.c
50 lines (46 loc) · 1.5 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apuchill <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/27 13:05:26 by apuchill #+# #+# */
/* Updated: 2020/10/30 19:52:35 by apuchill ### ########.fr */
/* */
/* ************************************************************************** */
/*
** LIBRARY: <string.h>
** SYNOPSIS: copy byte string
**
** DESCRIPTION:
** The memmove() function copies n bytes from string s2 to string s1. The
** two strings may overlap; the copy is always done in a non-destructive
** manner.
*/
#include "libft.h"
void *ft_memmove(void *dst, const void *src, size_t len)
{
size_t i;
if (!dst && !src)
return (0);
i = 0;
if ((size_t)dst - (size_t)src < len)
{
i = len - 1;
while (i < len)
{
((unsigned char *)dst)[i] = ((unsigned char *)src)[i];
i--;
}
}
else
{
while (i < len)
{
((unsigned char *)dst)[i] = ((unsigned char *)src)[i];
i++;
}
}
return (dst);
}