diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-01-17 10:56:16 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-01-17 10:56:16 +0100 |
| commit | fe37597119353ce183fc404417b81bd4702f64b7 (patch) | |
| tree | faa20a8352092c062e2fd272fff2104d9f2ddb3f /src/io/ft_printf/internals/list.c | |
| parent | 2e5ca2ab6276b7b24895ade28e1533356ef523dc (diff) | |
| download | libft-fe37597119353ce183fc404417b81bd4702f64b7.tar.gz libft-fe37597119353ce183fc404417b81bd4702f64b7.tar.bz2 libft-fe37597119353ce183fc404417b81bd4702f64b7.zip | |
Splited include like src/, Adding feature toggle protection in header
Diffstat (limited to 'src/io/ft_printf/internals/list.c')
| -rw-r--r-- | src/io/ft_printf/internals/list.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/io/ft_printf/internals/list.c b/src/io/ft_printf/internals/list.c new file mode 100644 index 0000000..99491f4 --- /dev/null +++ b/src/io/ft_printf/internals/list.c @@ -0,0 +1,67 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* list.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/29 00:14:50 by cacharle #+# #+# */ +/* Updated: 2019/11/05 23:45:42 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_vasprintf.h" + +t_flist *list_new(t_pformat *content) +{ + t_flist *lst; + + if ((lst = (t_flist*)malloc(sizeof(t_flist))) == NULL) + return (NULL); + lst->content = content; + lst->next = NULL; + return (lst); +} + +void *list_destroy(t_flist **lst) +{ + if (lst == NULL) + return (NULL); + while (*lst != NULL) + list_pop_front(lst); + return (NULL); +} + +void list_push_front(t_flist **lst, t_flist *new) +{ + if (lst == NULL || new == NULL) + return ; + new->next = *lst; + *lst = new; +} + +void list_pop_front(t_flist **lst) +{ + t_flist *tmp; + + if (lst == NULL || *lst == NULL) + return ; + tmp = (*lst)->next; + free((*lst)->content); + free(*lst); + *lst = tmp; +} + +t_flist *list_reverse(t_flist *lst) +{ + t_flist *tmp; + + if (lst == NULL) + return (NULL); + if (lst->next == NULL) + return (lst); + tmp = list_reverse(lst->next); + lst->next->next = lst; + lst->next = NULL; + return (tmp); +} |
