-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strdup.c
32 lines (28 loc) · 1.22 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gcosta-d <gcosta-d@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/20 16:35:48 by gcosta-d #+# #+# */
/* Updated: 2021/09/14 10:17:27 by gcosta-d ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/* This function dupplicates the string that is passed.
* And return a pointer to the copied string.
*/
char *ft_strdup(const char *s)
{
size_t s_len;
char *p;
char *pointer;
s_len = ft_strlen(s) + 1;
p = (char *)ft_calloc(s_len, sizeof(char));
if (!p)
return (NULL);
pointer = p;
ft_strlcpy(p, s, s_len);
return (pointer);
}