blob: d936851e730c0ce0afcc4d167a4f81118c412ecd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
/* By using this work you agree to the terms and conditions in 'LICENCE.txt' */
/* This */
#include "array.h"
/* System */
#include <stdlib.h>
#include <string.h>
ssize_t
array_add( void*arr_ , size_t*count , size_t*capacity , void*elem , unsigned int elemSize , unsigned int allocStep )
{
void** arr = arr_;
if( *count >= *capacity || *arr==NULL ){
size_t newLen = *count + allocStep;
void *newArr = realloc( *arr , newLen*elemSize );
if( ! newArr ){ return -1; }
*arr = newArr;
*capacity = newLen;
}
void *dstAddr = ((char*)*arr) + (*count)++ * elemSize;
memcpy( dstAddr , (char*)elem , elemSize );
return 0;
}
|