This repository has been archived by the owner on Nov 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ft_memmove.c
49 lines (44 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcombeau <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/23 15:57:19 by mcombeau #+# #+# */
/* Updated: 2021/12/02 16:48:38 by mcombeau ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
DESCRIPTION :
The function ft_memmove copies n bytes from memory area src to memory
area dst. The memory areas may overlap: if the dst pointer is found
to be between the src pointer and the index n, copying will be done
back to front to prevent data being modified before being copied.
Otherwise it will be done front to back to preserve data.
RETURN VALUE :
A pointer to dst.
*/
void *ft_memmove(void *dst, const void *src, size_t len)
{
char *dp;
const char *sp;
if (src == dst)
return (dst);
dp = (char *)dst;
sp = (const char *)src;
if (sp < dp && sp + len > dp)
while (len--)
*(dp + len) = *(sp + len);
else
{
while (len--)
{
*dp = *sp;
sp++;
dp++;
}
}
return (dst);
}