summaryrefslogtreecommitdiff
path: root/macro.h
diff options
context:
space:
mode:
authorMikhail Osipov <mike.osipov@gmail.com>2019-10-18 17:43:38 +0300
committerMikhail Osipov <mike.osipov@gmail.com>2019-10-18 17:43:38 +0300
commit3b00c7be0e8834402ed93eb42b3a93302076c5ff (patch)
treeebf1643f00d2206c80676b1057f6d42d494d5c3a /macro.h
parent9c05f1c4187de3c43c027f6102b6e161b2f7441c (diff)
skel
Diffstat (limited to 'macro.h')
-rw-r--r--macro.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/macro.h b/macro.h
new file mode 100644
index 0000000..c91b8cf
--- /dev/null
+++ b/macro.h
@@ -0,0 +1,25 @@
+#ifndef __TUNNEL_MACRO_H__
+#define __TUNNEL_MACRO_H__
+
+#include <stdlib.h>
+#include <string.h>
+
+#define _new(t) memset(malloc(sizeof(t)), 0, sizeof(t))
+
+#define _copy(p, ...) _copy_(p, ## __VA_ARGS__, sizeof(*p))
+#define _copy_(p, n, ...) memcpy(malloc(n), p, n)
+
+#define __unused __attribute__((unused))
+#define __cleanup(f) __attribute__((cleanup(f)))
+
+#define CAT(a, b) CAT_(a, b)
+#define CAT_(a, b) a ## b
+
+#define UNIQ(name) CAT(name, __LINE__)
+
+#define defer \
+ auto void UNIQ(defer_func)(int *); \
+ int UNIQ(defer_var) __cleanup(UNIQ(defer_func)); \
+ void UNIQ(defer_func)(int *p __unused)
+
+#endif