diff options
Diffstat (limited to 'src/include/gnunet_common.h')
-rw-r--r-- | src/include/gnunet_common.h | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h index 1e42af95c..52322e05e 100644 --- a/src/include/gnunet_common.h +++ b/src/include/gnunet_common.h | |||
@@ -772,6 +772,17 @@ GNUNET_ntoh_double (double d); | |||
772 | #define GNUNET_new(type) (type *) GNUNET_malloc (sizeof (type)) | 772 | #define GNUNET_new(type) (type *) GNUNET_malloc (sizeof (type)) |
773 | 773 | ||
774 | /** | 774 | /** |
775 | * Call memcpy() but check for @a n being 0 first. In the latter | ||
776 | * case, it is now safe to pass NULL for @a src or @a dst. | ||
777 | * Unlike traditional memcpy(), returns nothing. | ||
778 | * | ||
779 | * @param dst destination of the copy, may be NULL if @a n is zero | ||
780 | * @param src source of the copy, may be NULL if @a n is zero | ||
781 | * @param n number of bytes to copy | ||
782 | */ | ||
783 | #define GNUNET_memcpy(dst,src,n) do { if (0 != n) { (void) memcpy (dst,src,n); } } while (0) | ||
784 | |||
785 | /** | ||
775 | * @ingroup memory | 786 | * @ingroup memory |
776 | * Allocate a size @a n array with structs or unions of the given @a type. | 787 | * Allocate a size @a n array with structs or unions of the given @a type. |
777 | * Wrapper around #GNUNET_malloc that returns a pointer | 788 | * Wrapper around #GNUNET_malloc that returns a pointer |
@@ -879,12 +890,12 @@ GNUNET_ntoh_double (double d); | |||
879 | * | 890 | * |
880 | * static void push(struct foo * elem) { | 891 | * static void push(struct foo * elem) { |
881 | * GNUNET_array_grow(myVector, myVecLen, myVecLen+1); | 892 | * GNUNET_array_grow(myVector, myVecLen, myVecLen+1); |
882 | * memcpy(&myVector[myVecLen-1], elem, sizeof(struct foo)); | 893 | * GNUNET_memcpy(&myVector[myVecLen-1], elem, sizeof(struct foo)); |
883 | * } | 894 | * } |
884 | * | 895 | * |
885 | * static void pop(struct foo * elem) { | 896 | * static void pop(struct foo * elem) { |
886 | * if (myVecLen == 0) die(); | 897 | * if (myVecLen == 0) die(); |
887 | * memcpy(elem, myVector[myVecLen-1], sizeof(struct foo)); | 898 | * GNUNET_memcpy(elem, myVector[myVecLen-1], sizeof(struct foo)); |
888 | * GNUNET_array_grow(myVector, myVecLen, myVecLen-1); | 899 | * GNUNET_array_grow(myVector, myVecLen, myVecLen-1); |
889 | * } | 900 | * } |
890 | * </pre> | 901 | * </pre> |