diff options
author | Junio C Hamano <gitster@pobox.com> | 2016-10-03 13:30:33 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-10-03 13:30:33 -0700 |
commit | b1f0a856605981363053941b8210f3cc9389607a (patch) | |
tree | 9de4bc7cc285925913c219edd4536985cc0cc256 /git-compat-util.h | |
parent | 3ef7618e616e023cf04180e30d77c9fa5310f964 (diff) | |
parent | 45ccef87b3cc0ab09ec5fd1186aa0b33298ee8d4 (diff) | |
download | git-b1f0a856605981363053941b8210f3cc9389607a.tar.gz |
Merge branch 'rs/copy-array'
Code cleanup.
* rs/copy-array:
use COPY_ARRAY
add COPY_ARRAY
Diffstat (limited to 'git-compat-util.h')
-rw-r--r-- | git-compat-util.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/git-compat-util.h b/git-compat-util.h index 8aab0c3047..0ce2cdfb98 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -801,6 +801,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: |