1 /* src/client/array_append.c */
3 #include "array_append.h"
4 #include <stddef.h> /* size_t */
5 #include <stdint.h> /* uint32_t */
6 #include <stdlib.h> /* free() */
7 #include <string.h> /* memcpy() */
8 #include "../common/try_malloc.h" /* try_malloc() */
12 extern void array_append(uint32_t old_n, size_t region_size, void * new_region,
13 void ** ptr_old_array)
15 char * f_name = "array_append()";
16 uint32_t old_size = old_n * region_size;
17 uint32_t new_size = old_size + region_size;
18 char * new_array = try_malloc(new_size, f_name);
19 memcpy(new_array, * ptr_old_array, old_size);
20 memcpy(new_array + (old_n * region_size), new_region, region_size);
21 free(* ptr_old_array);
22 * ptr_old_array = new_array;