blob: ab5b5c1719d3fb9548a1c8a3f7f72fec881f1b09 (
plain)
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
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/14 17:07:09 by rbousset #+# #+# */
/* Updated: 2020/02/14 17:07:09 by rbousset ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
#include <stdlib.h>
char
*ft_strdup(const char *s1)
{
char *n_str;
size_t slen;
size_t i;
slen = ft_strlen(s1);
if (!(n_str = (char*)malloc((slen + 1) * sizeof(char))))
return (NULL);
i = 0;
while (s1[i])
{
n_str[i] = s1[i];
i++;
}
n_str[i] = '\0';
return (n_str);
}
|