cctools
assert.h
1 #ifndef CCTOOLS_ASSERT_H
2 #define CCTOOLS_ASSERT_H
3 
4 #include <stdio.h>
5 #include <stdlib.h>
6 
7 /* Tests use this assert and do not have CCTOOLS_SOURCE defined. */
8 #ifndef CCTOOLS_SOURCE
9 # define CCTOOLS_SOURCE "test"
10 #endif
11 
12 #ifndef NDEBUG
13 # define cctools_assert(exp) \
14  do {\
15  if (!(exp)) {\
16  fprintf(stderr, "%s: %s:%d[%s]: Assertion '%s' failed.\n", __func__, __FILE__, __LINE__, CCTOOLS_SOURCE, #exp);\
17  fflush(stderr);\
18  abort();\
19  }\
20  } while (0)
21 #else
22 # define cctools_assert(exp) ((void)0)
23 #endif
24 
25 #undef assert
26 #define assert(expr) cctools_assert(expr)
27 
28 #endif /* CCTOOLS_ASSERT_H */