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 | 76de4a0 | 2013-06-28 19:32:39 -0700 | [diff] [blame] | 6 | #include "DynamicUCharArray.h" |
| 7 | |
| 8 | char *ndn_DynamicUCharArray_reallocArray(struct ndn_DynamicUCharArray *self, unsigned int length) |
| 9 | { |
Jeff Thompson | 4f93888 | 2013-07-01 16:01:09 -0700 | [diff] [blame] | 10 | if (!self->realloc) |
| 11 | return "ndn_DynamicUCharArray_reallocArray: realloc function pointer not supplied"; |
| 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) |
| 21 | return "ndn_DynamicUCharArray_reallocArray: realloc failed"; |
| 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 | } |