From 6b4d77e566197d464e3501cc8919637ac4192b66 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 9 Nov 2014 02:40:16 +0100 Subject: add initialise and create for the tree structure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/mds-kbdc/tree.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'src/mds-kbdc/tree.c') diff --git a/src/mds-kbdc/tree.c b/src/mds-kbdc/tree.c index 45d2ca0..600bf2a 100644 --- a/src/mds-kbdc/tree.c +++ b/src/mds-kbdc/tree.c @@ -18,6 +18,37 @@ #include "tree.h" #include +#include + + + +/** + * Initialise a tree node + * + * @param this The memory slot for the tree node + * @param type The type of the node + */ +void mds_kbdc_tree_initialise(mds_kbdc_tree_t* restrict this, int type) +{ + memset(this, 0, sizeof(mds_kbdc_tree_t)); + this->type = type; +} + + +/** + * Create a tree node + * + * @param type The type of the node + * @return The tree node, `NULL` on error + */ +mds_kbdc_tree_t* mds_kbdc_tree_create(int type) +{ + mds_kbdc_tree_t* this = malloc(sizeof(mds_kbdc_tree_t)); + if (this == NULL) + return NULL; + mds_kbdc_tree_initialise(this, type); + return this; +} /** @@ -127,7 +158,6 @@ static void mds_kbdc_tree_destroy_(mds_kbdc_tree_t* restrict this, int recursive } - /** * Release all resources stored in a tree node, * without freeing the node itself or freeing -- cgit v1.2.3-70-g09d2