mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-05-13 16:08:45 +02:00
「✨」 feat(libft): added a very cool feature !
This commit is contained in:
35
libft/lst/ft_lstmap.c
Normal file
35
libft/lst/ft_lstmap.c
Normal file
@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstmap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/11 18:24:49 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:58:45 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
|
||||
{
|
||||
t_list *res;
|
||||
t_list *tmp;
|
||||
|
||||
if (!lst || !f || !del)
|
||||
return (NULL);
|
||||
res = NULL;
|
||||
while (lst)
|
||||
{
|
||||
tmp = ft_lstnew(f(lst->content));
|
||||
if (tmp == NULL)
|
||||
{
|
||||
ft_lstclear(&tmp, del);
|
||||
return (NULL);
|
||||
}
|
||||
ft_lstadd_back(&res, tmp);
|
||||
lst = lst->next;
|
||||
}
|
||||
return (res);
|
||||
}
|
Reference in New Issue
Block a user