-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strdup.c
executable file
·34 lines (31 loc) · 1.27 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: luperez <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/11/05 22:24:58 by luperez #+# #+# */
/* Updated: 2014/12/21 23:56:04 by luperez ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s1)
{
int i;
unsigned char *s2;
unsigned char *start_s2;
int len;
if (!s1)
return (NULL);
len = ft_strlen((char *)s1);
if (len < 0 || !(s2 = (unsigned char *)ft_strnew(len + 1)))
return (NULL);
ft_bzero(s2, len + 1);
start_s2 = s2;
s2[len] = '\0';
i = -1;
while (s1[++i])
s2[i] = (unsigned char)s1[i];
return ((char *)start_s2);
}