From f21cdbc9425478674b1624f5d2b23c477f6de316 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 19 Apr 2007 12:51:04 +0000 Subject: r22369: add ZERO_STRUCT() ... macros to lib/util/util.h again to fix the openchange build... we need to remove them from libreplace, but I'll think about that next week. metze (This used to be commit 2243142b46e20825339b4f6ed0e878c18e50e45f) --- source4/lib/util/util.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index cfd77e5a13..f2531aaa85 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -82,4 +82,45 @@ extern const char *panic_action; #define strlen(x) valgrind_strlen(x) #endif +/** + * zero a structure + */ +#ifndef ZERO_STRUCT +#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x)) +#endif + +/** + * zero a structure given a pointer to the structure + */ +#ifndef ZERO_STRUCTP +#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0) +#endif + +/** + * zero a structure given a pointer to the structure - no zero check + */ +#ifndef ZERO_STRUCTPN +#define ZERO_STRUCTPN(x) memset((char *)(x), 0, sizeof(*(x))) +#endif + +/* zero an array - note that sizeof(array) must work - ie. it must not be a + pointer */ +#ifndef ZERO_ARRAY +#define ZERO_ARRAY(x) memset((char *)(x), 0, sizeof(x)) +#endif + +/** + * work out how many elements there are in a static array + */ +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) +#endif + +/** + * pointer difference macro + */ +#ifndef PTR_DIFF +#define PTR_DIFF(p1,p2) ((ptrdiff_t)(((const char *)(p1)) - (const char *)(p2))) +#endif + #endif /* _SAMBA_UTIL_H_ */ -- cgit