-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memdup.c
31 lines (28 loc) · 1.16 KB
/
ft_memdup.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ylagtab <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/27 23:14:54 by ylagtab #+# #+# */
/* Updated: 2021/01/15 19:12:39 by ylagtab ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memdup(void *src, size_t n)
{
unsigned char *res;
unsigned char *s;
size_t i;
if (src == NULL || (res = (unsigned char*)ft_malloc(n)) == NULL)
return (NULL);
i = 0;
s = (unsigned char *)src;
while (i < n)
{
res[i] = s[i];
i++;
}
return ((void*)res);
}