Exemplo n.º 1
0
t_list			*ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
{
	t_list		*elem;
	t_list		*nlst;

	nlst = NULL;
	while (lst)
	{
		elem = f(lst);
		ft_add_elem(&nlst, elem);
		lst = lst->next;
	}
	return (nlst);
}
Exemplo n.º 2
0
int					get_next_line(int const fd, char **line)
{
	static t_lst	*stack = NULL;
	static t_info	*info = NULL;

	if (!info)
		ft_init_gnl(&info);
	if (stack && ft_trait(stack, info, line))
		return (1);
	if (fd < 0 || !(stack = ft_add_elem(info)))
		return (-1);
	while ((stack->ret = read(fd, stack->buff, BUFF_SIZE)) > 0)
	{
		stack->buff[stack->ret] = '\0';
		if (ft_trait(stack, info, line))
			return (1);
		if (!(stack = ft_add_elem(info)))
			return (-1);
	}
	if (stack->ret < 0)
		return (-1);
	*line = ft_join_elem(info);
	return (ft_reset_gnl(&info));
}