aboutsummaryrefslogtreecommitdiff
path: root/git-compat-util.h
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-08-23 14:33:46 -0700
committerJunio C Hamano <gitster@pobox.com>2017-08-23 14:33:46 -0700
commitd3b7ee087e3ed409b943d62501bd7fb8dbd96dd8 (patch)
tree1ed0f2f407610d50b984a4fa9b95bb72eaa17c14 /git-compat-util.h
parent752732c6d802ebc01a26e59614da38f900e3b89e (diff)
parent168e63554cbd965fee4d0092e02f8170eba7481f (diff)
downloadgit-d3b7ee087e3ed409b943d62501bd7fb8dbd96dd8.tar.gz
git-d3b7ee087e3ed409b943d62501bd7fb8dbd96dd8.tar.xz
Merge branch 'rs/move-array' into maint
Code clean-up. * rs/move-array: ls-files: don't try to prune an empty index apply: use COPY_ARRAY and MOVE_ARRAY in update_image() use MOVE_ARRAY add MOVE_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 db9c22de7..7d2c0ca75 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -828,6 +828,14 @@ static inline void copy_array(void *dst, const void *src, size_t n, size_t size)
memcpy(dst, src, st_mult(size, n));
}
+#define MOVE_ARRAY(dst, src, n) move_array((dst), (src), (n), sizeof(*(dst)) + \
+ BUILD_ASSERT_OR_ZERO(sizeof(*(dst)) == sizeof(*(src))))
+static inline void move_array(void *dst, const void *src, size_t n, size_t size)
+{
+ if (n)
+ memmove(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: