-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strdup.c
executable file
·35 lines (31 loc) · 1.16 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
34
35
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mwilliam <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/05 18:04:46 by mwilliam #+# #+# */
/* Updated: 2016/11/20 11:54:43 by mwilliam ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
** Copies s1 and returns a pointer to it
*/
char *ft_strdup(const char *s1)
{
char *s2;
char *tmp;
if (!(s2 = malloc(sizeof(char) * (ft_strlen(s1) + 1))))
return (NULL);
tmp = s2;
while (*s1 != '\0')
{
*tmp = *s1;
s1++;
tmp++;
}
*tmp = '\0';
return (s2);
}