YetAnotherCoupler 3.5.2
Loading...
Searching...
No Matches
ensure_array_size.h
Go to the documentation of this file.
1// Copyright (c) 2024 The YAC Authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef ENSURE_ARRAY_SIZE_H
6#define ENSURE_ARRAY_SIZE_H
7
8#include <stdlib.h>
9
10void
11yac_realloc_array(void **array, size_t elem_size, size_t *curr_array_size,
12 size_t requested_size);
13
14#define ENSURE_ARRAY_SIZE(arrayp, curr_array_size, req_size) \
15 do { \
16 if ((size_t)(req_size) > (size_t)(curr_array_size)) \
17 { \
18 size_t casize = (curr_array_size); \
19 \
20 yac_realloc_array((void **)&(arrayp), sizeof(*(arrayp)), &casize, \
21 (req_size)); \
22 (curr_array_size) = casize; \
23 } \
24 } \
25 while(0)
26
27#define ENSURE_BYTE_ARRAY_SIZE(arrayp, curr_array_size, req_size) \
28 do { \
29 if ((size_t)(req_size) > (size_t)(curr_array_size)) \
30 { \
31 size_t casize = (curr_array_size); \
32 \
33 yac_realloc_array(&(arrayp), 1, &casize, (req_size)); \
34 \
35 (curr_array_size) = casize; \
36 } \
37 } \
38 while(0)
39
40#endif
41
void yac_realloc_array(void **array, size_t elem_size, size_t *curr_array_size, size_t requested_size)