Jeff Thompson | 76de4a0 | 2013-06-28 19:32:39 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Author: Jeff Thompson |
| 3 | * |
| 4 | * BSD license, See the LICENSE file for more information. |
| 5 | */ |
| 6 | |
Jeff Thompson | 76de4a0 | 2013-06-28 19:32:39 -0700 | [diff] [blame] | 7 | #include "DynamicUCharArray.h" |
| 8 | |
| 9 | char *ndn_DynamicUCharArray_reallocArray(struct ndn_DynamicUCharArray *self, unsigned int length) |
| 10 | { |
Jeff Thompson | 4f93888 | 2013-07-01 16:01:09 -0700 | [diff] [blame^] | 11 | if (!self->realloc) |
| 12 | return "ndn_DynamicUCharArray_reallocArray: realloc function pointer not supplied"; |
| 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 | |
| 20 | unsigned char *newArray = (*self->realloc)(self->array, newLength); |
| 21 | if (!newArray) |
| 22 | return "ndn_DynamicUCharArray_reallocArray: realloc failed"; |
| 23 | |
| 24 | self->array = newArray; |
| 25 | self->length = newLength; |
| 26 | |
| 27 | return 0; |
Jeff Thompson | 76de4a0 | 2013-06-28 19:32:39 -0700 | [diff] [blame] | 28 | } |