forked from josanri/Libft_extended
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_lstclear.c
35 lines (32 loc) · 1.29 KB
/
ft_lstclear.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstclear.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aalvarez <aalvarez@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/17 22:52:37 by aalvarez #+# #+# */
/* Updated: 2022/08/17 23:08:48 by aalvarez ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
/**
* @brief iterates over a list and frees the content and nodes with free().
*
* @param lst the list to be iterated.
* @param del the function that will delete the content of the node.
*/
void ft_lstclear(t_list **lst, void (*del)(void *))
{
t_list *tmp;
if (!*lst)
return ;
while (*lst)
{
tmp = *lst;
del((*lst)->content);
*lst = (*lst)->next;
free(tmp);
}
}