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
/
Copy pathft_memcpy.c
46 lines (41 loc) · 1.45 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcombeau <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/23 15:02:13 by mcombeau #+# #+# */
/* Updated: 2021/12/02 15:26:40 by mcombeau ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
DESCRIPTION :
The function ft_memcpy copies n bytes from memory area src to memory
area dst.
Does not account for memory overlaps. Use ft_memmove if the memory areas
overlap or might overlap.
RETURN VALUE :
A pointer to dst. NULL if src and dst are both NULL.
*/
void *ft_memcpy(void *dst, const void *src, size_t n)
{
char *dp;
const char *sp;
if (!dst && !src)
return (0);
if (n == 0 || (dst == src))
return (dst);
dp = (char *)dst;
sp = (const char *)src;
while (n != 0)
{
if (*dp != *sp)
*dp = *sp;
dp++;
sp++;
n--;
}
return (dst);
}