-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strdup.c
43 lines (38 loc) · 1.29 KB
/
ft_strdup.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_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rlutsch <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/05 15:46:08 by rlutsch #+# #+# */
/* Updated: 2016/08/05 15:53:20 by rlutsch ### ########.fr */
/* */
/* ************************************************************************** */
#include "21sh.h"
void *ft_memcpy(void *restrict dst, const void *restrict src, size_t n)
{
char *s;
char *d;
int i;
s = (char *)src;
d = (char *)dst;
i = 0;
while (n > 0)
{
d[i] = s[i];
i++;
n--;
}
return (d);
}
char *ft_strdup(const char *s1)
{
size_t len;
char *copy;
len = ft_strlen(s1) + 1;
if (!(copy = malloc((unsigned int)len)))
return (NULL);
ft_memcpy((void *)s1, copy, len);
return (copy);
}