blob: 5a7e96db7cf3f63dc295034c9d2962c211a858b1 [file] [log] [blame]
Jeff Thompson47eecfc2013-07-07 22:56:46 -07001/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07002 * Copyright (C) 2013 Regents of the University of California.
3 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson47eecfc2013-07-07 22:56:46 -07004 * See COPYING for copyright and distribution information.
Jeff Thompson76de4a02013-06-28 19:32:39 -07005 */
6
Jeff Thompson10ad12a2013-09-24 16:19:11 -07007#include "dynamic-uint8-array.h"
Jeff Thompson76de4a02013-06-28 19:32:39 -07008
Jeff Thompson10ad12a2013-09-24 16:19:11 -07009ndn_Error ndn_DynamicUInt8Array_reallocArray(struct ndn_DynamicUInt8Array *self, unsigned int length)
Jeff Thompson76de4a02013-06-28 19:32:39 -070010{
Jeff Thompson4f938882013-07-01 16:01:09 -070011 if (!self->realloc)
Jeff Thompson10ad12a2013-09-24 16:19:11 -070012 return NDN_ERROR_DynamicUInt8Array_realloc_function_pointer_not_supplied;
Jeff Thompson4f938882013-07-01 16:01:09 -070013
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
Jeff Thompson10ad12a2013-09-24 16:19:11 -070020 uint8_t *newArray = (*self->realloc)(self, self->array, newLength);
Jeff Thompson4f938882013-07-01 16:01:09 -070021 if (!newArray)
Jeff Thompson10ad12a2013-09-24 16:19:11 -070022 return NDN_ERROR_DynamicUInt8Array_realloc_failed;
Jeff Thompson4f938882013-07-01 16:01:09 -070023
24 self->array = newArray;
25 self->length = newLength;
26
Jeff Thompsonadaf9232013-08-08 14:30:29 -070027 return NDN_ERROR_success;
Jeff Thompson7687dc02013-09-13 11:54:07 -070028}