/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_lstmap.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/10 01:03:28 by erey-bet #+# #+# */ /* Updated: 2022/10/10 14:55:38 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)) { t_list *head; t_list *new; if (lst == NULL || f == NULL || del == NULL) return (NULL); new = ft_lstnew(f(lst->content)); if (new == NULL) { ft_lstclear(&new, del); return (NULL); } head = new; lst = lst->next; while (lst != NULL) { new->next = ft_lstnew(f(lst->content)); if (new == NULL) { ft_lstclear(&head, del); return (NULL); } new = new->next; lst = lst->next; } return (head); }