-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strdup.c
39 lines (34 loc) · 1.23 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmasuda <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/04/11 22:30:20 by mmasuda #+# #+# */
/* Updated: 2021/04/18 22:09:25 by mmasuda ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static char *ft_strcpy(char *dst, const char *src)
{
int i;
i = 0;
while (src[i] != '\0')
{
dst[i] = src[i];
i++;
}
dst[i] = '\0';
return (dst);
}
char *ft_strdup(const char *s1)
{
char *s2;
int len;
len = ft_strlen(s1);
s2 = (char *)malloc(sizeof(char) * (len + 1));
if (!s2)
return (NULL);
return (ft_strcpy(s2, s1));
}