Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-10-12 00:18:32 +0300
committerJunio C Hamano <gitster@pobox.com>2016-10-12 00:18:32 +0300
commita813b19190a75e44b6ebd1ea5317ef5ed914cde0 (patch)
tree57781b3d45acf013b4e1b506ad324572f0c82e42 /git-compat-util.h
parentf7e2e592cf9bad03bc3adc44dcbe498b876dc808 (diff)
parent45ccef87b3cc0ab09ec5fd1186aa0b33298ee8d4 (diff)
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.h8
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: