-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memmove.c
60 lines (57 loc) · 1.97 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
56
57
58
59
60
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nholbroo <nholbroo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/13 17:05:42 by nholbroo #+# #+# */
/* Updated: 2025/02/03 16:50:41 by nholbroo ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
Which function:
Equivalent to the function "memmove" in string.h.
Definition:
The memmove() function copies n bytes from memory area src to memory
area dest. The memory areas may overlap: copying happens either starting
from the start or end of src, depending on how dest and src are placed
in the memory.
Return values:
Returns a pointer to dest.
@param src A pointer to the start of the original memory.
@param dest A pointer to the start of the copied memory.
@param n How many bytes to be copied.
@param j Stores n, in order to be able to copy starting from end instead of
start.
@param srcptr Making srcptr point to src, with the purpose of typecasting. Same
applies to destptr.
*/
void *ft_memmove(void *dest, const void *src, size_t n)
{
size_t i;
size_t j;
unsigned char *destptr;
const unsigned char *srcptr;
if (dest == NULL && src == NULL)
return (NULL);
i = 0;
j = n;
destptr = dest;
srcptr = src;
if (dest > src)
{
while (j-- > 0)
destptr[j] = srcptr[j];
}
else
{
while (i < n)
{
destptr[i] = srcptr[i];
i++;
}
}
return (dest);
}