Logging in C with support for monoid logging
logging jsonl monoid c
0

Configure Feed

Select the types of activity you want to include in your feed.

clog / src / dynarr.c
673 B 23 lines
1#include "dynarr.h" 2 3/// Allocate a new DynArrHeader with count=0 and capacity=0. 4/// Returns a pointer to the data region immediately following the header. 5void *new_header(void) { 6 DynArrHeader *h = malloc(sizeof(DynArrHeader)); 7 exists(h); 8 h->count = 0; 9 h->capacity = 0; 10 return h + 1; 11} 12 13/// Return a tight copy of arr (capacity == count). 14/// elem_size is the size of one element in bytes. 15void *copy_header(void *arr, size_t elem_size) { 16 DynArrHeader *src = da_header(arr); 17 size_t bytes = sizeof(DynArrHeader) + src->count * elem_size; 18 DynArrHeader *dst = malloc(bytes); 19 exists(dst); 20 memcpy(dst, src, bytes); 21 dst->capacity = dst->count; 22 return dst + 1; 23}