-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils.c
81 lines (72 loc) · 1.83 KB
/
get_next_line_utils.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
81
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bkaztaou <bkaztaou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/09 16:53:58 by bkaztaou #+# #+# */
/* Updated: 2023/05/09 16:54:42 by bkaztaou ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line_bonus.h"
char *newline_exist(char *str)
{
int i;
i = 0;
if (!str)
return (NULL);
while (str[i])
{
if (str[i] == '\n')
return (&str[i]);
i++;
}
return (NULL);
}
size_t ft_strlen(char *str)
{
size_t i;
i = 0;
while (str[i])
i++;
return (i);
}
char *ft_strjoin(char *stash, char *buff)
{
int i;
int j;
char *temp;
if (!stash && !buff)
return (NULL);
if (!stash)
stash = ft_calloc(1, sizeof(char));
temp = malloc(sizeof(char) * (ft_strlen(stash) + ft_strlen(buff) + 1));
if (!temp)
return (NULL);
i = -1;
while (stash[++i])
temp[i] = stash[i];
j = -1;
while (buff[++j])
temp[i++] = buff[j];
temp[i] = '\0';
return (free(stash), free(buff), temp);
}
void *ft_calloc(size_t count, size_t size)
{
size_t i;
char *ptr;
i = 0;
if (count && size > SIZE_MAX / count)
return (NULL);
ptr = malloc(count * size);
if (!ptr)
return (NULL);
while (i < count)
{
ptr[i] = '\0';
i++;
}
return (ptr);
}