-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvec-resize.h
More file actions
42 lines (32 loc) · 765 Bytes
/
vec-resize.h
File metadata and controls
42 lines (32 loc) · 765 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
/*
* Capsa Dynamic Array (Vector) Resizer
*
* Copyright (c) 2014-2023 Alexei A. Smekalkine
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#ifndef VEC_RESIZE_H
#define VEC_RESIZE_H 1
#include <capsa/atom.h>
#include <capsa/vec.h>
#include <errno.h>
#include <stdlib.h>
VEC_DECLARE_TYPED (atom, const void *, const void *);
static bool vec_resize_nc (struct atom_vec *o, size_t size, size_t next)
{
const void **data;
if ((data = realloc (o->data, size * next)) == NULL)
return false;
o->avail = next;
o->data = data;
return true;
}
static bool vec_resize (struct atom_vec *o, size_t size, size_t next)
{
if (next > ~(size_t) 0 / size) {
errno = ENOMEM;
return false;
}
return vec_resize_nc (o, size, next);
}
#endif /* VEC_RESIZE_H */