-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strdup.c
28 lines (25 loc) · 1.11 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmendes- <mmendes-@student.42lisboa.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/30 19:53:19 by mmendes- #+# #+# */
/* Updated: 2022/10/30 19:53:19 by mmendes- ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *string)
{
char *str;
int len;
char *p;
str = (char *)string;
len = ft_strlen(str);
p = malloc((len + 1) * sizeof(char));
if (!p)
return (NULL);
ft_strlcpy(p, str, len + 1);
return (p);
}