diff options
author | Junio C Hamano <gitster@pobox.com> | 2016-10-11 14:18:32 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-10-11 14:18:32 -0700 |
commit | a813b19190a75e44b6ebd1ea5317ef5ed914cde0 (patch) | |
tree | 57781b3d45acf013b4e1b506ad324572f0c82e42 /git-compat-util.h | |
parent | f7e2e592cf9bad03bc3adc44dcbe498b876dc808 (diff) | |
parent | 45ccef87b3cc0ab09ec5fd1186aa0b33298ee8d4 (diff) | |
download | git-a813b19190a75e44b6ebd1ea5317ef5ed914cde0.tar.gz |
Merge branch 'rs/copy-array' into maint
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 2c949983dc..aec8cc9890 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -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: |