aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_common.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/gnunet_common.h')
-rw-r--r--src/include/gnunet_common.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h
index ca49d3109..773ff8f3e 100644
--- a/src/include/gnunet_common.h
+++ b/src/include/gnunet_common.h
@@ -913,6 +913,32 @@ GNUNET_ntoh_double (double d);
913 */ 913 */
914#define GNUNET_new(type) (type *) GNUNET_malloc (sizeof (type)) 914#define GNUNET_new(type) (type *) GNUNET_malloc (sizeof (type))
915 915
916
917/**
918 * Compare memory in @a a and @a b, where both must be of
919 * the same pointer type.
920 */
921#define GNUNET_memcmp(a,b) ({ \
922 typeof(b) _a = (a); \
923 typeof(a) _b = (b); \
924 memcmp(_a, \
925 _b, \
926 sizeof (*a)); })
927
928
929/**
930 * Check that memory in @a a is all zeros. @a a must be a pointer.
931 *
932 * @param a pointer to a struct which should be tested for the
933 * entire memory being zero'ed out.
934 */
935#define GNUNET_is_zero(a) ({ \
936 typeof(*a) _z = { 0 }; \
937 memcmp(a, \
938 &_z, \
939 sizeof (_z)); })
940
941
916/** 942/**
917 * Call memcpy() but check for @a n being 0 first. In the latter 943 * Call memcpy() but check for @a n being 0 first. In the latter
918 * case, it is now safe to pass NULL for @a src or @a dst. 944 * case, it is now safe to pass NULL for @a src or @a dst.