-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfree_and_close.c
74 lines (68 loc) · 1.64 KB
/
free_and_close.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
63
64
65
66
67
68
69
70
71
72
73
74
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* free_and_close.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmeier <mmeier@student.hive.fi> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/04 14:33:33 by mmeier #+# #+# */
/* Updated: 2024/04/18 10:59:57 by mmeier ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
char *ft_free(char **str)
{
if (*str)
{
free(*str);
*str = NULL;
}
return (NULL);
}
int ft_free_map(char **str, int *fd)
{
if (*str)
{
free(*str);
*str = NULL;
close(*fd);
}
return (-1);
}
int ft_free_empty(char **str, int *fd)
{
if (*str)
{
free(*str);
*str = NULL;
close(*fd);
}
ft_printf("Error\nMap is empty or a directory :(\n");
return (-1);
}
void free_and_close(char **str, int *fd)
{
if (*str)
{
free(*str);
*str = NULL;
close(*fd);
}
}
int free_all(t_game *game, int n)
{
if (n == 0)
{
delete_error_images(game);
mlx_terminate(game->mlx);
if (game->map)
free_arr(game->map);
ft_printf("Game could not be initialised :(\n");
}
if (n == 1)
{
if (game->map)
free_arr(game->map);
}
return (0);
}