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