-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils_bonus.c
80 lines (71 loc) · 1.75 KB
/
get_next_line_utils_bonus.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: asibille <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/28 15:21:23 by asibille #+# #+# */
/* Updated: 2022/01/28 15:21:28 by asibille ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line_bonus.h"
char *ft_strdup(const char *s1)
{
char *ptr;
int len;
int i;
len = ft_strlen(s1);
ptr = malloc (len + 1);
if (!ptr)
return (NULL);
i = -1;
while (++i <= len)
ptr[i] = s1[i];
return (ptr);
}
int ft_strlen(const char *s)
{
int i;
if (!s)
return (0);
i = 0;
while (s[i])
++i;
return (i);
}
void *ft_calloc(size_t count, size_t size)
{
unsigned char *ptr;
size_t i;
ptr = malloc(size * count);
if (!ptr)
return (NULL);
i = 0;
while (i < (size * count))
{
ptr[i] = 0;
++i;
}
return ((void *) ptr);
}
char *ft_strjoin_buffer(char *s1)
{
char *ptr;
int s1_len;
char *ptr_cpy;
char *s1_cpy;
s1_cpy = s1;
s1_len = ft_strlen(s1);
ptr = ft_calloc((s1_len + BUFFER_SIZE + 1), sizeof(char));
ptr_cpy = ptr;
if (!ptr)
return (NULL);
if (s1)
{
while (*s1)
*(ptr++) = *(s1++);
}
free(s1_cpy);
return (ptr_cpy);
}