summaryrefslogtreecommitdiffstats
path: root/libft/src/ft_lstclear.c
blob: 37fec4e18a774192bc41fe67b7c78a45df100cbc (plain)
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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_lstclear.c                                      :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: rbousset <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/14 17:06:41 by rbousset          #+#    #+#             */
/*   Updated: 2020/02/14 17:06:41 by rbousset         ###   ########lyon.fr   */
/*                                                                            */
/* ************************************************************************** */

#include <libft.h>
#include <stdlib.h>

void	ft_lstclear(t_list **lst, void (*del)(void *))
{
	t_list	*tmp;
	t_list	*renext;

	if (lst == NULL)
	{
		return ;
	}
	tmp = *lst;
	while (tmp != NULL)
	{
		renext = tmp->next;
		del(tmp->content);
		free(tmp);
		tmp = renext;
	}
	*lst = NULL;
}