From: Stefan Metzmacher Date: Tue, 17 Apr 2007 08:03:29 +0000 (+0000) Subject: r22298: move ZERO_*, ARRAY_SIZE and PTR_DIFF macros into libreplace X-Git-Tag: samba-misc-tags/initial-v3-0-unstable~690 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8a7d2e633b98aa9c73cf1f7d1369015b294cf2e1;p=thirdparty%2Fsamba.git r22298: move ZERO_*, ARRAY_SIZE and PTR_DIFF macros into libreplace metze --- diff --git a/source/include/smb_macros.h b/source/include/smb_macros.h index d696db3d3ac..2b596d3c6b8 100644 --- a/source/include/smb_macros.h +++ b/source/include/smb_macros.h @@ -46,25 +46,6 @@ #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0) #endif -/* zero a structure */ -#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x)) - -/* zero a structure given a pointer to the structure */ -#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0) - -/* zero a structure given a pointer to the structure - no zero check */ -#define ZERO_STRUCTPN(x) memset((char *)(x), 0, sizeof(*(x))) - -/* zero an array - note that sizeof(array) must work - ie. it must not be a - pointer */ -#define ZERO_ARRAY(x) memset((char *)(x), 0, sizeof(x)) - -/* pointer difference macro */ -#define PTR_DIFF(p1,p2) ((ptrdiff_t)(((const char *)(p1)) - (const char *)(p2))) - -/* work out how many elements there are in a static array */ -#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) - /* assert macros */ #ifdef DEVELOPER #define SMB_ASSERT(b) ( (b) ? (void)0 : \ diff --git a/source/lib/replace/README b/source/lib/replace/README index c2de560314a..77558b2ca96 100644 --- a/source/lib/replace/README +++ b/source/lib/replace/README @@ -86,6 +86,12 @@ __STRINGSTRING MIN MAX QSORT_CAST +ZERO_STRUCT +ZERO_STRUCTP +ZERO_STRUCTPN +ZERO_ARRAY +ARRAY_SIZE +PTR_DIFF Headers: stdint.h diff --git a/source/lib/replace/replace.h b/source/lib/replace/replace.h index 840b448d24b..b96356ac467 100644 --- a/source/lib/replace/replace.h +++ b/source/lib/replace/replace.h @@ -451,6 +451,35 @@ typedef int bool; #define __location__ __FILE__ ":" __LINESTR__ #endif +/** + * zero a structure + */ +#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x)) + +/** + * zero a structure given a pointer to the structure + */ +#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0) + +/** + * zero a structure given a pointer to the structure - no zero check + */ +#define ZERO_STRUCTPN(x) memset((char *)(x), 0, sizeof(*(x))) + +/* zero an array - note that sizeof(array) must work - ie. it must not be a + pointer */ +#define ZERO_ARRAY(x) memset((char *)(x), 0, sizeof(x)) + +/** + * work out how many elements there are in a static array + */ +#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) + +/** + * pointer difference macro + */ +#define PTR_DIFF(p1,p2) ((ptrdiff_t)(((const char *)(p1)) - (const char *)(p2))) + #if MMAP_BLACKLIST #undef HAVE_MMAP #endif diff --git a/source/nsswitch/winbind_nss_config.h b/source/nsswitch/winbind_nss_config.h index d595631362b..c36d4e72325 100644 --- a/source/nsswitch/winbind_nss_config.h +++ b/source/nsswitch/winbind_nss_config.h @@ -103,18 +103,6 @@ typedef int BOOL; #endif /* don't lie. If we don't have it, then don't use it */ #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) { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } -#endif - /* Some systems (SCO) treat UNIX domain sockets as FIFOs */ #ifndef S_IFSOCK