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.
65 lines
1.7 KiB
65 lines
1.7 KiB
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* get_next_line_utils.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2021/10/29 08:54:42 by narnaud #+# #+# */
|
|
/* Updated: 2021/11/17 18:06:57 by narnaud ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "get_next_line.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(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_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;
|
|
}
|
|
|