blob: 83016ce9b6244ee149cd1bf955bcde18c299c8bf [file] [log] [blame]
Jeff Thompson76de4a02013-06-28 19:32:39 -07001/*
2 * Author: Jeff Thompson
3 *
4 * BSD license, See the LICENSE file for more information.
5 */
6
Jeff Thompson76de4a02013-06-28 19:32:39 -07007#include "DynamicUCharArray.h"
8
9char *ndn_DynamicUCharArray_reallocArray(struct ndn_DynamicUCharArray *self, unsigned int length)
10{
Jeff Thompson4f938882013-07-01 16:01:09 -070011 if (!self->realloc)
12 return "ndn_DynamicUCharArray_reallocArray: realloc function pointer not supplied";
13
14 // See if double is enough.
15 unsigned int newLength = self->length * 2;
16 if (length > newLength)
17 // The needed length is much greater, so use it.
18 newLength = length;
19
20 unsigned char *newArray = (*self->realloc)(self->array, newLength);
21 if (!newArray)
22 return "ndn_DynamicUCharArray_reallocArray: realloc failed";
23
24 self->array = newArray;
25 self->length = newLength;
26
27 return 0;
Jeff Thompson76de4a02013-06-28 19:32:39 -070028}