diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2010-02-10 13:01:33 +0100 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2010-02-18 13:48:44 -0500 |
commit | 29e9f5e711a03135944e30ad241c8182dacc6049 (patch) | |
tree | 0da07910b6618ced8b16d0011ad023687efed7cc /server/util | |
parent | 2c5bf74c71443f1680fef4fc0daa4a4c9dd10ad8 (diff) | |
download | sssd-29e9f5e711a03135944e30ad241c8182dacc6049.tar.gz sssd-29e9f5e711a03135944e30ad241c8182dacc6049.tar.bz2 sssd-29e9f5e711a03135944e30ad241c8182dacc6049.zip |
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.
Diffstat (limited to 'server/util')
-rw-r--r-- | server/util/util.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/server/util/util.h b/server/util/util.h index 9c8679ec..945e20d0 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 */ |