-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmisc_functions.c
More file actions
62 lines (56 loc) · 1.58 KB
/
misc_functions.c
File metadata and controls
62 lines (56 loc) · 1.58 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* misc_functions.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hmeftah <hmeftah@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/25 16:54:30 by hmeftah #+# #+# */
/* Updated: 2023/05/26 14:48:08 by hmeftah ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_malloc.h"
void destroy_node(t_address *node)
{
if (node == NULL)
return ;
if (node->ptr)
{
free (node->ptr);
node->dealloc = 1;
node->ptr = NULL;
node->size = 0;
}
free(node);
node = NULL;
}
t_address *create_node(void *ptr, unsigned int size)
{
t_address *node;
node = malloc(sizeof(t_address));
if (node == NULL)
return (NULL);
node->size = size;
node->dealloc = 0;
node->prev = NULL;
node->next = NULL;
node->ptr = ptr;
return (node);
}
void add_node_back(t_address **head, t_address *node)
{
t_address *temp;
temp = *head;
if (!*head)
{
*head = node;
return ;
}
else if (temp)
{
while (temp->next)
temp = temp->next;
}
temp->next = node;
node->prev = temp;
}