-
Notifications
You must be signed in to change notification settings - Fork 0
/
free_functions.c
48 lines (43 loc) · 1.52 KB
/
free_functions.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
/* ************************************************************************** */
/* */
/* :::::::: */
/* free_functions.c :+: :+: */
/* +:+ */
/* By: cschuijt <[email protected]> +#+ */
/* +#+ */
/* Created: 2022/11/12 20:32:15 by cschuijt #+# #+# */
/* Updated: 2022/11/12 20:32:15 by cschuijt ######## odam.nl */
/* */
/* ************************************************************************** */
#include "so_long.h"
#include <stdlib.h>
#include <stdio.h>
// @brief Frees each element in a NULL-terminated array of pointers, then
// frees the array itself. Does not set array pointer to NULL.
void free_array(void **array)
{
size_t i;
if (!array)
return ;
i = 0;
while (array[i])
{
free(array[i]);
i++;
}
free(array);
}
// @brief Prints "Error\n" on stderr, followed by a message, then exits the
// program with code 1.
void exit_message(char *msg)
{
ft_putstr_fd("Error\n", 2);
ft_putendl_fd(msg, 2);
exit(1);
}
// @brief Calls perror with msg, then exits the program with code 1.
void exit_perror(char *msg)
{
perror(msg);
exit(1);
}