-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_lstmap.c
45 lines (41 loc) · 1.51 KB
/
ft_lstmap.c
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
39
40
41
42
43
44
45
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gfoote <gfoote@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/10 16:54:07 by gfoote #+# #+# */
/* Updated: 2019/04/11 13:34:43 by gfoote ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static void ft_del(void *content, size_t content_size)
{
content_size = 0;
free(content);
}
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
{
t_list *new_elem;
t_list *temp_elem;
t_list *result;
if (!lst || !f || !(new_elem = (t_list*)malloc(sizeof(t_list))) ||
!(new_elem = f(lst)))
return (NULL);
result = new_elem;
temp_elem = new_elem;
lst = lst->next;
while (lst)
{
if (!(new_elem = f(lst)))
{
ft_lstdel(&result, &ft_del);
return (NULL);
}
temp_elem->next = ft_lstnew(new_elem->content, new_elem->content_size);
temp_elem = temp_elem->next;
lst = lst->next;
}
return (result);
}