-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper_1.c
57 lines (51 loc) · 1.09 KB
/
helper_1.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
#include "shell.h"
/**
* free_recurrent_data - free the fields needed each loop
* @data: struct of the program's data
* Return: Nothing
*/
void free_recurrent_data(data_of_program *data)
{
if (data->tokens)
free_array_of_pointers(data->tokens);
if (data->input_line)
free(data->input_line);
if (data->command_name)
free(data->command_name);
data->input_line = NULL;
data->command_name = NULL;
data->tokens = NULL;
}
/**
* free_all_data - free all field of the data
* @data: struct of the program's data
* Return: Nothing
*/
void free_all_data(data_of_program *data)
{
if (data->file_descriptor != 0)
{
if (close(data->file_descriptor))
perror(data->program_name);
}
free_recurrent_data(data);
free_array_of_pointers(data->env);
free_array_of_pointers(data->alias_list);
}
/**
* free_array_of_pointers - frees each pointer of an array of pointers and the
* array too
* @array: array of pointers
* Return: nothing
*/
void free_array_of_pointers(char **array)
{
int i;
if (array != NULL)
{
for (i = 0; array[i]; i++)
free(array[i]);
free(array);
array = NULL;
}
}