-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_lstmap.c
More file actions
38 lines (35 loc) · 1.34 KB
/
Copy pathft_lstmap.c
File metadata and controls
38 lines (35 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lbuscaro <lbuscaro@student.42porto.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/30 15:47:03 by lbuscaro #+# #+# */
/* Updated: 2025/04/30 15:47:04 by lbuscaro ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *ret_lst;
void *content;
t_list *node;
if (lst == NULL || f == NULL || del == NULL)
return (NULL);
ret_lst = NULL;
while (lst != NULL)
{
content = f(lst->content);
node = ft_lstnew(content);
if (node == NULL)
{
del(content);
ft_lstclear(&ret_lst, del);
return (NULL);
}
ft_lstadd_back(&ret_lst, node);
lst = lst->next;
}
return (ret_lst);
}