+static inline int IS_ERR(const void *ptr)
+{
+ return IS_ERR_VALUE((unsigned long)ptr);
+}
+
+static inline int IS_ERR_OR_NULL(const void *ptr)
+{
+ return !ptr || IS_ERR(ptr);
+}
+
+/*
+ * This looks more complex than it should be. But we need to
+ * get the type for the ~ right in round_down (it needs to be
+ * as wide as the result!), and we want to evaluate the macro
+ * arguments just once each.
+ */
+#define __round_mask(x, y) ((__typeof__(x))((y)-1))
+#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
+#define round_down(x, y) ((x) & ~__round_mask(x, y))
+
+/*
+ * printk
+ */
+#define printk(fmt, args...) fprintf(stderr, fmt, ##args)
+#define KERN_CRIT ""
+#define KERN_ERR ""
+
+/*
+ * kmalloc/kfree
+ */
+#define kmalloc(x, y) malloc(x)
+#define kzalloc(x, y) calloc(1, x)
+#define kstrdup(x, y) strdup(x)
+#define kfree(x) free(x)
+#define vmalloc(x) malloc(x)
+#define vfree(x) free(x)
+
+#ifndef BTRFS_DISABLE_BACKTRACE
+static inline void assert_trace(const char *assertion, const char *filename,
+ const char *func, unsigned line, long val)
+{
+ if (val)
+ return;
+ fprintf(stderr,
+ "%s:%d: %s: Assertion `%s` failed, value %ld\n",
+ filename, line, func, assertion, val);
+#ifndef BTRFS_DISABLE_BACKTRACE
+ print_trace();
+#endif
+ abort();
+ exit(1);
+}
+#define ASSERT(c) assert_trace(#c, __FILE__, __func__, __LINE__, (long)(c))