1 /* src/client/array_append.c
3 * This file is part of PlomRogue. PlomRogue is licensed under the GPL version 3
4 * or any later version. For details on its copyright, license, and warranties,
5 * see the file NOTICE in the root directory of the PlomRogue source package.
8 #include "array_append.h"
9 #include <stddef.h> /* size_t */
10 #include <stdint.h> /* uint32_t */
11 #include <stdlib.h> /* free() */
12 #include <string.h> /* memcpy() */
13 #include "../common/try_malloc.h" /* try_malloc() */
17 extern void array_append(uint32_t old_n, size_t region_size, void * new_region,
18 void ** ptr_old_array)
20 uint32_t old_size = old_n * region_size;
21 uint32_t new_size = old_size + region_size;
22 char * new_array = try_malloc(new_size, __func__);
23 memcpy(new_array, * ptr_old_array, old_size);
24 memcpy(new_array + (old_n * region_size), new_region, region_size);
25 free(* ptr_old_array);
26 * ptr_old_array = new_array;