blob: aaa26c108cf6d6bb54a78daa94b60505999d4d0e [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
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14struct ndn_DynamicUCharArray {
15 unsigned char *array;
16 unsigned int length;
17 unsigned char (*realloc)(unsigned char *array, unsigned int length);
18};
19
20static inline void ndn_DynamicUCharArray_init
21 (struct ndn_DynamicUCharArray *self, unsigned char *array, unsigned int length, unsigned char (*reallocFunction)(unsigned char *, unsigned int))
22{
23 self->array = array;
24 self->length = length;
25 self->realloc = reallocFunction;
26}
27
28char *ndn_DynamicUCharArray_reallocArray(struct ndn_DynamicUCharArray *self, unsigned int length);
29
30static inline char *ndn_DynamicUCharArray_ensureLength(struct ndn_DynamicUCharArray *self, unsigned int length)
31{
32 if (self->length >= length)
33 return 0;
34
35 return ndn_DynamicUCharArray_reallocArray(self, length);
36}
37
38static inline char *ndn_DynamicUCharArray_set
39 (struct ndn_DynamicUCharArray *self, unsigned char *value, unsigned int valueLength, unsigned int offset)
40{
41 char *error;
42 if (error = ndn_DynamicUCharArray_ensureLength(self, valueLength + offset))
43 return error;
44 ndn_memcpy(self->array + offset, value, valueLength);
45};
46
47#ifdef __cplusplus
48}
49#endif
50
51#endif
52