summaryrefslogtreecommitdiff
path: root/lib/birdlib.h
diff options
context:
space:
mode:
authorMaria Matejka <mq@ucw.cz>2023-01-20 14:07:38 +0100
committerMaria Matejka <mq@ucw.cz>2023-01-20 18:31:57 +0100
commit343628d8c0f1848b968930f6dbabdd1174404b14 (patch)
treeab4e9fa467dc371529fc148c0fe1669864b47b74 /lib/birdlib.h
parent1127f19a7a12b162064b1f521acd5c0017fbcf89 (diff)
Fixed various build problems on FreeBSD and/or CLang
Diffstat (limited to 'lib/birdlib.h')
-rw-r--r--lib/birdlib.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/birdlib.h b/lib/birdlib.h
index d743ecdf..5ecd19ca 100644
--- a/lib/birdlib.h
+++ b/lib/birdlib.h
@@ -9,13 +9,22 @@
#ifndef _BIRD_BIRDLIB_H_
#define _BIRD_BIRDLIB_H_
+#include <stddef.h>
+
#include "sysdep/config.h"
#include "lib/alloca.h"
/* Ugly structure offset handling macros */
#define SAME_TYPE(a, b) ({ int _ = ((a) != (b)); !_; })
+#define TYPE_CAST(from, to, what) ( SAME_TYPE(((from) NULL), (what)), ((to) (what)))
+
+#ifdef offsetof
+#define OFFSETOF offsetof
+#else
#define OFFSETOF(s, i) ((size_t) &((s *)0)->i)
+#endif
+
#define SKIP_BACK(s, i, p) ({ s *_ptr = ((s *)((char *)p - OFFSETOF(s, i))); SAME_TYPE(&_ptr->i, p); _ptr; })
#define BIRD_ALIGN(s, a) (((s)+a-1)&~(a-1))
#define CPU_STRUCT_ALIGN (MAX_(_Alignof(void*), _Alignof(u64)))