--- libelwix/src/array.c 2019/01/21 12:26:38 1.6.2.1 +++ libelwix/src/array.c 2019/01/22 16:16:45 1.7.2.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: array.c,v 1.6.2.1 2019/01/21 12:26:38 misho Exp $ +* $Id: array.c,v 1.7.2.1 2019/01/22 16:16:45 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -72,6 +72,35 @@ array_Init(int numItems) return arr; } + +/* + * array_Init2() - Initialize dynamic array + * + * @arr = Allocated array variable + * @numItems = Number of Items + * return: NULL error, != NULL allocated memory for array + */ +array_t * +array_Init2(array_t * __restrict arr, int numItems) +{ + if (!arr) + return array_Init(numItems); + + if (array_Size(arr)) + return NULL; /* already allocated array! */ + + arr->arr_last = -1; + arr->arr_num = numItems; + arr->arr_data = e_calloc(array_Size(arr), sizeof(intptr_t)); + if (!arr->arr_data) { + e_free(arr); + return NULL; + } else + array_Zero(arr); + + return arr; +} + /* * array_From() - Create and fill array from array with pointers