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 | |
| 19 | unsigned char *newArray = (*self->realloc)(self->array, newLength); |
| 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 | |
| 26 | return 0; |
Jeff Thompson | 76de4a0 | 2013-06-28 19:32:39 -0700 | [diff] [blame] | 27 | } |