-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils.c
86 lines (76 loc) · 1.98 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aaibar-h <aaibar-h@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/27 09:04:15 by aaibar-h #+# #+# */
/* Updated: 2023/03/21 14:56:08 by aaibar-h ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
void *ft_calloc(size_t nmemb, size_t size)
{
char *mem;
size_t i;
mem = malloc(nmemb * size);
i = size * nmemb;
while (i)
mem[--i] = 0;
return (mem);
}
void *ft_bzero(void *s, size_t n)
{
const void *ptr;
ptr = s;
while (n--)
*(unsigned char *)(s++) = 0;
return ((void *) ptr);
}
size_t ft_lstsize(t_list *lst)
{
size_t c;
if (!lst)
return (0);
c = 1;
if (lst->next)
c = ft_lstsize(lst->next) + 1;
return (c);
}
t_list *ft_strlstnew(char *content)
{
t_list *node;
size_t i;
unsigned char filled;
node = malloc(sizeof(t_list));
i = 0;
filled = 0;
if (!node)
return (NULL);
node->content = ft_calloc(BUFFER_SIZE, sizeof(char));
while (i < BUFFER_SIZE)
{
((char *) node->content)[i] = content[i];
if (((char *) node->content)[i])
filled = 1;
i++;
}
node->next = NULL;
if (!filled)
{
ft_lstclear(&node, &free);
node = NULL;
}
return (node);
}
void ft_lstclear(t_list **lst, void (*del)(void *))
{
if (!lst || !*lst || !del)
return ;
if ((*lst)->next)
ft_lstclear(&((*lst)->next), del);
del((*lst)->content);
free(*lst);
*lst = NULL;
}