aboutsummaryrefslogtreecommitdiff
path: root/git-compat-util.h
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-08-11 13:26:57 -0700
committerJunio C Hamano <gitster@pobox.com>2017-08-11 13:26:57 -0700
commit32f90258bd510d84dfe8970211ec1427e9e327dc (patch)
tree6727e0574f5c648aec927e43545617b0c5fca32e /git-compat-util.h
parentc2bfd0f9cba5e94c08dcc1033d39d7bef29be08e (diff)
parent168e63554cbd965fee4d0092e02f8170eba7481f (diff)
downloadgit-32f90258bd510d84dfe8970211ec1427e9e327dc.tar.gz
git-32f90258bd510d84dfe8970211ec1427e9e327dc.tar.xz
Merge branch 'rs/move-array'
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: