-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strdup.c
More file actions
43 lines (40 loc) · 1.28 KB
/
ft_strdup.c
File metadata and controls
43 lines (40 loc) · 1.28 KB
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
36
37
38
39
40
41
42
43
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_strdup.c :+: :+: */
/* +:+ */
/* By: greed <greed@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2019/10/31 15:51:34 by greed #+# #+# */
/* Updated: 2019/11/06 10:42:28 by greed ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
#include <errno.h>
char *ft_strdup(const char *s1)
{
unsigned char *block;
int len;
int i;
char *str;
len = 0;
i = 0;
while (s1[len])
len++;
block = (unsigned char*)ft_calloc(sizeof(char), len);
if (!(block))
ENOMEM;
else
{
str = (char*)malloc(len + 1);
while (s1[i])
{
str[i] = s1[i];
i++;
}
str[i] = '\0';
return (str);
}
return (0);
}