aboutsummaryrefslogtreecommitdiff
path: root/src/vec/ft_vecnew.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-04-01 21:21:10 +0200
committerCharles <sircharlesaze@gmail.com>2020-04-01 21:21:10 +0200
commita1675f56b35f5521a91851bae8ca650706374ae6 (patch)
tree73bf00503b27ac4e548ae66bf7789eff4eb8eede /src/vec/ft_vecnew.c
parent9316f2063255bd4a0abd5c38d4c065969a8980bb (diff)
downloadlibft-a1675f56b35f5521a91851bae8ca650706374ae6.tar.gz
libft-a1675f56b35f5521a91851bae8ca650706374ae6.tar.bz2
libft-a1675f56b35f5521a91851bae8ca650706374ae6.zip
Added vector
Diffstat (limited to 'src/vec/ft_vecnew.c')
-rw-r--r--src/vec/ft_vecnew.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/vec/ft_vecnew.c b/src/vec/ft_vecnew.c
new file mode 100644
index 0000000..8a8736a
--- /dev/null
+++ b/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);
+}