-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memcpy.c
75 lines (57 loc) · 1.73 KB
/
ft_memcpy.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: musenov <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/20 00:23:46 by musenov #+# #+# */
/* Updated: 2022/12/08 18:27:15 by musenov ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memcpy(void *dst, const void *src, size_t n)
{
size_t i;
if (n == 0 || dst == src)
return (dst);
i = 0;
while (i < n)
{
*((unsigned char *)dst + i) = *((unsigned char *)src + i);
i++;
}
return (dst);
}
/*
ft_memcpy:
PARAMETERS
-/-
RETURN VALUE
The memcpy() function returns the original value of dst.
DESCRIPTION
The memcpy() function copies n bytes from memory area src to memory area dst.
If dst and src overlap, behavior is undefined. Applications in which dst
and src might overlap should use memmove(3) instead.
QUESTIONS
-/-
ANSWER
-/-
COMPARE
-/-
ALTERNATIVE SOLUTION
-/-
EXPLANATION
0123456789ABC
| |
d s n = 5 -> s: src, d: dst
result:
6789A89ABC
0123456789ABC
| |
s d n = 5 -> s: src, d: dst
result:
34534BC
REMARK
Memory overlap not possible, use memmove for that
*/