Merge branch 'rs/copy-array' into maint
Code cleanup. * rs/copy-array: use COPY_ARRAY add COPY_ARRAY
This commit is contained in:
@ -798,6 +798,14 @@ extern FILE *fopen_for_writing(const char *path);
|
||||
#define ALLOC_ARRAY(x, alloc) (x) = xmalloc(st_mult(sizeof(*(x)), (alloc)))
|
||||
#define REALLOC_ARRAY(x, alloc) (x) = xrealloc((x), st_mult(sizeof(*(x)), (alloc)))
|
||||
|
||||
#define COPY_ARRAY(dst, src, n) copy_array((dst), (src), (n), sizeof(*(dst)) + \
|
||||
BUILD_ASSERT_OR_ZERO(sizeof(*(dst)) == sizeof(*(src))))
|
||||
static inline void copy_array(void *dst, const void *src, size_t n, size_t size)
|
||||
{
|
||||
if (n)
|
||||
memcpy(dst, src, st_mult(size, n));
|
||||
}
|
||||
|
||||
/*
|
||||
* These functions help you allocate structs with flex arrays, and copy
|
||||
* the data directly into the array. For example, if you had:
|
||||
|
Reference in New Issue
Block a user