-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memcpy.c
43 lines (40 loc) · 1.68 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: imunaev- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/01 10:40:38 by imunaev- #+# #+# */
/* Updated: 2025/01/18 12:37:57 by imunaev- ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/**
* @brief Copies bytes from one memory area to another.
*
* This function copies `n` bytes from the memory area pointed to by `src`
* to the memory area pointed to by `dest`. The memory areas must not overlap.
*
* @param dest Pointer to the destination memory area.
* @param src Pointer to the source memory area.
* @param n The number of bytes to copy.
* @return void* A pointer to the destination memory area `dest`.
* Returns a pointer to a newly allocated memory block if both
* `dest` and `src` are NULL.
*/
void *ft_memcpy(void *dest, const void *src, size_t n)
{
const unsigned char *s;
unsigned char *d;
if (!dest && !src)
return (malloc(0));
d = (unsigned char *)dest;
s = (const unsigned char *)src;
while (n > 0)
{
*d++ = *s++;
n--;
}
return (dest);
}