-
Notifications
You must be signed in to change notification settings - Fork 12
/
ft_strdup.c
33 lines (29 loc) · 1.35 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: apuchill <apuchill@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/12/12 16:57:53 by apuchill #+# #+# */
/* Updated: 2020/02/19 14:06:00 by apuchill ### ########.fr */
/* */
/* ************************************************************************** */
/*
** LIBRARY: <string.h>
** SYNOPSIS: save a copy of a string (with malloc)
**
** DESCRIPTION:
** The strdup() function allocates sufficient memory for a copy of the
** string s1, does the copy, and returns a pointer to it. The pointer may
** subsequently be used as an argument to the function free(3).
*/
#include "libft.h"
char *ft_strdup(const char *s1)
{
char *s2;
if (!(s2 = (char *)malloc(ft_strlen(s1) + 1)))
return (0);
ft_memcpy(s2, s1, ft_strlen(s1) + 1);
return (s2);
}