-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.c
62 lines (53 loc) · 1.68 KB
/
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: acostaz <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/26 18:13:42 by acostaz #+# #+# */
/* Updated: 2019/04/08 14:37:26 by acostaz ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
/*
** Function to free map and eventually exit the program in case of error
*/
void free_map(t_data *e, int error, char *message)
{
int i;
i = -1;
while (++i < e->line_nbr)
free(e->map[i]);
free(e->map);
if (error)
ft_error(message);
}
/*
** Exiting function if no error was encountered
*/
void free_and_exit(t_data *e)
{
free(e->trigrid);
exit(0);
}
/*
** e->map allocation, see parse_file.c
*/
void alloc_map(t_data *e)
{
int line_stock;
line_stock = e->line_nbr;
if (!(e->map = (int**)malloc(sizeof(int*) * e->line_nbr)))
ft_error("Failed allocation");
while (e->line_nbr > 0)
{
if (!(e->map[--e->line_nbr] = (int*)malloc(sizeof(int) * e->col_nbr)))
{
while (++e->line_nbr < line_stock)
free(e->map[e->line_nbr]);
free(e->map);
ft_error("Failed allocation");
}
}
}