diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-04-06 14:37:07 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-04-06 14:37:07 +0200 |
commit | c57caa206c761424b73e900978edff0a1b8fca50 (patch) | |
tree | 66641306c9a1d196dfe9f82c863bada50fb86187 /src/include/gnunet_common.h | |
parent | c0d08bbdeed4523cf89bf55b64ce2c16476c3e26 (diff) | |
download | gnunet-c57caa206c761424b73e900978edff0a1b8fca50.tar.gz gnunet-c57caa206c761424b73e900978edff0a1b8fca50.zip |
introduce GNUNET_memcmp() and GNUNET_is_zero()
Diffstat (limited to 'src/include/gnunet_common.h')
-rw-r--r-- | src/include/gnunet_common.h | 26 |
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. |