-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strdup.c
36 lines (33 loc) · 1.17 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ylagtab <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/31 23:44:28 by ylagtab #+# #+# */
/* Updated: 2021/01/15 19:15:23 by ylagtab ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s)
{
size_t i;
size_t len;
char *ret;
if (s == NULL)
return (NULL);
len = 0;
while (s[len])
len++;
if ((ret = (char *)ft_malloc(len + 1)) == NULL)
return (NULL);
i = 0;
while (s[i])
{
ret[i] = s[i];
i++;
}
ret[i] = '\0';
return (ret);
}