Add MOVE_ARRAY to complement COPY_ARRAY, which was added in 60566cbb. It provides the same convenience, safety and support for NULL pointers as representations of empty arrays, just as a wrapper for memmove(3) instead of memcpy(3). Inspired-by: Martin Liska <mliska@xxxxxxx> Signed-off-by: Rene Scharfe <l.s.r@xxxxxx> --- git-compat-util.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/git-compat-util.h b/git-compat-util.h index 8a4a3f85e7..3266a71fb4 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -812,6 +812,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: -- 2.12.2