42_cub3d/Libft/ft_lstmap.c
2024-10-09 03:35:09 +02:00

41 lines
1.4 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/24 11:59:12 by grobledo #+# #+# */
/* Updated: 2023/02/24 11:59:13 by grobledo ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, void *(f)(void *), void (*del)(void *))
{
t_list *new;
t_list *current;
if (!lst || !f ||!del)
return (NULL);
new = ft_lstnew(NULL);
if (!new)
return (NULL);
current = new;
while (lst)
{
current->content = f(lst->content);
if (lst->next)
{
current->next = ft_lstnew(NULL);
if (!current)
{
ft_lstclear(&new, del);
return (NULL);
}
current = current ->next;
}
lst = lst->next;
}
return (new);
}