-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memmove.c
47 lines (45 loc) · 1.61 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jamendoe <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/12 18:22:08 by jamendoe #+# #+# */
/* Updated: 2022/11/12 18:22:13 by jamendoe ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memmove(void *dest, const void *src, size_t n)
{
size_t i;
char *destptr;
const char *srcptr;
destptr = dest;
srcptr = src;
i = 0;
if (!destptr && !srcptr)
return (NULL);
if (dest <= src)
{
while (n > 0)
{
destptr[i] = srcptr[i];
i++;
n--;
}
return (dest);
}
while (n--)
destptr[n] = srcptr[n];
return (dest);
}
/*
memmove - copy memory area
The memmove() function copies n bytes from memory area src to
memory area dest. The memory areas may overlap: copying takes
place as though the bytes in src are first copied into a
temporary array that does not overlap src or dest, and the bytes
are then copied from the temporary array to dest.
The memmove() function returns a pointer to dest.
*/