-
Notifications
You must be signed in to change notification settings - Fork 4
/
ft_strdup.c
29 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
29
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aalvarez <aalvarez@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/21 13:36:25 by aalvarez #+# #+# */
/* Updated: 2024/06/21 13:38:03 by aalvarez ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "libft.h"
char *ft_strdup(const char *s)
{
char *str;
size_t len;
len = ft_strlen(s);
str = (char *)malloc(len + 1);
if (str == NULL)
return (NULL);
ft_memcpy(str, s, len);
str[len] = '\0';
return (str);
}