-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathn_array_grow_priv.c
More file actions
42 lines (30 loc) · 874 Bytes
/
n_array_grow_priv.c
File metadata and controls
42 lines (30 loc) · 874 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "n_array_int.h"
static tn_array *n_array_realloc(tn_array *arr, size_t new_size)
{
register int diff;
register size_t i;
void **tmp;
diff = new_size - arr->allocated;
n_assert(diff > 0);
tmp = n_realloc(arr->data, new_size * sizeof(*tmp));
for (i = arr->allocated; i < new_size; i++)
tmp[i] = NULL;
arr->data = tmp;
arr->allocated = new_size;
return arr;
}
tn_array *n_array_grow_priv_(tn_array *arr, size_t req_size)
{
register size_t new_size = arr->allocated;
while (req_size >= new_size) {
if (arr->flags & TN_ARRAY_CONSTSIZE) {
trurl_die("n_array_grow: grow request for const size array");
return NULL;
}
new_size *= 2;
}
return n_array_realloc(arr, new_size);
}