diff --git a/libft/includes/btree.h b/libft/includes/btree.h index ab5b587e..6e6d4215 100644 --- a/libft/includes/btree.h +++ b/libft/includes/btree.h @@ -7,12 +7,13 @@ typedef struct s_btree t_btree; struct s_btree { + void *item; + size_t content_size; struct s_btree *left; struct s_btree *right; - void *item; }; -t_btree *btree_create_node(void *item); +t_btree *btree_create_node(void const *item, size_t content_size); void btree_insert_data( t_btree **root, diff --git a/libft/src/btree/btree_create_node.c b/libft/src/btree/btree_create_node.c index b50c4be4..83170a7f 100644 --- a/libft/src/btree/btree_create_node.c +++ b/libft/src/btree/btree_create_node.c @@ -12,13 +12,24 @@ #include "btree.h" -t_btree *btree_create_node(void *item) +t_btree *btree_create_node(void const *item, size_t content_size) { t_btree *node; - node = (t_btree *)malloc(sizeof(t_btree)); + if (!(node = (t_btree *)malloc(sizeof(t_btree)))) + return (NULL); node->left = 0; node->right = 0; - node->item = item; return (node); + if (!content) + { + new->content_size = 0; + new->item = NULL; + } + else + { + new->content_size = content_size; + new->item = ft_memalloc(content_size + 1); + ft_memcpy(new->item, item, content_size); + } } diff --git a/libft/src/lst/ft_lstnew.c b/libft/src/lst/ft_lstnew.c index 1ad8c10a..302aff27 100644 --- a/libft/src/lst/ft_lstnew.c +++ b/libft/src/lst/ft_lstnew.c @@ -16,23 +16,19 @@ t_list *ft_lstnew(void const *content, size_t content_size) { t_list *new; + if (!(new = (t_list *)malloc(sizeof(*new)))) + return (NULL); + new->next = NULL; if (!content) { - new = malloc(sizeof(*new)); - if (!new) - return (NULL); new->content_size = 0; new->content = NULL; } else { - new = (t_list *)malloc(sizeof(*new)); - if (!new) - return (NULL); new->content_size = content_size; new->content = ft_memalloc(content_size + 1); ft_memcpy(new->content, content, content_size); } - new->next = NULL; return (new); }