summaryrefslogtreecommitdiffstats
path: root/include/libtf/defines.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/libtf/defines.h')
-rw-r--r--include/libtf/defines.h67
1 files changed, 67 insertions, 0 deletions
diff --git a/include/libtf/defines.h b/include/libtf/defines.h
new file mode 100644
index 0000000..7e35ff7
--- /dev/null
+++ b/include/libtf/defines.h
@@ -0,0 +1,67 @@
+/* tf.h - libtf helper defines
+ *
+ * Copyright (C) 2009 Timo Teräs <timo.teras@iki.fi>
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 or later as
+ * published by the Free Software Foundation.
+ *
+ * See http://www.gnu.org/ for details.
+ */
+
+#ifndef TF_DEFINES_H
+#define TF_DEFINES_H
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#ifndef NULL
+#define NULL 0L
+#endif
+
+#ifndef TRUE
+#define TRUE 1
+#endif
+
+#ifndef FALSE
+#define FALSE 0
+#endif
+
+#ifndef array_size
+#define array_size(array) (sizeof(array) / sizeof((array)[0]))
+#endif
+
+#ifndef offsetof
+#define offsetof(type, member) __builtin_offsetof (type, member)
+#endif
+
+#ifndef container_of
+#define container_of(ptr, type, member) ({ \
+ const typeof( ((type *)0)->member ) *__mptr = (ptr); \
+ (type *)( (char *)__mptr - offsetof(type,member) );})
+#endif
+
+#ifndef likely
+#define likely(x) __builtin_expect(!!(x), 1)
+#endif
+
+#ifndef unlikely
+#define unlikely(x) __builtin_expect(!!(x), 0)
+#endif
+
+#define attribute_never_inline __attribute__((noinline))
+#define attribute_weak_function __attribute__((weak))
+
+#define TF_BUG_ON(cond) if (cond) { \
+ fprintf(stderr, "BUG: failure at %s:%d/%s(): %s!\n", \
+ __FILE__, __LINE__, __func__, #cond); \
+ abort(); \
+}
+
+#define TF_ALIGN(size,align) ((((size_t)(size)) + (align)-1) & ~((align)-1))
+
+#define TF_EMPTY_ARRAY 0
+
+#endif