42-archive/ftp/libft/srcs/lst/ft_lstmap.c
2017-10-08 12:28:04 +02:00

26 lines
1.1 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:21 by jhalford #+# #+# */
/* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, void *(*f)(void *))
{
t_list *elem;
if (!lst)
return (NULL);
if (!(elem = (t_list *)ft_malloc(sizeof(*elem))))
return (NULL);
elem->content = (*f)(lst->content);
elem->next = ft_lstmap(lst->next, f);
return (elem);
}