-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfree_utils.c
53 lines (47 loc) · 1.41 KB
/
free_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
/* ************************************************************************** */
/* */
/* :::::::: */
/* free_utils.c :+: :+: */
/* +:+ */
/* By: jvan-hal <[email protected]> +#+ */
/* +#+ */
/* Created: 2023/03/07 13:11:32 by jvan-hal #+# #+# */
/* Updated: 2023/03/23 11:04:57 by jvan-hal ######## odam.nl */
/* */
/* ************************************************************************** */
#include<stdlib.h>
#include"pipex.h"
static void free_split(char **arr)
{
int i;
i = 0;
while (arr[i])
{
free(arr[i]);
arr[i] = NULL;
++i;
}
free(arr);
arr = NULL;
}
static void free_split_array(char ***split_arr)
{
int i;
i = 0;
while (split_arr[i])
{
free_split(split_arr[i]);
++i;
}
free(split_arr);
}
void free_state(t_info *state)
{
if (state->paths)
free_split(state->paths);
if (state->comm_paths)
free_split(state->comm_paths);
if (state->comm_argv)
free_split_array(state->comm_argv);
free(state);
}