Project de l'école 42 : Get_next_line
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.7 KiB

3 years ago
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/29 08:54:42 by narnaud #+# #+# */
/* Updated: 2021/11/19 13:24:25 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line_bonus.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_lstlast(t_split *lst)
{
if (!lst)
return (NULL);
while (lst->next)
lst = lst->next;
return (lst);
}
t_split *ft_new_split(void *content)
{
t_split *empty_lst;
empty_lst = (t_split *)ft_calloc(1, sizeof(*empty_lst));
if (!empty_lst)
return (NULL);
empty_lst->content = (char *)content;
empty_lst->next = NULL;
empty_lst->i = 0;
empty_lst->count = 1;
return (empty_lst);
}
void ft_lstadd_back(t_split **alst, t_split *new)
{
t_split *i_cell;
if (!alst || !new)
return ;
if (*alst)
{
i_cell = ft_lstlast(*alst);
i_cell->next = new;
new->count = i_cell->count + 1;
}
else
*alst = new;
}