-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strdup.c
28 lines (25 loc) · 1.09 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rlutsch <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/05 15:46:08 by rlutsch #+# #+# */
/* Updated: 2016/11/15 07:58:24 by rlutsch ### ########.fr */
/* */
/* ************************************************************************** */
#include "21sh.h"
char *ft_strdup(const char *s1)
{
char *c;
int len;
len = -1;
while (s1[++len])
;
c = (char *)malloc(len * sizeof(char) + 1);
if (c != NULL)
ft_strcpy(c, s1);
*(c + len) = '\0';
return (c);
}