blob: d961e7f0948929e414d3ea5ac63c830a09d81dd5 [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 Thompson53412192013-08-06 13:35:50 -07006#include "dynamic-uchar-array.h"
Jeff Thompson76de4a02013-06-28 19:32:39 -07007
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
Jeff Thompson9254d742013-08-12 12:04:44 -070019 unsigned char *newArray = (*self->realloc)(self, self->array, newLength);
Jeff Thompson4f938882013-07-01 16:01:09 -070020 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
Jeff Thompsonadaf9232013-08-08 14:30:29 -070026 return NDN_ERROR_success;
Jeff Thompson76de4a02013-06-28 19:32:39 -070027}