xref: /haiku/headers/posix/assert.h (revision 6d2f2ec177bf615a117a7428d71be4330545b320)
1 /*
2  * Copyright 2004-2015 Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 /* Include guards are omitted, as assert.h is required
7    to support being included multiple times.
8 
9    E.g. the following is required to be valid:
10 
11    #undef NDEBUG
12    #include <assert.h>
13 
14    assert(0); // this assertion will be triggered
15 
16    #define NDEBUG
17    #include <assert.h>
18 
19    assert(0); // this assertion will not be triggered
20 */
21 
22 #undef assert
23 
24 #ifndef NDEBUG
25 	/* defining NDEBUG disables assert() functionality */
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 extern void __assert_fail(const char *assertion, const char *file,
32 				unsigned int line, const char *function)
33 	__attribute__ ((noreturn));
34 
35 extern void __assert_perror_fail(int error, const char *file,
36 				unsigned int line, const char *function)
37 	__attribute__ ((noreturn));
38 
39 #ifdef __cplusplus
40 }
41 #endif
42 
43 #define assert(assertion) \
44 	((assertion) ? (void)0 : __assert_fail(#assertion, __FILE__, __LINE__, __PRETTY_FUNCTION__))
45 
46 #else	/* NDEBUG */
47 #	define assert(condition) ((void)0)
48 #endif
49