Jeff Thompson | 47eecfc | 2013-07-07 22:56:46 -0700 | [diff] [blame] | 1 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame^] | 2 | * Copyright (C) 2013 Regents of the University of California. |
| 3 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | 47eecfc | 2013-07-07 22:56:46 -0700 | [diff] [blame] | 4 | * See COPYING for copyright and distribution information. |
Jeff Thompson | 76de4a0 | 2013-06-28 19:32:39 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
Jeff Thompson | 5341219 | 2013-08-06 13:35:50 -0700 | [diff] [blame] | 7 | #include "dynamic-uchar-array.h" |
Jeff Thompson | 76de4a0 | 2013-06-28 19:32:39 -0700 | [diff] [blame] | 8 | |
Jeff Thompson | 8b66600 | 2013-07-08 01:16:26 -0700 | [diff] [blame] | 9 | ndn_Error ndn_DynamicUCharArray_reallocArray(struct ndn_DynamicUCharArray *self, unsigned int length) |
Jeff Thompson | 76de4a0 | 2013-06-28 19:32:39 -0700 | [diff] [blame] | 10 | { |
Jeff Thompson | 4f93888 | 2013-07-01 16:01:09 -0700 | [diff] [blame] | 11 | if (!self->realloc) |
Jeff Thompson | 8b66600 | 2013-07-08 01:16:26 -0700 | [diff] [blame] | 12 | return NDN_ERROR_DynamicUCharArray_realloc_function_pointer_not_supplied; |
Jeff Thompson | 4f93888 | 2013-07-01 16:01:09 -0700 | [diff] [blame] | 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 | |
Jeff Thompson | 9254d74 | 2013-08-12 12:04:44 -0700 | [diff] [blame] | 20 | unsigned char *newArray = (*self->realloc)(self, self->array, newLength); |
Jeff Thompson | 4f93888 | 2013-07-01 16:01:09 -0700 | [diff] [blame] | 21 | if (!newArray) |
Jeff Thompson | 8b66600 | 2013-07-08 01:16:26 -0700 | [diff] [blame] | 22 | return NDN_ERROR_DynamicUCharArray_realloc_failed; |
Jeff Thompson | 4f93888 | 2013-07-01 16:01:09 -0700 | [diff] [blame] | 23 | |
| 24 | self->array = newArray; |
| 25 | self->length = newLength; |
| 26 | |
Jeff Thompson | adaf923 | 2013-08-08 14:30:29 -0700 | [diff] [blame] | 27 | return NDN_ERROR_success; |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame^] | 28 | } |