-
Notifications
You must be signed in to change notification settings - Fork 11
/
aux_lists2.c
61 lines (53 loc) · 958 Bytes
/
aux_lists2.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
#include "main.h"
/**
* add_rvar_node - adds a variable at the end
* of a r_var list.
* @head: head of the linked list.
* @lvar: length of the variable.
* @val: value of the variable.
* @lval: length of the value.
* Return: address of the head.
*/
r_var *add_rvar_node(r_var **head, int lvar, char *val, int lval)
{
r_var *new, *temp;
new = malloc(sizeof(r_var));
if (new == NULL)
return (NULL);
new->len_var = lvar;
new->val = val;
new->len_val = lval;
new->next = NULL;
temp = *head;
if (temp == NULL)
{
*head = new;
}
else
{
while (temp->next != NULL)
temp = temp->next;
temp->next = new;
}
return (*head);
}
/**
* free_rvar_list - frees a r_var list
* @head: head of the linked list.
* Return: no return.
*/
void free_rvar_list(r_var **head)
{
r_var *temp;
r_var *curr;
if (head != NULL)
{
curr = *head;
while ((temp = curr) != NULL)
{
curr = curr->next;
free(temp);
}
*head = NULL;
}
}