-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strdup.c
33 lines (29 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: inwagner <inwagner@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/03 18:10:41 by inwagner #+# #+# */
/* Updated: 2023/06/09 15:16:31 by inwagner ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s1)
{
char *dup;
size_t len;
if (!s1)
return (NULL);
len = ft_strlen(s1) + 1;
dup = (char *)ft_calloc(len, sizeof(char));
if (!dup)
return (NULL);
ft_strlcpy(dup, s1, len);
return (dup);
}
/*
Duplica a string `s`.
Retorna um ponteiro para a string criada ou retorna nulo se não houver espaço na memória.
*/