-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapicheck.h
47 lines (36 loc) · 1.3 KB
/
apicheck.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* apicheck.h
* Copyright (C) 2017 Adrian Perez <[email protected]>
*
* Distributed under terms of the MIT license.
*/
#ifndef APICHECK_H
#define APICHECK_H
#include <stdlib.h>
#include <stdio.h>
#ifndef API_CHECK_OUTPUT_FILE
#define API_CHECK_OUTPUT_FILE stderr
#endif /* !API_CHECK_OUTPUT_FILE */
#ifndef API_CHECK_SHOULD_ABORT
#define API_CHECK_SHOULD_ABORT 0
#endif /* !API_CHECK_SHOULD_ABORT */
#if defined(API_CHECK_DISABLE) && API_CHECK_DISABLE
#define api_check_return(expr) ((void) (expr))
#define api_check_return_val(expr, val) ((void) (expr), (void) (val))
#else
#define api_check_return_val(expr, val) do { \
if (!(expr)) { \
FILE* __api_check_output_ ## __LINE__ = (API_CHECK_OUTPUT_FILE); \
if (!__api_check_output_ ## __LINE__) \
__api_check_output_ ## __LINE__ = stderr; \
fprintf (__api_check_output_ ## __LINE__, \
"API check '%s' failed at %s (%s:%d)\n", \
#expr, __func__, __FILE__, __LINE__); \
fflush (__api_check_output_ ## __LINE__); \
if (!!(API_CHECK_SHOULD_ABORT)) abort (); \
return val; \
} \
} while (0)
#define api_check_return(expr) api_check_return_val(expr,)
#endif /* API_CHECK_DISABLE */
#endif /* !APICHECK_H */