diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2020-10-11 15:52:52 +0200 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2020-10-11 15:52:52 +0200 |
| commit | c98de126d2252fe47dc2a9094a5f9a8fa6b4b60a (patch) | |
| tree | 12f1c827ee063ed3e7038f6a704014e611e4f388 /libft/src/lst/ft_lstremove_if.c | |
| parent | a4ceb5974d1b7dcdd12cc81b7eb07893ea16c8ad (diff) | |
| download | minishell-c98de126d2252fe47dc2a9094a5f9a8fa6b4b60a.tar.gz minishell-c98de126d2252fe47dc2a9094a5f9a8fa6b4b60a.tar.bz2 minishell-c98de126d2252fe47dc2a9094a5f9a8fa6b4b60a.zip | |
Removing libft/minishell_test submodules, Removing subject/README/etc
Diffstat (limited to 'libft/src/lst/ft_lstremove_if.c')
| -rw-r--r-- | libft/src/lst/ft_lstremove_if.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/libft/src/lst/ft_lstremove_if.c b/libft/src/lst/ft_lstremove_if.c new file mode 100644 index 0000000..4070355 --- /dev/null +++ b/libft/src/lst/ft_lstremove_if.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstremove_if.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/30 09:36:49 by cacharle #+# #+# */ +/* Updated: 2020/02/28 12:20:51 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_lst.h" + +/* +** \brief Remove node on some condition +** \param cmp Comparison function, return 0 if equal +** \param ref Reference data passed has the first arg of `cmp` +** \param del Delete function to free removed node data +*/ + +void ft_lstremove_if(t_ftlst **lst, t_ftcompar_func cmp, + const void *ref, t_ftdel_func del) +{ + t_ftlst *saved_next; + + if (lst == NULL || *lst == NULL) + return ; + if (cmp(ref, (*lst)->data) == 0) + { + saved_next = (*lst)->next; + ft_lstdelone(*lst, del); + *lst = saved_next; + ft_lstremove_if(lst, cmp, ref, del); + return ; + } + ft_lstremove_if(&(*lst)->next, cmp, ref, del); +} |
