From 29e9f5e711a03135944e30ad241c8182dacc6049 Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Wed, 10 Feb 2010 13:01:33 +0100 Subject: Use macros to hide memcpy calls The memcpy calls introduced in the memalign patches are ugly. This patch hides them behind a set of macros. --- server/util/util.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'server/util/util.h') diff --git a/server/util/util.h b/server/util/util.h index 9c8679eca..945e20d00 100644 --- a/server/util/util.h +++ b/server/util/util.h @@ -162,6 +162,28 @@ errno_t set_debug_file_from_fd(const int fd); #define OUT_OF_ID_RANGE(id, min, max) \ (id == 0 || (min && (id < min)) || (max && (id > max))) +#define COPY_MEM(to, from, ptr, size) do { \ + memcpy(to, from, size); \ + ptr += size; \ +} while(0) + +#define COPY_TYPE(to, from, ptr, type) COPY_MEM(to, from, ptr, sizeof(type)) + +#define COPY_VALUE(to, value, ptr, type) do { \ + type CV_MACRO_val = (type) value; \ + COPY_TYPE(to, &CV_MACRO_val, ptr, type); \ +} while(0) + +#define COPY_UINT32(to, from, ptr) COPY_TYPE(to, from, ptr, uint32_t) +#define COPY_UINT32_VALUE(to, value, ptr) COPY_VALUE(to, value, ptr, uint32_t) +#define COPY_INT32(to, from, ptr) COPY_TYPE(to, from, ptr, int32_t) +#define COPY_INT32_VALUE(to, value, ptr) COPY_VALUE(to, value, ptr, int32_t) + +#define COPY_UINT32_CHECK(to, from, ptr, size) do { \ + if ((ptr + sizeof(uint32_t)) > size) return EINVAL; \ + COPY_UINT32(to, from, ptr); \ +} while(0) + #include "util/dlinklist.h" /* From debug.c */ -- cgit