diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2006-03-05 20:45:18 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:52:15 -0500 |
commit | 4d8fe47f7fcfa1b0f479faf72d7d3fe15f799be5 (patch) | |
tree | 51b814ec40aeb679444666253f8045a304963586 /source4/lib/util/util.h | |
parent | 8ef42b1fab5e7608a8f90f303ec4c1d3524627d9 (diff) | |
download | samba-4d8fe47f7fcfa1b0f479faf72d7d3fe15f799be5.tar.gz samba-4d8fe47f7fcfa1b0f479faf72d7d3fe15f799be5.tar.bz2 samba-4d8fe47f7fcfa1b0f479faf72d7d3fe15f799be5.zip |
r13849: More improvements to the libutil docs.
(This used to be commit eed16ac3b7f7062a34f09f602db0f828cac7f246)
Diffstat (limited to 'source4/lib/util/util.h')
-rw-r--r-- | source4/lib/util/util.h | 63 |
1 files changed, 57 insertions, 6 deletions
diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index 55d775e25c..272cc13f4e 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -24,6 +24,11 @@ #ifndef _SAMBA_UTIL_H_ #define _SAMBA_UTIL_H_ +/** + * @file + * @brief Helpful macros + */ + struct substitute_context; #include "util/xfile.h" @@ -32,34 +37,55 @@ struct substitute_context; #include "util/byteorder.h" #include "util/util_proto.h" -/* zero a structure */ +/** + * zero a structure + */ #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x)) -/* zero a structure given a pointer to the structure */ +/** + * 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 */ +/** + * zero a structure given a pointer to the structure - no zero check + */ #define ZERO_STRUCTPN(x) memset((char *)(x), 0, sizeof(*(x))) -/* pointer difference macro */ +/** + * 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 */ +/** + * work out how many elements there are in a static array + */ #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) -/* assert macros */ +/** + * assert macros + */ #define SMB_ASSERT(b) do { if (!(b)) { \ DEBUG(0,("PANIC: assert failed at %s(%d)\n", __FILE__, __LINE__)); \ smb_panic("assert failed"); }} while (0) +/** + * determine the lowest of two values + */ #ifndef MIN #define MIN(a,b) ((a)<(b)?(a):(b)) #endif +/** + * determine the highest of two values + */ #ifndef MAX #define MAX(a,b) ((a)>(b)?(a):(b)) #endif +/** + * determine absolute value + */ #ifndef ABS #define ABS(a) ((a)>0?(a):(-(a))) #endif @@ -78,4 +104,29 @@ struct substitute_context; #define malloc_array_p(type, count) (type *)realloc_array(NULL, sizeof(type), count) #define realloc_p(p, type, count) (type *)realloc_array(p, sizeof(type), count) +#if defined(VALGRIND) +#define strlen(x) valgrind_strlen(x) +#endif + +/** + this is a warning hack. The idea is to use this everywhere that we + get the "discarding const" warning from gcc. That doesn't actually + fix the problem of course, but it means that when we do get to + cleaning them up we can do it by searching the code for + discard_const. + + It also means that other error types aren't as swamped by the noise + of hundreds of const warnings, so we are more likely to notice when + we get new errors. + + Please only add more uses of this macro when you find it + _really_ hard to fix const warnings. Our aim is to eventually use + this function in only a very few places. + + Also, please call this via the discard_const_p() macro interface, as that + makes the return type safe. +*/ +#define discard_const(ptr) ((void *)((intptr_t)(ptr))) +#define discard_const_p(type, ptr) ((type *)discard_const(ptr)) + #endif /* _SAMBA_UTIL_H_ */ |