diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-10-25 04:42:08 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-10-25 04:42:08 +0200 |
| commit | feb71e200972bb78fe86130629ef040ef80811a7 (patch) | |
| tree | 24b84b3f4937ab4eb930e1ad851494d8d49a9775 /list.c | |
| parent | 1b4df01bfa793fe91a58192a4b79917909bf1614 (diff) | |
| download | ft_printf-feb71e200972bb78fe86130629ef040ef80811a7.tar.gz ft_printf-feb71e200972bb78fe86130629ef040ef80811a7.tar.bz2 ft_printf-feb71e200972bb78fe86130629ef040ef80811a7.zip | |
WIP: Added libft submodule, make ft_printf lib
Diffstat (limited to 'list.c')
| -rw-r--r-- | list.c | 56 |
1 files changed, 31 insertions, 25 deletions
@@ -1,54 +1,60 @@ #include <stdlib.h> #include "header.h" -t_list *list_new(t_pformat *data) +t_pformat_list *list_new(t_pformat *content) { - t_list *list; + t_pformat_list *lst; - if ((list = (t_list*)malloc(sizeof(t_list))) == NULL) + if ((lst = (t_pformat_list*)malloc(sizeof(t_pformat_list))) == NULL) return NULL; - list->data = data; - list->next = NULL; - return (list); + lst->content = content; + lst->next = NULL; + return (lst); } -t_list *list_destroy(t_list *list) +void *list_destroy(t_pformat_list **lst) { - while (list != NULL) - list_pop_front(&list); + if (lst == NULL) + return (NULL); + while (*lst != NULL) + list_pop_front(lst); return (NULL); } -void list_push_front(t_list **list, t_list *new_front) +void list_push_front(t_pformat_list **lst, t_pformat_list *new) { - new_front->next = *list; - *list = new_front; + if (lst == NULL || new == NULL) + return ; + new->next = *lst; + *lst = new; } -void list_push_back(t_list **list, t_list *new_back) +void list_push_back(t_pformat_list **lst, t_pformat_list *new) { - t_list *cursor; + t_pformat_list *cursor; - if (*list == NULL) + if (lst == NULL || new == NULL) + return ; + if (*lst == NULL) { - *list = new_back; + *lst = new; return ; } - cursor = *list; + cursor = *lst; while (cursor->next != NULL) cursor = cursor->next; - cursor->next = new_back; + cursor->next = new; } -void list_pop_front(t_list **list) +void list_pop_front(t_pformat_list **lst) { - t_list *tmp; + t_pformat_list *tmp; - if (*list == NULL) + if (lst == NULL || *lst == NULL) return ; - tmp = (*list)->next; - free((*list)->data); - free(*list); - *list = tmp; + tmp = (*lst)->next; + free((*lst)->content); + free(*lst); + *lst = tmp; } |
