blob: 29fd9d94273f3128e4dadb88d46ac36e5157c294 [file] [log] [blame]
Jeff Thompson76de4a02013-06-28 19:32:39 -07001/*
2 * Author: Jeff Thompson
3 *
4 * BSD license, See the LICENSE file for more information.
5 */
6
7#ifndef NDN_DYNAMICUCHARARRAY_H
8#define NDN_DYNAMICUCHARARRAY_H
9
Jeff Thompson2630dd02013-06-28 19:40:18 -070010#include "ndn_memory.h"
11
Jeff Thompson76de4a02013-06-28 19:32:39 -070012#ifdef __cplusplus
13extern "C" {
14#endif
15
16struct ndn_DynamicUCharArray {
17 unsigned char *array;
18 unsigned int length;
19 unsigned char (*realloc)(unsigned char *array, unsigned int length);
20};
21
22static inline void ndn_DynamicUCharArray_init
23 (struct ndn_DynamicUCharArray *self, unsigned char *array, unsigned int length, unsigned char (*reallocFunction)(unsigned char *, unsigned int))
24{
25 self->array = array;
26 self->length = length;
27 self->realloc = reallocFunction;
28}
29
30char *ndn_DynamicUCharArray_reallocArray(struct ndn_DynamicUCharArray *self, unsigned int length);
31
32static inline char *ndn_DynamicUCharArray_ensureLength(struct ndn_DynamicUCharArray *self, unsigned int length)
33{
34 if (self->length >= length)
35 return 0;
36
37 return ndn_DynamicUCharArray_reallocArray(self, length);
38}
39
40static inline char *ndn_DynamicUCharArray_set
41 (struct ndn_DynamicUCharArray *self, unsigned char *value, unsigned int valueLength, unsigned int offset)
42{
43 char *error;
44 if (error = ndn_DynamicUCharArray_ensureLength(self, valueLength + offset))
45 return error;
46 ndn_memcpy(self->array + offset, value, valueLength);
47};
48
49#ifdef __cplusplus
50}
51#endif
52
53#endif
54