/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* get_next_line_utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/29 08:54:42 by narnaud #+# #+# */ /* Updated: 2021/12/10 14:21:30 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ #include "fdf.h" void *ft_calloc(size_t count, size_t size) { void *ret; size_t i; i = 0; ret = malloc(count * size); if (ret) while (i < (count * size)) *(char *)(ret + i++) = 0; return (ret); } t_split *ft_splitlast(t_split *lst) { if (!lst) return (NULL); while (lst->next) lst = lst->next; return (lst); } t_split *ft_new_split(char *content) { t_split *empty_lst; empty_lst = (t_split *)malloc(sizeof(*empty_lst)); if (!empty_lst) return (NULL); empty_lst->content = content; empty_lst->next = NULL; empty_lst->i = 0; empty_lst->count = 1; return (empty_lst); } void ft_splitadd_back(t_split **alst, t_split *new) { t_split *i_cell; if (!alst || !new) return ; if (*alst) { i_cell = ft_splitlast(*alst); i_cell->next = new; new->count = i_cell->count + 1; } else *alst = new; }