diff options
Diffstat (limited to 'test_mini/libft/src/vec/ft_vecnew.c')
| -rw-r--r-- | test_mini/libft/src/vec/ft_vecnew.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test_mini/libft/src/vec/ft_vecnew.c b/test_mini/libft/src/vec/ft_vecnew.c new file mode 100644 index 0000000..8a8736a --- /dev/null +++ b/test_mini/libft/src/vec/ft_vecnew.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_vecnew.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/01 19:03:49 by charles #+# #+# */ +/* Updated: 2020/04/01 20:00:00 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_vec.h" + +/* +** \brief Create a new vector +** \param capacity Initial capacity of the underlying array +** Can't be lower than 1 +** \return Created vector or NULL on malloc error +*/ + +t_ftvec *ft_vecnew(size_t capacity) +{ + t_ftvec *vec; + + if ((vec = (t_ftvec*)malloc(sizeof(t_ftvec))) == NULL) + return (NULL); + if (capacity == 0) + capacity = 1; + if ((vec->data = (void**)malloc(sizeof(void*) * capacity)) == NULL) + { + free(vec); + return (NULL); + } + vec->capacity = capacity; + vec->size = 0; + return (vec); +} |
