summaryrefslogtreecommitdiff
path: root/macro.h
blob: c91b8cfb58e122690cb3293f2c2ba58aeb9d643c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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