libft/list/ft_lstmap.c
Raphael 3cadabea0a
docs(list): moving the actual documentation on the header
- The documentation on the header allow u to see on the files where the
header is inclued
2025-09-05 16:29:29 +02:00

38 lines
1.4 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/12 11:43:28 by rparodi #+# #+# */
/* Updated: 2025/09/05 16:14:05 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "list.h"
#include <unistd.h>
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *tempo;
t_list *tempo_content;
tempo_content = ft_lstnew(f(lst->content));
if (!tempo_content)
return (NULL);
tempo = tempo_content;
lst = lst->next;
while (lst)
{
tempo_content = ft_lstnew(f(lst->content));
if (!tempo_content)
{
ft_lstclear(&tempo, del);
return (NULL);
}
ft_lstadd_back(&tempo, tempo_content);
lst = lst->next;
}
return (tempo);
}