aboutsummaryrefslogtreecommitdiff
path: root/functions_reference/ref_ft_list_remove_if.c
blob: 90bd1cc192256574855e77e88a628d70b74da644 (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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ref_ft_list_remove_if.c                            :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: cacharle <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/08 03:20:03 by cacharle          #+#    #+#             */
/*   Updated: 2020/04/13 15:01:02 by charles          ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "libasm_test.h"

void ref_ft_list_remove_if(t_list **begin_list, void *data_ref,
							int (*cmp)(), void (*free_fct)(void *))
{
	t_list *saved_next;

	if (begin_list == NULL || *begin_list == NULL)
		return ;
	if (cmp((*begin_list)->data, data_ref) != 0)
	{
		ref_ft_list_remove_if(&(*begin_list)->next, data_ref, cmp, free_fct);
		return ;
	}
	saved_next = (*begin_list)->next;
	free_fct((*begin_list)->data);
	free(*begin_list);
	*begin_list = saved_next;
	ref_ft_list_remove_if(begin_list, data_ref, cmp, free_fct);
}