-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strdup.c
31 lines (28 loc) · 1.12 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dskrypny <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/11 21:43:42 by dskrypny #+# #+# */
/* Updated: 2018/02/11 16:54:13 by dskrypny ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s1)
{
int len;
char *s;
char *dst;
len = 0;
while (s1[len])
len++;
if (!(dst = malloc(sizeof(char) * (len + 1))))
return (NULL);
s = dst;
while (*s1)
*dst++ = *s1++;
*dst = '\0';
return (s);
}