blob: 30b0814f45f2bfdc1167de872e16a7c5197ed2da [file] [log] [blame]
Jeff Thompson47eecfc2013-07-07 22:56:46 -07001/**
2 * @author: Jeff Thompson
3 * See COPYING for copyright and distribution information.
Jeff Thompson76de4a02013-06-28 19:32:39 -07004 */
5
Jeff Thompson76de4a02013-06-28 19:32:39 -07006#include "DynamicUCharArray.h"
7
8char *ndn_DynamicUCharArray_reallocArray(struct ndn_DynamicUCharArray *self, unsigned int length)
9{
Jeff Thompson4f938882013-07-01 16:01:09 -070010 if (!self->realloc)
11 return "ndn_DynamicUCharArray_reallocArray: realloc function pointer not supplied";
12
13 // See if double is enough.
14 unsigned int newLength = self->length * 2;
15 if (length > newLength)
16 // The needed length is much greater, so use it.
17 newLength = length;
18
19 unsigned char *newArray = (*self->realloc)(self->array, newLength);
20 if (!newArray)
21 return "ndn_DynamicUCharArray_reallocArray: realloc failed";
22
23 self->array = newArray;
24 self->length = newLength;
25
26 return 0;
Jeff Thompson76de4a02013-06-28 19:32:39 -070027}