-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathft_utils.c
77 lines (68 loc) · 1.75 KB
/
ft_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: escura <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/04 14:09:06 by escura #+# #+# */
/* Updated: 2024/05/08 15:20:05 by escura ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_alloc.h"
t_allocs *ft_allocs(t_allocs *lst)
{
static t_allocs *allocs;
if (lst != NULL)
{
allocs = lst;
return (NULL);
}
return (allocs);
}
int ft_allocsize(void)
{
t_allocs *lst;
int size;
lst = ft_allocs(NULL);
size = 0;
while (lst)
{
size++;
lst = lst->next;
}
return (size);
}
t_allocs *ft_lstlast(t_allocs *lst)
{
if (!lst)
return (NULL);
while (lst->next)
lst = lst->next;
return (lst);
}
void add_allocnode(t_allocs **lst, t_allocs *nnew)
{
if (DEBUG)
printf("Creating new alloc %p\n", nnew->ptr);
if (!lst || !nnew)
return ;
if (*lst)
ft_lstlast(*lst)->next = nnew;
else
*lst = nnew;
}
t_allocs *create_alloc(void *ptr)
{
t_allocs *new;
new = malloc(sizeof(t_allocs));
if (new == NULL)
{
printf("Memory allocation failed\n");
ft_destructor();
exit(EXIT_FAILURE);
}
new->ptr = ptr;
new->next = NULL;
return (new);
}