summaryrefslogtreecommitdiff
path: root/meme/util.h
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2014-09-12 02:54:30 (GMT)
committerWerner Almesberger <werner@almesberger.net>2014-09-12 03:13:49 (GMT)
commit2bc5b2f3ab23a4f75bbb8c23cf437519bb332808 (patch)
treeae092628f305c449572ce3f5304e6b3164e77e68 /meme/util.h
parente41c8e654bbe68360aec22b35b424a8849947a98 (diff)
downloadmisc-2bc5b2f3ab23a4f75bbb8c23cf437519bb332808.zip
misc-2bc5b2f3ab23a4f75bbb8c23cf437519bb332808.tar.gz
misc-2bc5b2f3ab23a4f75bbb8c23cf437519bb332808.tar.bz2
measmesh/: renamed to meme/
Too much typing ;-)
Diffstat (limited to 'meme/util.h')
-rw-r--r--meme/util.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/meme/util.h b/meme/util.h
new file mode 100644
index 0000000..ec05995
--- /dev/null
+++ b/meme/util.h
@@ -0,0 +1,33 @@
+/*
+ * util.h - Common utility functions
+ *
+ * Written 2006, 2009, 2010, 2014 by Werner Almesberger
+ * Copyright 2006, 2009, 2010, 2014 Werner Almesberger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+
+#ifndef UTIL_H
+#define UTIL_H
+
+#include <stddef.h>
+#include <stdlib.h>
+
+
+#define alloc_size(s) \
+ ({ void *alloc_size_tmp = malloc(s); \
+ if (!alloc_size_tmp) \
+ abort(); \
+ alloc_size_tmp; })
+
+#define alloc_type(t) ((t *) alloc_size(sizeof(t)))
+
+
+#define container(ptr, type, member) \
+ ((type *) ((void *) (ptr) - offsetof(type, member)))
+
+#endif /* !UTIL_H */