-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathutil.h
27 lines (21 loc) · 977 Bytes
/
util.h
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
26
27
#ifndef __KVS_UTIL_H__
#define __KVS_UTIL_H__
#include "status.h"
#define KVS_OFFSET_OF(TYPE, FIELD) (((size_t)(&((TYPE *) sizeof(TYPE))->FIELD)) - sizeof(TYPE))
#define KVS_UNSAFE_CAST(BASE, OFFSET) ((void *) (((char *) (BASE)) + OFFSET))
#define KVS_ARRAY_SIZE(ARRAY) (sizeof(ARRAY) / sizeof(ARRAY[0]))
#define KVS_DO(ST, X) \
do { \
if (KVS_FAILED(ST = (X))) { \
return ST; \
} \
} while (0)
#define KVS_DO_GOTO(ST, LABEL, X) \
do { \
if (KVS_FAILED(ST = (X))) { \
goto LABEL; \
} \
} while (0)
#define KVS_CHECK_OOM(X) if ((X) == NULL) { return KVS_OUT_OF_MEMORY; }
#define KVS_CHECK_OOM_GOTO(ST, LABEL, X) if ((X) == NULL) { ST = KVS_OUT_OF_MEMORY; goto LABEL; }
#endif /* __KVS_UTIL_H__ */