summaryrefslogtreecommitdiff
path: root/src/shared/macro.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/macro.h')
-rw-r--r--src/shared/macro.h18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/shared/macro.h b/src/shared/macro.h
index 4e5d0f4f2f..f884bf653f 100644
--- a/src/shared/macro.h
+++ b/src/shared/macro.h
@@ -67,9 +67,11 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) {
* @member: the name of the member within the struct.
*
*/
-#define container_of(ptr, type, member) ({ \
- const typeof( ((type *)0)->member ) *__mptr = (ptr); \
- (type *)( (char *)__mptr - offsetof(type,member) );})
+#define container_of(ptr, type, member) \
+ __extension__ ({ \
+ const typeof( ((type *)0)->member ) *__mptr = (ptr); \
+ (type *)( (char *)__mptr - offsetof(type,member) ); \
+ })
#undef MAX
#define MAX(a,b) \
@@ -255,4 +257,14 @@ do { \
} \
} while(false)
+/* Returns the number of chars needed to format variables of the
+ * specified type as a decimal string. Adds in extra space for a
+ * negative '-' prefix. */
+
+#define DECIMAL_STR_MAX(type) \
+ (1+(sizeof(type) <= 1 ? 3 : \
+ sizeof(type) <= 2 ? 5 : \
+ sizeof(type) <= 4 ? 10 : \
+ sizeof(type) <= 8 ? 20 : sizeof(int[-2*(sizeof(type) > 8)])))
+
#include "log.h"