-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharg_checkers.h
31 lines (23 loc) · 1.2 KB
/
arg_checkers.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
28
29
30
31
#ifndef __ARG_CHECKERS_H__
#define __ARG_CHECKERS_H__
#include <stddef.h>
#include <errno.h>
// clang-format off
#define RETURN_IF(cond, retv) if (cond) return retv
#define GOTO_IF(cond, labal) if(cond) goto labal
// clang-format on
#define RETURN_IF_VALUE(cond, val, retv) RETURN_IF((val) == (cond), retv)
#define RETURN_IF_NVALUE(cond, val, retv) RETURN_IF((val) != (cond), retv)
#define RETURN_IF_ZERO(cond, retv) RETURN_IF_VALUE(cond, 0, retv)
#define RETURN_IF_NZERO(cond, retv) RETURN_IF_NVALUE(cond, 0, retv)
#define GOTO_IF_VALUE(cond, val, labal) GOTO_IF((val) == (cond), labal)
#define GOTO_IF_NVALUE(cond, val, labal) GOTO_IF((val) != (cond), labal)
#define GOTO_IF_ZERO(cond, labal) GOTO_IF_VALUE(cond, 0, labal)
#define GOTO_IF_NZERO(cond, labal) GOTO_IF_NVALUE(cond, 0, labal)
#define CHECK_PTR(ptr, retv) RETURN_IF(NULL == (ptr), retv)
#define CHECK_PTR_GOTO(ptr, labal) GOTO_IF(NULL == (ptr), labal)
#define CHECK_IN_OPEN_RANGE(val, left, right, retv) \
RETURN_IF((val) < (right) && (val) > (left), retv)
#define CHECK_IN_CLOSED_RANGE(val, left, right, retv) \
RETURN_IF((val) <= (right) && (val) >= (left), retv)
#endif // __ARG_CHECKERS_H__