blob: eb28072ac1b3644a88e89fbe1df44bce3a1c8b8d [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
Jeff Thompson8b666002013-07-08 01:16:26 -07008ndn_Error ndn_DynamicUCharArray_reallocArray(struct ndn_DynamicUCharArray *self, unsigned int length)
Jeff Thompson76de4a02013-06-28 19:32:39 -07009{
Jeff Thompson4f938882013-07-01 16:01:09 -070010 if (!self->realloc)
Jeff Thompson8b666002013-07-08 01:16:26 -070011 return NDN_ERROR_DynamicUCharArray_realloc_function_pointer_not_supplied;
Jeff Thompson4f938882013-07-01 16:01:09 -070012
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)
Jeff Thompson8b666002013-07-08 01:16:26 -070021 return NDN_ERROR_DynamicUCharArray_realloc_failed;
Jeff Thompson4f938882013-07-01 16:01:09 -070022
23 self->array = newArray;
24 self->length = newLength;
25
26 return 0;
Jeff Thompson76de4a02013-06-28 19:32:39 -070027}