-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils.c
87 lines (76 loc) · 1.94 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
82
83
84
85
86
87
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aceauses <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/09 17:00:27 by aceauses #+# #+# */
/* Updated: 2023/05/18 15:38:24 by aceauses ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
void *ft_calloc(size_t count, size_t size)
{
char *memory;
size_t i;
memory = malloc(count * size);
if (!memory)
return (free(memory), NULL);
i = 0;
while (i < count * size)
{
memory[i] = 0;
i++;
}
return (memory);
}
char *ft_strjoin_gnl(char const *line, char const *new_line)
{
char *mem;
int x;
int i;
if (!line || !new_line)
return (NULL);
mem = malloc(ft_strlen(line) + ft_strlen(new_line) + 1);
if (!mem)
return (NULL);
i = 0;
x = 0;
while (line[x] != '\0')
mem[i++] = line[x++];
x = 0;
while (new_line[x] != '\0')
mem[i++] = new_line[x++];
mem[i] = '\0';
return (mem);
}
size_t ft_strlen(const char *str)
{
size_t i;
i = 0;
while (str[i] != '\0')
i++;
return (i);
}
char *ft_strchr(const char *str, int c)
{
char cr;
cr = (char)c;
while (*str != '\0')
{
if (*str == cr)
return ((char *)str);
str++;
}
while (cr == '\0')
return ((char *)str);
return (NULL);
}
char *free_join(char *buffer, char *buff)
{
char *temp;
temp = ft_strjoin_gnl(buffer, buff);
free(buffer);
return (temp);
}